]> granicus.if.org Git - graphviz/commitdiff
also provide a calloc wrapper in lib/common
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 2 Jun 2020 03:48:54 +0000 (20:48 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 16 Jun 2020 14:23:28 +0000 (07:23 -0700)
lib/common/memory.c
lib/common/memory.h

index ab1006e4761aac823ea8d52ab2d8af3f53b31c8a..5610a450e441f929cbceb8609fab19c8f678b094 100644 (file)
@@ -40,6 +40,16 @@ void *zrealloc(void *ptr, size_t size, size_t elt, size_t osize)
     return p;
 }
 
+void *gcalloc(size_t nmemb, size_t size)
+{
+    char *rv = calloc(nmemb, size);
+    if (rv == NULL) {
+       fprintf(stderr, "out of memory\n");
+       exit(EXIT_FAILURE);
+    }
+    return rv;
+}
+
 void *gmalloc(size_t nbytes)
 {
     char *rv;
index 1f0c53c919d45a7a11341f743892f7d1391a3aa1..6d08dd8cf0aae70b9523bec74735688bdf4a413f 100644 (file)
@@ -45,6 +45,7 @@ extern "C" {
 
     extern void *zmalloc(size_t);
     extern void *zrealloc(void *, size_t, size_t, size_t);
+    extern void *gcalloc(size_t nmemb, size_t size);
     extern void *gmalloc(size_t);
        extern void *grealloc(void *, size_t);
 #undef extern