X-Git-Url: https://git.xinqibao.xyz/dwm.git/blobdiff_plain/e3b7e1d620e18818222c1e5033356ae29dd49e7f..646b351cc79845f4cc77415dfff474b9ae0053d9:/util.c 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); +}