X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=sbr%2Futils.c;h=b0e8274f2a0dde220ca3058c3f6b5064ada32047;hb=0595979e1f0514b3da28762f336b3b9ac9eec5c5;hp=f23e1d03953e5f78e156c6781b014b3642c4063e;hpb=cf1205b5cbea2f0cd6ea710ec16c637df85b647c;p=mmh diff --git a/sbr/utils.c b/sbr/utils.c index f23e1d0..b0e8274 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -49,7 +49,7 @@ mh_xrealloc(void *ptr, size_t size) /* Some non-POSIX realloc()s don't cope with realloc(NULL,sz) */ if (!ptr) { - return mh_xmalloc(size); + return mh_xcalloc((size_t) 1, size); } if (size == 0) @@ -63,13 +63,31 @@ mh_xrealloc(void *ptr, size_t size) } /* + * Safely call calloc + */ +void * +mh_xcalloc(size_t nmemb, size_t size) +{ + void *memory; + + if (nmemb == 0 || size == 0) + adios(EX_SOFTWARE, NULL, "Tried to calloc 0 bytes"); + + if ((memory = calloc(nmemb, size))) { + return memory; + } else { + adios(EX_OSERR, NULL, "calloc failed"); + } +} + +/* ** Return the present working directory, if the current directory does not ** exist, or is too long, make / the pwd. */ char * pwd(void) { - register char *cp; + char *cp; static char curwd[PATH_MAX]; if (!getcwd(curwd, PATH_MAX)) {