X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=xmalloc.h;h=3766043df0203473c303947ecbbe60dc88d49738;hb=33cddbff323efcbae1503e91e6e65b2733da80c7;hp=e186501350c1a8125fa6a845f49bdf4c90bf5cfb;hpb=c8f608f4c4c6d2eb6cb7b12cb60de04cadcb3750;p=~andy%2Ffetchmail diff --git a/xmalloc.h b/xmalloc.h index e1865013..3766043d 100644 --- a/xmalloc.h +++ b/xmalloc.h @@ -1,4 +1,4 @@ -/* xmalloc.h -- split out of fetchmail.h */ +/** \file xmalloc.h -- Declarations for the fail-on-OOM string functions */ #ifndef XMALLOC_H #define XMALLOC_H @@ -6,14 +6,24 @@ #include "config.h" /* xmalloc.c */ -#if defined(HAVE_VOIDPOINTER) -#define XMALLOCTYPE void -#else -#define XMALLOCTYPE char -#endif -XMALLOCTYPE *xmalloc(size_t); -XMALLOCTYPE *xrealloc(/*@null@*/ XMALLOCTYPE *, size_t); + +/** Allocate \a n characters of memory, abort program on failure. */ +void *xmalloc(size_t n); + +/** Reallocate \a n characters of memory, abort program on failure. */ +void *xrealloc(/*@null@*/ void *, 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; } -char *xstrdup(const char *); + +/** 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