gawk

[old] Sed-like interface to the Gopher protocol
Log | Files | Refs | LICENSE

commit b4d15a0913a03db122763a0928016bf6a91c12bf
parent e21d50921b3ec8a2ccf651134b8327b6cf1da6c8
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Tue,  5 Jan 2021 13:53:18 -0800

Define die() as a variadic macro wrapping warn()

While I don't need printf(3)-like formatting this keeps the diagnostic
messages standard without adding `vwarn` and `err` functions. Perhaps
die() should be the function and warn() the macro but this works
well.

Diffstat:
Mmain.c | 4++--
Mutil.c | 7-------
Mutil.h | 3++-
3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/main.c b/main.c @@ -423,14 +423,14 @@ main(int argc, char const *argv[]) #ifdef __OpenBSD__ if (pledge("stdio rpath wpath cpath inet dns proc exec", NULL) == -1) - die("pledge"); + die(errno, "pledge"); #endif /* __OpenBSD__ */ signal(SIGCHLD, SIG_IGN); signal(SIGINT, sighandler); if (mkdtemp(tmpdir) == NULL) - die("mkdtemp"); + die(errno, "mkdtemp"); status = sgoto(argc, argv, 0, default_address); if (wremove(tmpdir) == -1) return 1; diff --git a/util.c b/util.c @@ -86,13 +86,6 @@ wremove(char const *path) } void -die(char const *s) -{ - fprintf(stderr, "%s: %s: %s\n", getprogname(), s, strerror(errno)); - exit(EXIT_FAILURE); -} - -void tr(char *r, char const *s, int orig, int repl) { for (; *s != '\0'; ++s, ++r) diff --git a/util.h b/util.h @@ -4,13 +4,14 @@ #include <stdarg.h> #include <stdio.h> +#define die(E, ...) { warn(E, __VA_ARGS__); exit(EXIT_FAILURE); } + FILE * wfopen(char const *, char const *); int exists(char const *); int strtorange(unsigned int *, unsigned int, unsigned int, char const *); int warg(int, int, int, char const **); int wfclose(FILE *); int wremove(char const *); -void die(char const *); void tr(char *, char const *, int, int); void warn(int, char const *, ...);