]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
New function xnmalloc.
authorBruno Haible <bruno@clisp.org>
Mon, 6 Nov 2006 12:47:56 +0000 (12:47 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:14:18 +0000 (12:14 +0200)
gnulib-local/ChangeLog
gnulib-local/lib/xalloc.h
gnulib-local/lib/xmalloc.c

index ff6c4ac1d16ff6ad234c06904fa30d9cde405b74..b4a2efcc383be8a3b5a6afd9be4eceb520869ed7 100644 (file)
@@ -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".
index a12c984b94eb52353bf0ebe7dff2d6b38f58d7b0..a044610f520c42d67ebd8d385e180fba2a278f3a 100644 (file)
@@ -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);
index 8f06d891d0e9100ed7fd38d7e03f438cf6b96ea9..ed9758ed6951917d50e523c5ea72c8dfdb657d24 100644 (file)
@@ -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.  */