summaryrefslogtreecommitdiffstats
path: root/gnulib-local/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2006-11-06 12:47:56 +0000
committerBruno Haible <bruno@clisp.org>2009-06-23 12:14:18 +0200
commite46d7f6e127b69f926c3a25952d156eb01cc39d2 (patch)
tree968d79891abbfa8669ded228304820c3932ac2d6 /gnulib-local/lib
parent13fa5131b37c72af941c0f45c20fe643bee64651 (diff)
downloadexternal_gettext-e46d7f6e127b69f926c3a25952d156eb01cc39d2.zip
external_gettext-e46d7f6e127b69f926c3a25952d156eb01cc39d2.tar.gz
external_gettext-e46d7f6e127b69f926c3a25952d156eb01cc39d2.tar.bz2
New function xnmalloc.
Diffstat (limited to 'gnulib-local/lib')
-rw-r--r--gnulib-local/lib/xalloc.h4
-rw-r--r--gnulib-local/lib/xmalloc.c20
2 files changed, 23 insertions, 1 deletions
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. */