Author: Bleep <tomh@inxpress.net>
[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 #ifndef INCLUDED_fda_h
20 #define INCLUDED_fda_h
21
22 #if !defined(NDEBUG)
23 #ifndef INCLUDED_sys_types_h
24 #include <sys/types.h>      /* size_t */
25 #define INCLUDED_sys_types_h
26 #endif
27
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 extern size_t fda_get_byte_count(void);
34 extern size_t fda_get_block_count(void);
35 extern size_t fda_sizeof(const void* p);
36 extern void   fda_clear_refs(void);
37 extern void   fda_set_ref(const void* p);
38 extern void   fda_assert_refs(void);
39 extern int    fda_enum_locations(void (*enumfn)(const char*, int, int));
40 extern int    fda_enum_leaks(void (*enumfn)(const char*, int, size_t, void*));
41 extern void   fda_dump_hash(void (*enumfn)(int, int));
42 extern void   fda_set_byte_limit(size_t nbytes);
43 extern int    valid_ptr(const void* p, size_t size);
44
45 extern void* fda_malloc(size_t size, const char* file, int line);
46 extern void* fda_realloc(void* p, size_t size, const char* file, int line);
47 extern void* fda_calloc(size_t nelems, size_t size, const char* file, int line);
48 extern char* fda_strdup(const char* src, const char* file, int line);
49 extern void  fda_free(void* p);
50
51 #if defined(FDA_REDEFINE_MALLOC)
52 #define malloc(s)     fda_malloc((s), __FILE__, __LINE__)
53 #define realloc(p, s) fda_realloc((p), (s), __FILE__, __LINE__)
54 #define calloc(n, s)  fda_calloc((n), (s), __FILE__, __LINE__)
55 #define strdup(s)     fda_strdup((s), __FILE__, __LINE__)
56 #define free(p)       fda_free((p))
57 #endif
58
59 extern void fda_set_lowmem_handler(void (*fn)(void));
60 extern void fda_set_nomem_handler(void (*fn)(void));
61
62 #ifdef __cplusplus
63 }
64 #endif
65
66 #endif /* !defined(NDEBUG) */
67 #endif /* INCLUDED_fda_h */