From b7b5462bde6ed791c19ea5a918cb4ff1dd532175 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 4 May 2015 22:06:17 +0200 Subject: [PATCH 3/4] util: die(): print errno if last character is ':' ... and make use of it for some functions. --- dwm.c | 8 ++++---- util.c | 15 +++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/dwm.c b/dwm.c index f447f60..1446800 100644 --- a/dwm.c +++ b/dwm.c @@ -632,7 +632,7 @@ createmon(void) { Monitor *m; if(!(m = (Monitor *)calloc(1, sizeof(Monitor)))) - die("fatal: could not malloc() %u bytes\n", sizeof(Monitor)); + die("fatal: could not malloc() %u bytes:", sizeof(Monitor)); m->tagset[0] = m->tagset[1] = 1; m->mfact = mfact; m->nmaster = nmaster; @@ -1011,7 +1011,7 @@ manage(Window w, XWindowAttributes *wa) { XWindowChanges wc; if(!(c = calloc(1, sizeof(Client)))) - die("fatal: could not malloc() %u bytes\n", sizeof(Client)); + die("fatal: could not malloc() %u bytes:", sizeof(Client)); c->win = w; updatetitle(c); if(XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { @@ -1575,7 +1575,7 @@ showhide(Client *c) { void sigchld(int unused) { if(signal(SIGCHLD, sigchld) == SIG_ERR) - die("Can't install SIGCHLD handler"); + die("Can't install SIGCHLD handler:"); while(0 < waitpid(-1, NULL, WNOHANG)); } @@ -1792,7 +1792,7 @@ updategeom(void) { for(n = 0, m = mons; m; m = m->next, n++); /* only consider unique geometries as separate screens */ if(!(unique = (XineramaScreenInfo *)malloc(sizeof(XineramaScreenInfo) * nn))) - die("fatal: could not malloc() %u bytes\n", sizeof(XineramaScreenInfo) * nn); + die("fatal: could not malloc() %u bytes:", sizeof(XineramaScreenInfo) * nn); for(i = 0, j = 0; i < nn; i++) if(isuniquegeom(unique, j, &info[i])) memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); diff --git a/util.c b/util.c index 51acd1a..78d3035 100644 --- a/util.c +++ b/util.c @@ -2,16 +2,23 @@ #include #include #include +#include #include "util.h" 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); } -- 2.3.7