File: xmalloc.h

package info (click to toggle)
fetchmail 6.3.26-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,980 kB
  • ctags: 4,235
  • sloc: ansic: 29,508; sh: 5,796; perl: 3,181; python: 1,955; yacc: 458; makefile: 350; lex: 265; awk: 124; lisp: 84; exp: 43; sed: 16
file content (34 lines) | stat: -rw-r--r-- 1,075 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/** \file xmalloc.h -- Declarations for the fail-on-OOM string functions */

#ifndef XMALLOC_H
#define XMALLOC_H

#include "config.h"

/* xmalloc.c */
#if defined(HAVE_VOIDPOINTER)
#define XMALLOCTYPE void
#else
#define XMALLOCTYPE char
#endif

/** Allocate \a n characters of memory, abort program on failure. */
XMALLOCTYPE *xmalloc(size_t n);

/** Reallocate \a n characters of memory, abort program on failure. */
XMALLOCTYPE *xrealloc(/*@null@*/ XMALLOCTYPE *, size_t n);

/** Free memory at position \a p and set pointer \a p to NULL afterwards. */
#define xfree(p) { if (p) { free(p); } (p) = 0; }

/** Duplicate string \a src to a newly malloc()d memory region and return its
 * pointer, abort program on failure. */
char *xstrdup(const char *src);

/** Duplicate at most the first \a n characters from \a src to a newly
 * malloc()d memory region and NUL-terminate it, and return its pointer, abort
 * program on failure. The memory size is the lesser of either the string
 * length including NUL byte or n + 1. */
char *xstrndup(const char *src, size_t n);

#endif