2013-08-06 07:16:27 -04:00
|
|
|
/* 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);
|
2014-10-02 18:45:25 -04:00
|
|
|
venprintf(1, fmt, ap);
|
2013-08-06 07:16:27 -04:00
|
|
|
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)
|
|
|
|
{
|
2014-03-28 11:56:28 -04:00
|
|
|
#ifdef DEBUG
|
2014-02-10 07:32:40 -05:00
|
|
|
fprintf(stderr, "%s: ", argv0);
|
2014-03-28 11:52:37 -04:00
|
|
|
#endif
|
2013-08-12 06:03:53 -04:00
|
|
|
|
2013-08-06 07:16:27 -04:00
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
|
2014-07-09 11:39:32 -04:00
|
|
|
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
|
2013-08-06 07:16:27 -04:00
|
|
|
fputc(' ', stderr);
|
|
|
|
perror(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(status);
|
|
|
|
}
|
2014-03-12 10:18:29 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
weprintf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2014-03-28 11:52:37 -04:00
|
|
|
#ifdef DEBUG
|
2014-03-12 10:18:29 -04:00
|
|
|
fprintf(stderr, "%s: ", argv0);
|
2014-03-12 10:29:11 -04:00
|
|
|
#endif
|
2014-03-12 10:18:29 -04:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
|
|
|
|
fputc(' ', stderr);
|
|
|
|
perror(NULL);
|
|
|
|
}
|
|
|
|
}
|