"Fossies" - the Fresh Open Source Software Archive

Member "FunctionCheck-3.2.0/src/fcmanager/fc_graph.c" (26 May 2012, 2131 Bytes) of package /linux/privat/old/FunctionCheck-3.2.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * FunctionCheck profiler
    3  * (C) Copyright 2000-2012 Yannick Perret
    4  * 
    5  *  This program is free software; you can redistribute it and/or
    6  *  modify it under the terms of the FC_NU FC_eneral Public License as
    7  *  published by the Free Software Foundation; either version 2 of the
    8  *  License, or (at your option) any later version.
    9  *
   10  *  This program is distributed in the hope that it will be useful,
   11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the FC_NU
   13  *  FC_eneral Public License for more details.
   14  *
   15  *  You should have received a copy of the FC_NU FC_eneral Public License
   16  *  along with this program; if not, write to the Free Software
   17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   18  */
   19 /** fc_graph.c:  **/
   20 
   21 #include <stdio.h>
   22 #include <stdlib.h>
   23 #include "fc_xlhash.h"
   24 #include "fc_global.h"
   25 #include "fc_graph.h"
   26 #include "fc_tools.h"
   27 
   28 /* init the arc list */
   29 FC_LHash *fc_graph_init(int size)
   30 {
   31     /* we use 'from' part of arcs as key, because only one
   32          call can start from a given address */
   33     return (fc_lhash_new());
   34 }
   35 
   36 /* add a new arc */
   37 int fc_graph_add(FC_LHash *graph, void *from, void *to)
   38 {
   39     int *val;
   40     void **ptr1, **ptr2;
   41     unsigned long long key;
   42 
   43     if (graph == NULL)
   44         return (0);
   45 
   46     /* empty entry */
   47     if (from == NULL)
   48         return (1);
   49 
   50     /* compute the key */
   51     key = (((unsigned long long) ((unsigned int) from)) << (sizeof (int) *8)) +
   52             ((unsigned long long) ((unsigned int) to));
   53 
   54     /* look for the element */
   55     if (fc_lhash_lookup_modify(graph, key, &val, &ptr1, &ptr2))
   56     {
   57         /* still referenced: add the arc */
   58         (*val)++;
   59         return (1);
   60     }
   61 
   62     /* else add the key */
   63     fc_lhash_insert(graph, key, 1, NULL, NULL);
   64 
   65     return (1);
   66 }
   67 
   68 /* add a new arc (if not present) */
   69 int fc_graph_add_single(FC_LHash *graph, void *from, void *to)
   70 {
   71     /* redirect */
   72     return (fc_graph_add(graph, from, to));
   73 }
   74 
   75 /* remove the graph */
   76 int fc_graph_free(FC_LHash *graph)
   77 {
   78     fc_lhash_destroy(graph);
   79 
   80     return (1);
   81 }
   82 
   83