+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".
/* 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);
{
void *p;
- p = 0;
+ p = NULL;
if (n == 0)
p = malloc ((size_t) 1);
if (p == NULL)
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. */