]>
Commit | Line | Data |
---|---|---|
25f98340 AJ |
1 | #ifndef _SQUID_COMPAT_XALLOC_H |
2 | #define _SQUID_COMPAT_XALLOC_H | |
3 | ||
4 | #ifdef __cplusplus | |
5 | extern "C" { | |
6 | #endif | |
7 | ||
8236d34f A |
8 | /** |
9 | * xcalloc() - same as calloc(3). Used for portability. | |
10 | * Never returns NULL; fatal on error. | |
11 | * | |
12 | * Define failure_notify to receive error message. | |
13 | * otherwise perror() is used to display it. | |
14 | */ | |
15 | void *xcalloc(size_t n, size_t sz); | |
25f98340 | 16 | |
8236d34f A |
17 | /** |
18 | * xmalloc() - same as malloc(3). Used for portability. | |
19 | * Never returns NULL; fatal on error. | |
20 | * | |
21 | * Define failure_notify to receive error message. | |
22 | * otherwise perror() is used to display it. | |
23 | */ | |
24 | void *xmalloc(size_t sz); | |
25f98340 | 25 | |
8236d34f A |
26 | /** |
27 | * xrealloc() - same as realloc(3). Used for portability. | |
28 | * Never returns NULL; fatal on error. | |
29 | */ | |
30 | void *xrealloc(void *s, size_t sz); | |
25f98340 | 31 | |
8236d34f A |
32 | /** |
33 | * xfree() - same as free(3). Used for portability. | |
34 | * Will not call free(3) if s == NULL. | |
35 | * | |
36 | * Define failure_notify to receive error message. | |
37 | * otherwise perror() is used to display it. | |
38 | */ | |
39 | void xfree(void *s); | |
25f98340 | 40 | |
8236d34f A |
41 | /** |
42 | * xxfree() / free_const() - Same as free(3). Used for portability. | |
43 | * Accepts pointers to dynamically allocated const data. | |
44 | * | |
45 | * Define failure_notify to receive error message. | |
46 | * otherwise perror() is used to display it. | |
47 | */ | |
48 | void free_const(const void *s); | |
25f98340 AJ |
49 | |
50 | /// Backward compatibility alias for free_const(const void *s) | |
51 | #define xxfree(x) free_const((x)) | |
52 | ||
8236d34f A |
53 | /** |
54 | * Accepts pointers to dynamically allocated const data. | |
55 | * Will not call free(3) if the pointer is NULL. | |
56 | * Sets the pointer to NULL on completion. | |
57 | * | |
58 | * Use xfree() if the pointer does not need to be set afterward. | |
59 | * | |
60 | * Define failure_notify to receive error message. | |
61 | * otherwise perror() is used to display it. | |
62 | */ | |
2aa24bd9 | 63 | #define safe_free(x) while (x) { xxfree(x); (x) = NULL; } |
25f98340 AJ |
64 | |
65 | ||
66 | #if XMALLOC_STATISTICS | |
8236d34f | 67 | void malloc_statistics(void (*func) (int, int, int, void *), void *data); |
25f98340 AJ |
68 | #endif |
69 | ||
70 | #ifdef __cplusplus | |
71 | } | |
72 | #endif | |
73 | ||
74 | #endif /* _SQUID_COMPAT_XALLOC_H */ |