]> Pileus Git - ~andy/fetchmail/blob - xmalloc.h
socket.c: drop OPENSSL_NO_SSL_INTERN, no longer needed.
[~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 #include <stdlib.h>
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /* xmalloc.c */
14
15 /** Allocate \a n characters of memory, abort program on failure. */
16 void *xmalloc(size_t n);
17
18 /** Reallocate \a n characters of memory, abort program on failure. */
19 void *xrealloc(/*@null@*/ void *, 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 /** Duplicate at most the first \a n characters from \a src to a newly
29  * malloc()d memory region and NUL-terminate it, and return its pointer, abort
30  * program on failure. The memory size is the lesser of either the string
31  * length including NUL byte or n + 1. */
32 char *xstrndup(const char *src, size_t n);
33
34 #ifdef __cplusplus
35 }
36 #endif
37
38 #endif