2011-05-22 21:36:34 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <stdarg.h>
|
2012-05-14 16:28:41 -04:00
|
|
|
#include <stdio.h>
|
2011-05-22 21:36:34 -04:00
|
|
|
#include <stdlib.h>
|
2012-05-14 16:28:41 -04:00
|
|
|
#include <string.h>
|
2013-03-05 15:46:48 -05:00
|
|
|
|
2011-05-24 08:00:30 -04:00
|
|
|
#include "../util.h"
|
2011-05-22 21:36:34 -04:00
|
|
|
|
2012-05-14 16:28:41 -04:00
|
|
|
char *argv0;
|
|
|
|
|
|
|
|
static void venprintf(int, const char *, va_list);
|
2011-06-18 01:41:28 -04:00
|
|
|
|
2011-05-22 21:36:34 -04:00
|
|
|
void
|
|
|
|
eprintf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2014-10-02 18:46:04 -04:00
|
|
|
venprintf(1, fmt, ap);
|
2011-05-22 21:36:34 -04:00
|
|
|
va_end(ap);
|
|
|
|
}
|
2012-05-14 16:28:41 -04:00
|
|
|
|
|
|
|
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:55:08 -04:00
|
|
|
#ifdef DEBUG
|
2013-11-14 08:06:48 -05:00
|
|
|
fprintf(stderr, "%s: ", argv0);
|
2014-03-28 11:55:08 -04:00
|
|
|
#endif
|
2012-05-14 16:28:41 -04:00
|
|
|
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
|
|
|
|
if(fmt[0] && fmt[strlen(fmt)-1] == ':') {
|
|
|
|
fputc(' ', stderr);
|
|
|
|
perror(NULL);
|
|
|
|
}
|
2013-03-05 15:46:48 -05:00
|
|
|
|
2012-05-14 16:28:41 -04:00
|
|
|
exit(status);
|
|
|
|
}
|
2013-03-05 15:46:48 -05:00
|
|
|
|
2013-11-13 06:39:24 -05:00
|
|
|
void
|
|
|
|
weprintf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2014-03-28 11:55:08 -04:00
|
|
|
#ifdef DEBUG
|
2013-11-14 08:06:48 -05:00
|
|
|
fprintf(stderr, "%s: ", argv0);
|
2014-03-28 11:55:08 -04:00
|
|
|
#endif
|
2013-11-14 08:06:48 -05:00
|
|
|
|
2013-11-13 06:39:24 -05:00
|
|
|
va_start(ap, fmt);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
|
|
|
|
fputc(' ', stderr);
|
|
|
|
perror(NULL);
|
|
|
|
}
|
2013-12-04 12:41:52 -05:00
|
|
|
}
|