diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-02-18 17:26:24 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-02-18 17:26:24 +0100 |
commit | 623c781706175767a81287f48fc399bf6aee5a43 (patch) | |
tree | e8472d9641763ca7568e26d353bbe1c27682449a /src/common | |
parent | 1959f0511ee6e7f4c036c4f4b39f2e55e731a89e (diff) |
Simplify die*()
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/cerr.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/common/cerr.c b/src/common/cerr.c index 0032795..8570247 100644 --- a/src/common/cerr.c +++ b/src/common/cerr.c @@ -13,6 +13,8 @@ static bool color; static const char *progname; +static const char *_bold, *_done; + void cerrinit(const char *s) { @@ -24,6 +26,14 @@ cerrinit(const char *s) if (!ev || !*ev) color = true; } + + if (color) { + _bold = SGR_BOLD; + _done = SGR_DONE; + } else { + _bold = ""; + _done = ""; + } } void @@ -33,8 +43,7 @@ die(const char *fmt, ...) int e = errno; va_start(ap, fmt); - fprintf(stderr, "%s%s:%s ", color ? SGR_BOLD : "", progname, - color ? SGR_DONE : ""); + fprintf(stderr, "%s%s:%s ", _bold, progname, _done); vfprintf(stderr, fmt, ap); fprintf(stderr, ": %s\n", strerror(e)); va_end(ap); @@ -48,8 +57,7 @@ diex(const char *fmt, ...) va_list ap; va_start(ap, fmt); - fprintf(stderr, "%s%s:%s ", color ? SGR_BOLD : "", progname, - color ? SGR_DONE : ""); + fprintf(stderr, "%s%s:%s ", _bold, progname, _done); vfprintf(stderr, fmt, ap); fputc('\n', stderr); va_end(ap); @@ -63,8 +71,7 @@ die_with_off(const char *file, size_t off, const char *fmt, ...) va_list ap; va_start(ap, fmt); - fprintf(stderr, "%s%s:%s:%zu:%s ", color ? SGR_BOLD : "", progname, file, - off, color ? SGR_DONE : ""); + fprintf(stderr, "%s%s:%s:%zu:%s ", _bold, progname, file, off, _done); vfprintf(stderr, fmt, ap); fputc('\n', stderr); va_end(ap); |