X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=xmalloc.h;h=3766043df0203473c303947ecbbe60dc88d49738;hb=98cfcef26048bba06975e68a1aad05a8bac0d65d;hp=690b574199af4313deb6d1c95689f309e6d5661c;hpb=0c92635914becb4f6913c3f1d5a6f3756325315b;p=~andy%2Ffetchmail diff --git a/xmalloc.h b/xmalloc.h index 690b5741..3766043d 100644 --- a/xmalloc.h +++ b/xmalloc.h @@ -6,17 +6,12 @@ #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); +void *xmalloc(size_t n); /** Reallocate \a n characters of memory, abort program on failure. */ -XMALLOCTYPE *xrealloc(/*@null@*/ XMALLOCTYPE *, size_t n); +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; } @@ -25,4 +20,10 @@ XMALLOCTYPE *xrealloc(/*@null@*/ XMALLOCTYPE *, size_t n); * 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