mirror of
https://github.com/samba-team/samba.git
synced 2025-01-14 19:24:43 +03:00
d9ce876ea9
This allows us to avoid err.h in failtest. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
65 lines
1.1 KiB
C
65 lines
1.1 KiB
C
#include "err.h"
|
|
|
|
#if !HAVE_ERR_H
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
static const char *progname = "unknown program";
|
|
|
|
void err_set_progname(const char *name)
|
|
{
|
|
progname = name;
|
|
}
|
|
|
|
void NORETURN err(int eval, const char *fmt, ...)
|
|
{
|
|
int err_errno = errno;
|
|
va_list ap;
|
|
|
|
fprintf(stderr, "%s: ", progname);
|
|
va_start(ap, fmt);
|
|
vfprintf(stderr, fmt, ap);
|
|
va_end(ap);
|
|
fprintf(stderr, ": %s\n", strerror(err_errno));
|
|
exit(eval);
|
|
}
|
|
|
|
void NORETURN errx(int eval, const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
fprintf(stderr, "%s: ", progname);
|
|
va_start(ap, fmt);
|
|
vfprintf(stderr, fmt, ap);
|
|
va_end(ap);
|
|
fprintf(stderr, "\n");
|
|
exit(eval);
|
|
}
|
|
|
|
void warn(const char *fmt, ...)
|
|
{
|
|
int err_errno = errno;
|
|
va_list ap;
|
|
|
|
fprintf(stderr, "%s: ", progname);
|
|
va_start(ap, fmt);
|
|
vfprintf(stderr, fmt, ap);
|
|
va_end(ap);
|
|
fprintf(stderr, ": %s\n", strerror(err_errno));
|
|
}
|
|
|
|
void warnx(const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
fprintf(stderr, "%s: ", progname);
|
|
va_start(ap, fmt);
|
|
vfprintf(stderr, fmt, ap);
|
|
va_end(ap);
|
|
fprintf(stderr, "\n");
|
|
}
|
|
#endif
|