]> Pileus Git - ~andy/fetchmail/blob - xmalloc.h
Attempt merging from 6.3.24.
[~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
10 /** Allocate \a n characters of memory, abort program on failure. */
11 void *xmalloc(size_t n);
12
13 /** Reallocate \a n characters of memory, abort program on failure. */
14 void *xrealloc(/*@null@*/ void *, size_t n);
15
16 /** Free memory at position \a p and set pointer \a p to NULL afterwards. */
17 #define xfree(p) { if (p) { free(p); } (p) = 0; }
18
19 /** Duplicate string \a src to a newly malloc()d memory region and return its
20  * pointer, abort program on failure. */
21 char *xstrdup(const char *src);
22
23 /** Duplicate at most the first \a n characters from \a src to a newly
24  * malloc()d memory region and NUL-terminate it, and return its pointer, abort
25  * program on failure. The memory size is the lesser of either the string
26  * length including NUL byte or n + 1. */
27 char *xstrndup(const char *src, size_t n);
28
29 #endif