summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gnulib-local/ChangeLog6
-rw-r--r--gnulib-local/lib/xalloc.h4
-rw-r--r--gnulib-local/lib/xmalloc.c20
3 files changed, 29 insertions, 1 deletions
diff --git a/gnulib-local/ChangeLog b/gnulib-local/ChangeLog
index ff6c4ac..b4a2efc 100644
--- a/gnulib-local/ChangeLog
+++ b/gnulib-local/ChangeLog
@@ -1,3 +1,9 @@
+2006-11-02 Bruno Haible <bruno@clisp.org>
+
+ * lib/xalloc.h (xnmalloc): New declaration. From gnulib xalloc.h.
+ * lib/xmalloc.c (fixup_null_alloc): Write NULL, not 0.
+ (xnmalloc): New function.
+
2006-10-29 Bruno Haible <bruno@clisp.org>
* lib/fstrcmp.h: Wrap declarations in extern "C".
diff --git a/gnulib-local/lib/xalloc.h b/gnulib-local/lib/xalloc.h
index a12c984..a044610 100644
--- a/gnulib-local/lib/xalloc.h
+++ b/gnulib-local/lib/xalloc.h
@@ -32,6 +32,10 @@ extern "C" {
/* Allocate SIZE bytes of memory dynamically, with error checking. */
extern void *xmalloc (size_t size);
+/* Allocate memory for NMEMB elements of SIZE bytes, with error checking.
+ SIZE must be > 0. */
+extern void *xnmalloc (size_t nmemb, size_t size);
+
/* Allocate SIZE bytes of memory dynamically, with error checking,
and zero it. */
extern void *xzalloc (size_t size);
diff --git a/gnulib-local/lib/xmalloc.c b/gnulib-local/lib/xmalloc.c
index 8f06d89..ed9758e 100644
--- a/gnulib-local/lib/xmalloc.c
+++ b/gnulib-local/lib/xmalloc.c
@@ -48,7 +48,7 @@ fixup_null_alloc (size_t n)
{
void *p;
- p = 0;
+ p = NULL;
if (n == 0)
p = malloc ((size_t) 1);
if (p == NULL)
@@ -69,6 +69,24 @@ xmalloc (size_t n)
return p;
}
+/* Allocate memory for NMEMB elements of SIZE bytes, with error checking.
+ SIZE must be > 0. */
+
+void *
+xnmalloc (size_t nmemb, size_t size)
+{
+ size_t n;
+ void *p;
+
+ if (xalloc_oversized (nmemb, size))
+ xalloc_die ();
+ n = nmemb * size;
+ p = malloc (n);
+ if (p == NULL)
+ p = fixup_null_alloc (n);
+ return p;
+}
+
/* Allocate SIZE bytes of memory dynamically, with error checking,
and zero it. */