2011-05-23 01:36:34 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <stdarg.h>
|
2012-05-14 20:28:41 +00:00
|
|
|
#include <stdio.h>
|
2011-05-23 01:36:34 +00:00
|
|
|
#include <stdlib.h>
|
2012-05-14 20:28:41 +00:00
|
|
|
#include <string.h>
|
2013-03-05 20:46:48 +00:00
|
|
|
|
2011-05-24 12:00:30 +00:00
|
|
|
#include "../util.h"
|
2011-05-23 01:36:34 +00:00
|
|
|
|
2012-05-14 20:28:41 +00:00
|
|
|
char *argv0;
|
|
|
|
|
2015-12-21 08:28:44 +00:00
|
|
|
static void xvprintf(const char *, va_list);
|
2011-06-18 05:41:28 +00:00
|
|
|
|
2011-05-23 01:36:34 +00:00
|
|
|
void
|
|
|
|
eprintf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2015-12-21 08:28:44 +00:00
|
|
|
xvprintf(fmt, ap);
|
2011-05-23 01:36:34 +00:00
|
|
|
va_end(ap);
|
2015-12-21 08:28:44 +00:00
|
|
|
|
|
|
|
exit(1);
|
2011-05-23 01:36:34 +00:00
|
|
|
}
|
2012-05-14 20:28:41 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
enprintf(int status, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2015-12-21 08:28:44 +00:00
|
|
|
xvprintf(fmt, ap);
|
2012-05-14 20:28:41 +00:00
|
|
|
va_end(ap);
|
2013-03-05 20:46:48 +00:00
|
|
|
|
2012-05-14 20:28:41 +00:00
|
|
|
exit(status);
|
|
|
|
}
|
2013-03-05 20:46:48 +00:00
|
|
|
|
2013-11-13 11:39:24 +00:00
|
|
|
void
|
|
|
|
weprintf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2015-12-21 08:28:44 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
xvprintf(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xvprintf(const char *fmt, va_list ap)
|
|
|
|
{
|
2015-12-21 12:57:10 +00:00
|
|
|
if (argv0 && strncmp(fmt, "usage", strlen("usage")))
|
2015-04-04 22:34:58 +00:00
|
|
|
fprintf(stderr, "%s: ", argv0);
|
2013-11-14 13:06:48 +00:00
|
|
|
|
2013-11-13 11:39:24 +00:00
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
|
|
|
|
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
|
|
|
|
fputc(' ', stderr);
|
|
|
|
perror(NULL);
|
|
|
|
}
|
2013-12-04 17:41:52 +00:00
|
|
|
}
|