X-Git-Url: https://git.danieliu.xyz/?p=dwm.git;a=blobdiff_plain;f=util.c;h=6b703e9b8180fb32ce3e3e018a2bf0124748c797;hp=51acd1aed516d3cdeff714c31b9cd8f455c6c50e;hb=646b351cc79845f4cc77415dfff474b9ae0053d9;hpb=e3b7e1d620e18818222c1e5033356ae29dd49e7f diff --git a/util.c b/util.c index 51acd1a..6b703e9 100644 --- a/util.c +++ b/util.c @@ -2,16 +2,32 @@ #include #include #include +#include #include "util.h" +void * +ecalloc(size_t nmemb, size_t size) +{ + void *p; + + if (!(p = calloc(nmemb, size))) + perror(NULL); + return p; +} + void -die(const char *errstr, ...) { +die(const char *fmt, ...) { va_list ap; - va_start(ap, errstr); - vfprintf(stderr, errstr, ap); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); va_end(ap); - exit(EXIT_FAILURE); -} + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { + fputc(' ', stderr); + perror(NULL); + } + + exit(1); +}