diff options
author | sin <sin@2f30.org> | 2014-02-06 11:14:33 +0000 |
---|---|---|
committer | sin <sin@2f30.org> | 2014-02-06 11:14:33 +0000 |
commit | 51664faebcc10b53a1a78cff95f0efc04a2c7f8e (patch) | |
tree | feb5e28aab2356c97a4624bffc45948ca6fee4be /util |
Initial commit
Diffstat (limited to 'util')
-rw-r--r-- | util/eprintf.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/util/eprintf.c b/util/eprintf.c new file mode 100644 index 0000000..6d6fa65 --- /dev/null +++ b/util/eprintf.c @@ -0,0 +1,46 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "../util.h" + +char *argv0; + +static void venprintf(int, const char *, va_list); + +void +eprintf(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + venprintf(EXIT_FAILURE, fmt, ap); + va_end(ap); +} + +void +enprintf(int status, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + venprintf(status, fmt, ap); + va_end(ap); +} + +void +venprintf(int status, const char *fmt, va_list ap) +{ + fprintf(stderr, "%s: ", argv0); + + vfprintf(stderr, fmt, ap); + + if(fmt[0] && fmt[strlen(fmt)-1] == ':') { + fputc(' ', stderr); + perror(NULL); + } + + exit(status); +} |