aboutsummaryrefslogtreecommitdiffstats
path: root/eprintf.c
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2016-12-22 14:18:38 +0100
committerTomasz Kramkowski <tk@the-tk.com>2016-12-22 14:18:38 +0100
commit04be5b1456b381303709fdc90385fe74dad1bd10 (patch)
treeb8f07ed1a0037587739d166d23954d3ca8102d81 /eprintf.c
parentfad06882fe3305983292dfa34d335ec461761b61 (diff)
downloadhktool-04be5b1456b381303709fdc90385fe74dad1bd10.tar.gz
hktool-04be5b1456b381303709fdc90385fe74dad1bd10.tar.xz
hktool-04be5b1456b381303709fdc90385fe74dad1bd10.zip
eprintf: add ecalloc
Add ecalloc as an error handling calloc wrapper.
Diffstat (limited to 'eprintf.c')
-rw-r--r--eprintf.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/eprintf.c b/eprintf.c
index 7a885b3..41c043f 100644
--- a/eprintf.c
+++ b/eprintf.c
@@ -76,6 +76,18 @@ void *emalloc(size_t n)
return p;
}
+/* ecalloc: attempt to allocate memory or exit on error */
+void *ecalloc(size_t nmemb, size_t size)
+{
+ void *p;
+
+ p = calloc(nmemb, size);
+ if (p == NULL)
+ eprintf("ecalloc(%zu, %zu) failed:", nmemb, size);
+
+ return p;
+}
+
/* erealloc: attempt to reallocate memory or exit on error */
void *erealloc(void *p, size_t n)
{