]> Pileus Git - ~andy/fetchmail/blob - xmalloc.h
690b574199af4313deb6d1c95689f309e6d5661c
[~andy/fetchmail] / xmalloc.h
1 /** \file xmalloc.h -- Declarations for the fail-on-OOM string functions */
2
3 #ifndef XMALLOC_H
4 #define XMALLOC_H
5
6 #include "config.h"
7
8 /* xmalloc.c */
9 #if defined(HAVE_VOIDPOINTER)
10 #define XMALLOCTYPE void
11 #else
12 #define XMALLOCTYPE char
13 #endif
14
15 /** Allocate \a n characters of memory, abort program on failure. */
16 XMALLOCTYPE *xmalloc(size_t n);
17
18 /** Reallocate \a n characters of memory, abort program on failure. */
19 XMALLOCTYPE *xrealloc(/*@null@*/ XMALLOCTYPE *, size_t n);
20
21 /** Free memory at position \a p and set pointer \a p to NULL afterwards. */
22 #define xfree(p) { if (p) { free(p); } (p) = 0; }
23
24 /** Duplicate string \a src to a newly malloc()d memory region and return its
25  * pointer, abort program on failure. */
26 char *xstrdup(const char *src);
27
28 #endif