#include <config.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "missing.h"
#include "error.h"
static void _warning __P((int, const char *, va_list));
void cleanup __P((int));
void
#ifdef __STDC__
error(int eval, const char *fmt, ...)
#else
error(eval, fmt, va_alist)
int eval;
const char *fmt;
va_dcl
#endif
{
va_list ap;
#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
_warning(1, fmt, ap);
va_end(ap);
cleanup(0);
exit(eval);
}
void
#ifdef __STDC__
errorx(int eval, const char *fmt, ...)
#else
errorx(eval, fmt, va_alist)
int eval;
const char *fmt;
va_dcl
#endif
{
va_list ap;
#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
_warning(0, fmt, ap);
va_end(ap);
cleanup(0);
exit(eval);
}
void
#ifdef __STDC__
warning(const char *fmt, ...)
#else
warning(fmt, va_alist)
const char *fmt;
va_dcl
#endif
{
va_list ap;
#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
_warning(1, fmt, ap);
va_end(ap);
}
void
#ifdef __STDC__
warningx(const char *fmt, ...)
#else
warningx(fmt, va_alist)
const char *fmt;
va_dcl
#endif
{
va_list ap;
#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
_warning(0, fmt, ap);
va_end(ap);
}
static void
_warning(use_errno, fmt, ap)
int use_errno;
const char *fmt;
va_list ap;
{
int serrno = errno;
fputs(getprogname(), stderr);
if (fmt != NULL) {
fputs(": ", stderr);
vfprintf(stderr, fmt, ap);
}
if (use_errno) {
fputs(": ", stderr);
fputs(strerror(serrno), stderr);
}
putc('\n', stderr);
}