summaryrefslogtreecommitdiff
path: root/xmalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'xmalloc.c')
-rw-r--r--xmalloc.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/xmalloc.c b/xmalloc.c
index 02d6ce4..bdb6234 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -34,6 +34,21 @@ void *xmalloc(size_t size)
return ptr;
}
+void *xcalloc(size_t nmemb, size_t size)
+{
+ void *ptr;
+
+ if (unlikely(nmemb == 0 || size == 0))
+ panic("xcalloc: zero size\n");
+
+ ptr = calloc(nmemb, size);
+ if (unlikely(ptr == NULL))
+ panic("xcalloc: out of memory (allocating %zu members of "
+ "%zu bytes)\n", nmemb, size);
+
+ return ptr;
+}
+
void *xzmalloc(size_t size)
{
void *ptr = xmalloc(size);