From: Carl Worth Date: Mon, 4 Nov 2013 21:40:06 +0000 (-0800) Subject: xmalloc: Add xcalloc wrapper for calloc X-Git-Url: https://git.cworth.org/git?p=fips;a=commitdiff_plain;h=01b9630089d68e7e0e570cf9793c00a8519df973 xmalloc: Add xcalloc wrapper for calloc Some code will be wanting to use this soon. --- diff --git a/xmalloc.c b/xmalloc.c index 07490c2..e8b9367 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -39,6 +39,20 @@ xmalloc (size_t size) return ret; } +void * +xcalloc (size_t nmemb, size_t size) +{ + void *ret; + + ret = calloc (nmemb, size); + if (size != 0 && ret == NULL) { + fprintf (stderr, "Out of memory\n"); + exit (1); + } + + return ret; +} + void * xrealloc (void *ptr, size_t size) { diff --git a/xmalloc.h b/xmalloc.h index f2eda31..23b3de5 100644 --- a/xmalloc.h +++ b/xmalloc.h @@ -25,6 +25,9 @@ void * xmalloc (size_t size); +void * +xcalloc (size_t nmemb, size_t size); + void * xrealloc (void *ptr, size_t size);