X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/b02a191a4c725fb987c56dc41b2a81fbd6bff44c..7711f3fc00259e55f630cfe6104eff3083dc9d77:/sbr/utils.c diff --git a/sbr/utils.c b/sbr/utils.c index 9dece994..c6f75e07 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -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.