X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=util.c;h=124bcd59aec1a9c93297d8c05d4c288dc0322a7a;hb=a71424ac0e74f05274a8009f07487112730fa472;hp=d0444c552d68202d20ff8d8fe4514cd71abe8691;hpb=81bcf078f6c510314f140471efb8952160fdb3ad;p=dmenu.git diff --git a/util.c b/util.c index d0444c5..124bcd5 100644 --- a/util.c +++ b/util.c @@ -1,5 +1,4 @@ -/* - * (C)opyright MMVI Anselm R. Garbe +/* (C)opyright MMVI-MMVII Anselm R. Garbe * See LICENSE file for license details. */ #include "dmenu.h" @@ -7,23 +6,13 @@ #include #include #include -#include -#include - -/* static */ - -static void -badmalloc(unsigned int size) { - eprint("fatal: could not malloc() %u bytes\n", size); -} - -/* extern */ void * emalloc(unsigned int size) { void *res = malloc(size); + if(!res) - badmalloc(size); + eprint("fatal: could not malloc() %u bytes\n", size); return res; } @@ -40,7 +29,8 @@ eprint(const char *errstr, ...) { char * estrdup(const char *str) { void *res = strdup(str); + if(!res) - badmalloc(strlen(str)); + eprint("fatal: could not malloc() %u bytes\n", strlen(str)); return res; }