63a5eddebb0ab2197d902f244f906b0a56c1533e
[ircu2.10.12-pk.git] / include / fda.h
1 /*
2  * fda.c - Free Debug Allocator
3  * Copyright (C) 1997 Thomas Helvey <tomh@inxpress.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General 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  * $Id$
20  */
21 #ifndef INCLUDED_fda_h
22 #define INCLUDED_fda_h
23
24 #if defined(MDEBUG)
25 #ifndef INCLUDED_sys_types_h
26 #include <sys/types.h>      /* size_t */
27 #define INCLUDED_sys_types_h
28 #endif
29
30
31 extern size_t fda_get_byte_count(void);
32 extern size_t fda_get_block_count(void);
33 extern size_t fda_sizeof(const void* p);
34 extern void   fda_clear_refs(void);
35 extern void   fda_set_ref(const void* p);
36 extern void   fda_assert_refs(void);
37 extern int    fda_enum_locations(void (*enumfn)(const char*, int, int));
38 extern int    fda_enum_leaks(void (*enumfn)(const char*, int, size_t, void*));
39 extern void   fda_dump_hash(void (*enumfn)(int, int));
40 extern void   fda_set_byte_limit(size_t nbytes);
41 extern int    valid_ptr(const void* p, size_t size);
42
43 extern void* fda_malloc(size_t size, const char* file, int line);
44 extern void* fda_realloc(void* p, size_t size, const char* file, int line);
45 extern void* fda_calloc(size_t nelems, size_t size, const char* file, int line);
46 extern char* fda_strdup(const char* src, const char* file, int line);
47 extern void  fda_free(void* p);
48
49 #if defined(FDA_REDEFINE_MALLOC)
50 #define malloc(s)     fda_malloc((s), __FILE__, __LINE__)
51 #define realloc(p, s) fda_realloc((p), (s), __FILE__, __LINE__)
52 #define calloc(n, s)  fda_calloc((n), (s), __FILE__, __LINE__)
53 #define strdup(s)     fda_strdup((s), __FILE__, __LINE__)
54 #define free(p)       fda_free((p))
55 #endif
56
57 extern void fda_set_lowmem_handler(void (*fn)(void));
58 extern void fda_set_nomem_handler(void (*fn)(void));
59
60
61 #endif /* defined(MDEBUG) */
62 #endif /* INCLUDED_fda_h */