]>
Commit | Line | Data |
---|---|---|
37be9888 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
37be9888 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
25f98340 AJ |
9 | #ifndef _SQUID_COMPAT_XALLOC_H |
10 | #define _SQUID_COMPAT_XALLOC_H | |
11 | ||
12 | #ifdef __cplusplus | |
13 | extern "C" { | |
14 | #endif | |
15 | ||
f53969cc SM |
16 | /** |
17 | * xcalloc() - same as calloc(3). Used for portability. | |
18 | * Never returns NULL; fatal on error. | |
19 | * | |
20 | * Define failure_notify to receive error message. | |
21 | * otherwise perror() is used to display it. | |
22 | */ | |
23 | void *xcalloc(size_t n, size_t sz); | |
25f98340 | 24 | |
f53969cc SM |
25 | /** |
26 | * xmalloc() - same as malloc(3). Used for portability. | |
27 | * Never returns NULL; fatal on error. | |
28 | * | |
29 | * Define failure_notify to receive error message. | |
30 | * otherwise perror() is used to display it. | |
31 | */ | |
32 | void *xmalloc(size_t sz); | |
25f98340 | 33 | |
f53969cc SM |
34 | /** |
35 | * xrealloc() - same as realloc(3). Used for portability. | |
36 | * Never returns NULL; fatal on error. | |
37 | */ | |
38 | void *xrealloc(void *s, size_t sz); | |
25f98340 | 39 | |
f53969cc SM |
40 | /** |
41 | * free_const() - Same as free(3). Used for portability. | |
42 | * Accepts pointers to dynamically allocated const data. | |
43 | * | |
44 | * Define failure_notify to receive error message. | |
45 | * otherwise perror() is used to display it. | |
46 | */ | |
47 | void free_const(const void *s); | |
25f98340 | 48 | |
f53969cc SM |
49 | /** |
50 | * xfree() - same as free(3). Used for portability. | |
51 | * Accepts pointers to dynamically allocated const data. | |
52 | * Will not call free(3) if the pointer is NULL. | |
53 | * | |
54 | * Pointer is left with a value on completion. | |
55 | * Use safe_free() if the pointer needs to be set to NULL afterward. | |
56 | * | |
57 | * Define failure_notify to receive error message. | |
58 | * otherwise perror() is used to display it. | |
59 | */ | |
60 | static inline void xfree(const void *p) { if (p) free_const(p); } | |
25f98340 | 61 | |
f53969cc SM |
62 | /** |
63 | * safe_free() - same as free(3). Used for portability. | |
64 | * Accepts pointers to dynamically allocated const data. | |
65 | * Will not call free(3) if the pointer is NULL. | |
66 | * Sets the pointer to NULL on completion. | |
67 | * | |
68 | * Use xfree() if the pointer does not need to be set afterward. | |
69 | * | |
70 | * Define failure_notify to receive error message. | |
71 | * otherwise perror() is used to display it. | |
72 | */ | |
42b93184 | 73 | #define safe_free(x) while ((x)) { free_const((x)); (x) = NULL; } |
25f98340 | 74 | |
25f98340 AJ |
75 | #ifdef __cplusplus |
76 | } | |
77 | #endif | |
78 | ||
0210ab23 AJ |
79 | #if XMALLOC_STATISTICS |
80 | extern void malloc_statistics(void (*func) (int, int, int, void *), void *data); | |
81 | #endif | |
82 | ||
25f98340 | 83 | #endif /* _SQUID_COMPAT_XALLOC_H */ |
f53969cc | 84 |