diff options
| author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2024-10-27 20:10:07 +0100 |
|---|---|---|
| committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2024-10-27 20:10:07 +0100 |
| commit | fcb2476b693ca4c40ad32c7119e27bbeb856865c (patch) | |
| tree | 2bde8374f00eb53f7296e5f1a8ea6b9d4ed32b3d | |
| parent | sync drw.{c,h} from dmenu (diff) | |
| download | dwm-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.c | 13 |
1 files changed, 7 insertions, 6 deletions
| @@ -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 | |||
| 10 | die(const char *fmt, ...) | 11 | die(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 | } |
