From 410ef5960fde8a8d601264859032bb9032ead6f6 Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Tue, 1 Aug 2017 20:00:08 +0200 Subject: Revert some changes and add old code from dmenu --- util.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 51acd1a..fe044fc 100644 --- a/util.c +++ b/util.c @@ -2,16 +2,34 @@ #include #include #include +#include #include "util.h" +void * +ecalloc(size_t nmemb, size_t size) +{ + void *p; + + if (!(p = calloc(nmemb, size))) + die("calloc:"); + 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); + } else { + fputc('\n', stderr); + } + + exit(1); +} -- cgit v1.2.3