Files
sbase/libutil/eprintf.c
FRIGN 94e92d9cc0 Refactor eprintf.c
When we move the exit() out of venprintf(), we can reuse it for
weprintf(), which basically had duplicate code.
I also renamed venprintf() to xvprintf (extended vprintf) so it's
more obvious what it actually does.
2015-12-21 09:34:13 +00:00

60 lines
823 B
C

/* 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 xvprintf(const char *, va_list);
void
eprintf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
xvprintf(fmt, ap);
va_end(ap);
exit(1);
}
void
enprintf(int status, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
xvprintf(fmt, ap);
va_end(ap);
exit(status);
}
void
weprintf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
xvprintf(fmt, ap);
va_end(ap);
}
void
xvprintf(const char *fmt, va_list ap)
{
if (strncmp(fmt, "usage", strlen("usage")))
fprintf(stderr, "%s: ", argv0);
vfprintf(stderr, fmt, ap);
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
fputc(' ', stderr);
perror(NULL);
}
}