]> diplodocus.org Git - nmh/blobdiff - sbr/utils.c
Fix error message to correctly report the program that failed to execute
[nmh] / sbr / utils.c
index 9dece994980ae44cea38f51e188d4af4713913a6..c6f75e07379e3c47878359c7eb88c6a4485a945f 100644 (file)
@@ -64,6 +64,24 @@ mh_xrealloc(void *ptr, size_t size)
     return memory;
 }
 
+/*
+ * Safely call calloc
+ */
+void *
+mh_xcalloc(size_t nmemb, size_t size)
+{
+    void *memory;
+
+    if (nmemb == 0  ||  size == 0)
+        adios(NULL, "Tried to calloc 0 bytes");
+
+    if ((memory = calloc(nmemb, size))) {
+        return memory;
+    } else {
+        adios(NULL, "calloc failed");
+    }
+}
+
 /*
  * Return the present working directory, if the current directory does not
  * exist, or is too long, make / the pwd.