X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=util.c;h=9b27512e1efe5fb258b7fa65a07b476fb0bc27fc;hb=10fd4f275feaef0b505cc8e65a2deccae69a0968;hp=d0444c552d68202d20ff8d8fe4514cd71abe8691;hpb=81bcf078f6c510314f140471efb8952160fdb3ad;p=dmenu.git diff --git a/util.c b/util.c index d0444c5..9b27512 100644 --- a/util.c +++ b/util.c @@ -1,46 +1,23 @@ -/* - * (C)opyright MMVI Anselm R. Garbe - * See LICENSE file for license details. - */ -#include "dmenu.h" +/* See LICENSE file for copyright and license details. */ #include #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); - return res; -} +#include "util.h" void -eprint(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); -} -char * -estrdup(const char *str) { - void *res = strdup(str); - if(!res) - badmalloc(strlen(str)); - return res; + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { + fputc(' ', stderr); + perror(NULL); + } + + exit(1); }