]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add x_calloc()
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 25 Aug 2010 20:11:10 +0000 (22:11 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 25 Aug 2010 20:11:10 +0000 (22:11 +0200)
ccache.h
util.c

index 58f2cd4745302bfbe003048886defbc89f3d40bb..a822d1a7cf885a62f1f4a4355f0c5406ad2a7d85 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -125,6 +125,7 @@ char *x_strdup(const char *s);
 char *x_strndup(const char *s, size_t n);
 void *x_realloc(void *ptr, size_t size);
 void *x_malloc(size_t size);
+void *x_calloc(size_t nmemb, size_t size);
 void traverse(const char *dir, void (*fn)(const char *, struct stat *));
 char *basename(const char *s);
 char *dirname(char *s);
diff --git a/util.c b/util.c
index 2779971d09a1def2f06ab4efb00d8478e06433f5..d11331bc2c72ededd43d91ca72ee82e63ab9cb64 100644 (file)
--- a/util.c
+++ b/util.c
@@ -546,6 +546,18 @@ x_malloc(size_t size)
        return ret;
 }
 
+/* This is like calloc() but dies if the allocation fails. */
+void *
+x_calloc(size_t nmemb, size_t size)
+{
+       void *ret;
+       ret = calloc(nmemb, size);
+       if (!ret) {
+               fatal("x_calloc: Could not allocate %lu bytes", (unsigned long)size);
+       }
+       return ret;
+}
+
 /*
   this is like realloc() but dies if the malloc fails
 */