summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2024-10-27 20:10:07 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2024-10-27 20:10:07 +0100
commitfcb2476b693ca4c40ad32c7119e27bbeb856865c (patch)
tree2bde8374f00eb53f7296e5f1a8ea6b9d4ed32b3d
parentsync drw.{c,h} from dmenu (diff)
downloaddwm-fcb2476b693ca4c40ad32c7119e27bbeb856865c.tar.gz
dwm-fcb2476b693ca4c40ad32c7119e27bbeb856865c.zip
util.c: output function might override errno and thus affect perror()
Original patch by Raymond Cole with some modifications, thanks!
Diffstat (limited to '')
-rw-r--r--util.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/util.c b/util.c
index 96b82c9..8e26a51 100644
--- a/util.c
+++ b/util.c
@@ -1,4 +1,5 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2#include <errno.h>
2#include <stdarg.h> 3#include <stdarg.h>
3#include <stdio.h> 4#include <stdio.h>
4#include <stdlib.h> 5#include <stdlib.h>
@@ -10,17 +11,17 @@ void
10die(const char *fmt, ...) 11die(const char *fmt, ...)
11{ 12{
12 va_list ap; 13 va_list ap;
14 int saved_errno;
15
16 saved_errno = errno;
13 17
14 va_start(ap, fmt); 18 va_start(ap, fmt);
15 vfprintf(stderr, fmt, ap); 19 vfprintf(stderr, fmt, ap);
16 va_end(ap); 20 va_end(ap);
17 21
18 if (fmt[0] && fmt[strlen(fmt)-1] == ':') { 22 if (fmt[0] && fmt[strlen(fmt)-1] == ':')
19 fputc(' ', stderr); 23 fprintf(stderr, " %s", strerror(saved_errno));
20 perror(NULL); 24 fputc('\n', stderr);
21 } else {
22 fputc('\n', stderr);
23 }
24 25
25 exit(1); 26 exit(1);
26} 27}