sock: in listen_sock(), add debug message when socket() call failed.
[obnox/tinyproxy.git] / src / heap.h
1 /* tinyproxy - A fast light-weight HTTP proxy
2  * Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 /* See 'heap.c' for detailed information. */
20
21 #ifndef TINYPROXY_HEAP_H
22 #define TINYPROXY_HEAP_H
23
24 /*
25  * The following is to allow for better memory checking.
26  */
27 #ifndef NDEBUG
28
29 extern void *debugging_calloc (size_t nmemb, size_t size, const char *file,
30                                unsigned long line);
31 extern void *debugging_malloc (size_t size, const char *file,
32                                unsigned long line);
33 extern void debugging_free (void *ptr, const char *file, unsigned long line);
34 extern void *debugging_realloc (void *ptr, size_t size, const char *file,
35                                 unsigned long line);
36 extern char *debugging_strdup (const char *s, const char *file,
37                                unsigned long line);
38
39 #  define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__)
40 #  define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
41 #  define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__)
42 #  define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__)
43 #  define safefree(x) (debugging_free(x, __FILE__, __LINE__), *(&(x)) = NULL)
44
45 #else
46
47 #  define safecalloc(x, y) calloc(x, y)
48 #  define safemalloc(x) malloc(x)
49 #  define saferealloc(x, y) realloc(x, y)
50 #  define safefree(x) (free (x), *(&(x)) = NULL)
51 #  define safestrdup(x) strdup(x)
52
53 #endif
54
55 /*
56  * Allocate memory from the "shared" region of memory.
57  */
58 extern void *malloc_shared_memory (size_t size);
59 extern void *calloc_shared_memory (size_t nmemb, size_t size);
60
61 #endif