]> Pileus Git - ~andy/fetchmail/blob - xmalloc.h
Update <sq> Albanian translation to fetchmail-6.4.3-rc2
[~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 #if defined(HAVE_VOIDPOINTER) || defined(__cplusplus)
15 #define XMALLOCTYPE void
16 #else
17 #define XMALLOCTYPE char
18 #endif
19
20 /** Allocate \a n characters of memory, abort program on failure. */
21 XMALLOCTYPE *xmalloc(size_t n);
22
23 /** Reallocate \a n characters of memory, abort program on failure. */
24 XMALLOCTYPE *xrealloc(/*@null@*/ void *, size_t n);
25
26 /** Free memory at position \a p and set pointer \a p to NULL afterwards. */
27 #define xfree(p) { if (p) { free(p); } (p) = 0; }
28
29 /** Duplicate string \a src to a newly malloc()d memory region and return its
30  * pointer, abort program on failure. */
31 char *xstrdup(const char *src);
32
33 /** Duplicate at most the first \a n characters from \a src to a newly
34  * malloc()d memory region and NUL-terminate it, and return its pointer, abort
35  * program on failure. The memory size is the lesser of either the string
36  * length including NUL byte or n + 1. */
37 char *xstrndup(const char *src, size_t n);
38
39 #ifdef __cplusplus
40 }
41 #endif
42
43 #endif