Inserting VZGOT development tree within GIT
[safe/jmp/vzgot] / lib / dbgmem.h
1 /************************************************/
2 /*                                              */
3 /*      Copyright:                              */
4 /*       Jean-Marc Pigeon <jmp@safe.ca>  2009   */
5 /*                                              */
6 /************************************************/
7 /* This program is free software; you can       */
8 /* redistribute it and/or modify it under the   */
9 /* terms of the GNU General Public License as   */
10 /* published by the Free Software Foundation    */
11 /* version 2 of the License                     */
12 /*                                              */
13 /* This program is distributed in the hope that */
14 /* it will be useful, but WITHOUT ANY WARRANTY; */
15 /* without even the implied warranty of         */
16 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR  */
17 /* PURPOSE.  See the GNU General Public License */
18 /* for more details.                            */
19 /*                                              */
20 /* You should have received a copy of the GNU   */
21 /* General Public License along with this       */
22 /* program; if not, write to the Free Software  */
23 /* Foundation, Inc., 51 Franklin Street,        */
24 /* Fifth Floor, Boston, MA  02110-1301, USA.    */
25 /************************************************/
26 /*                                              */
27 /*      Define sub level procedure to debug     */
28 /*      memory problem                          */
29 /*                                              */
30 /************************************************/
31 #ifndef DBGMEM
32 #define DBGMEM
33 #include        <stdlib.h>
34 #include        <stdarg.h>
35
36 /*define it at compile if you want to look for  */
37 /*memory leak, report is displayed each time    */
38 /*dbg_dumpmem is called.                        */
39 #ifdef  DEBUG
40 #define DEBUGMEM
41 /*
42 */
43 #endif
44
45 /*to activate Memory leak detector              */
46 #define DMTRUE  1       /*Boolean               */
47 #define DMFALSE 0       /*Boolean               */
48
49 #ifdef DEBUGMEM
50 #ifndef DEBUG
51 #error "Caution, See dbgmem.h,"
52 #error "you should use DEBUGMEM in DEBUG compilation mode"
53 #endif
54 #define DMTRACE DMTRUE  
55 #else
56 #define DMTRACE DMFALSE 
57 #endif
58
59 #ifdef  DEBUGMEM        
60 #define calloc          dbg_calloc
61 #define malloc          dbg_malloc
62 #define realloc         dbg_realloc
63 #define free            dbg_free
64 #define putenv          dbg_putenv
65 #define setenv          dbg_setenv
66 #define unsetenv        dbg_unsetenv
67 #define asprintf        dbg_asprintf
68 #define vasprintf       dbg_vasprintf
69 #define SYSfree         dbg_sysfree
70
71 #undef strdup
72 #define strdup          dbg_strdup
73 #else
74 #define SYSfree         free
75 #endif
76
77 extern int memleak;
78
79 extern void dbg_setcurpath(char *path);
80 extern void dbg_setcurbase(char *path);
81 extern void *dbg_malloc(size_t size);
82 extern void *dbg_calloc(size_t nmemb,size_t size);
83 extern void *dbg_realloc(void *ptr,size_t size);
84 extern char *dbg_strdup(const char *str);
85 extern void dbg_free(void *ptr);
86 extern int dbg_putenv(char *valeur);
87 extern int dbg_setenv(const char *name,const char *value,int overwrite);
88 extern int dbg_unsetenv(const char *name);
89 extern int dbg_vasprintf(char **strp, const char *fmt,va_list args);
90 extern int dbg_asprintf(char **strp, const char *fmt, ...);
91 extern void dbg_sysfree(void *ptr);
92 extern void dbg_dumpmem(const char *apname,const char *extension);
93 extern void dbg_setnoleak(int value);
94 #endif