From: Bruno Haible Date: Mon, 6 Nov 2006 20:34:54 +0000 (+0000) Subject: Add two more functions, for gnulib compatibility. X-Git-Tag: v0.17~673 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de3224151261c0250c3759ee8d20293f802b0230;p=thirdparty%2Fgettext.git Add two more functions, for gnulib compatibility. --- diff --git a/gnulib-local/ChangeLog b/gnulib-local/ChangeLog index a9237a371..91b82d526 100644 --- a/gnulib-local/ChangeLog +++ b/gnulib-local/ChangeLog @@ -1,3 +1,9 @@ +2006-11-06 Bruno Haible + + * lib/xalloc.h (xcharalloc): New macro. + (xmemdup): New declaration. + * lib/xstrdup.c (xmemdup): New function. + 2006-11-03 Bruno Haible * lib/xalloc.h (XMALLOC, XNMALLOC, XZALLOC, XCALLOC): New macros. diff --git a/gnulib-local/lib/xalloc.h b/gnulib-local/lib/xalloc.h index ceb1eb926..1168a546c 100644 --- a/gnulib-local/lib/xalloc.h +++ b/gnulib-local/lib/xalloc.h @@ -111,9 +111,17 @@ xnboundedmalloc (size_t n, size_t bound, size_t s) #define XCALLOC(N,T) \ ((T *) xcalloc (N, sizeof (T))) +/* Return a pointer to a new buffer of N bytes. This is like xmalloc, + except it returns char *. */ +#define xcharalloc(N) \ + XNMALLOC (N, char) + /* Defined in xstrdup.c. */ +/* Return a newly allocated copy of the N bytes of memory starting at P. */ +extern void *xmemdup (const void *p, size_t n); + /* Return a newly allocated copy of STRING. */ extern char *xstrdup (const char *string); diff --git a/gnulib-local/lib/xstrdup.c b/gnulib-local/lib/xstrdup.c index cb3c53be6..842e99a29 100644 --- a/gnulib-local/lib/xstrdup.c +++ b/gnulib-local/lib/xstrdup.c @@ -22,6 +22,16 @@ #include +/* Return a newly allocated copy of the N bytes of memory starting at P. */ + +void * +xmemdup (const void *p, size_t n) +{ + void *q = xmalloc (n); + memcpy (q, p, n); + return q; +} + /* Return a newly allocated copy of STRING. */ char *