diff options
author | sin <sin@2f30.org> | 2014-09-26 15:55:40 +0100 |
---|---|---|
committer | sin <sin@2f30.org> | 2014-09-26 15:55:40 +0100 |
commit | 5994d52d71816317553d081360980ad6708d295c (patch) | |
tree | ce70638a1301996fd07c49e933c3b6bb0040cd8e /eprintf.c | |
parent | 7077107778a54cd326e3898318ce53da4de28fc5 (diff) |
Add eprintf.c
Diffstat (limited to 'eprintf.c')
-rw-r--r-- | eprintf.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/eprintf.c b/eprintf.c new file mode 100644 index 0000000..f89cc3d --- /dev/null +++ b/eprintf.c @@ -0,0 +1,59 @@ +/* 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 +enprintf(int status, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + venprintf(status, fmt, ap); + va_end(ap); +} + +void +eprintf(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + venprintf(EXIT_FAILURE, fmt, ap); + va_end(ap); +} + +void +venprintf(int status, const char *fmt, va_list ap) +{ + vfprintf(stderr, fmt, ap); + + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { + fputc(' ', stderr); + perror(NULL); + } + + exit(status); +} + +void +weprintf(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { + fputc(' ', stderr); + perror(NULL); + } +} |