07e541cc2e
Passing NULL for the format is just easier with a function.
80 lines
1.1 KiB
C
80 lines
1.1 KiB
C
/*
|
|
* Public domain
|
|
* err.h compatibility shim
|
|
*/
|
|
|
|
#ifdef HAVE_ERR_H
|
|
|
|
#include_next <err.h>
|
|
|
|
#else
|
|
|
|
#ifndef LIBCRYPTOCOMPAT_ERR_H
|
|
#define LIBCRYPTOCOMPAT_ERR_H
|
|
|
|
#include <errno.h>
|
|
#include <stdarg.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static inline void
|
|
err(int eval, const char *fmt, ...)
|
|
{
|
|
int sverrno = errno;
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
if (fmt != NULL) {
|
|
vfprintf(stderr, fmt, ap);
|
|
fprintf(stderr, ": ");
|
|
}
|
|
fprintf(stderr, "%s\n", strerror(sverrno));
|
|
exit(eval);
|
|
va_end(ap);
|
|
}
|
|
|
|
static inline void
|
|
errx(int eval, const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
if (fmt != NULL)
|
|
vfprintf(stderr, fmt, ap);
|
|
fprintf(stderr, "\n");
|
|
exit(eval);
|
|
va_end(ap);
|
|
}
|
|
|
|
static inline void
|
|
warn(const char *fmt, ...)
|
|
{
|
|
int sverrno = errno;
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
if (fmt != NULL) {
|
|
vfprintf(stderr, fmt, ap);
|
|
fprintf(stderr, ": ");
|
|
}
|
|
fprintf(stderr, "%s\n", strerror(sverrno));
|
|
va_end(ap);
|
|
}
|
|
|
|
static inline void
|
|
warnx(const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
if (fmt != NULL)
|
|
vfprintf(stderr, fmt, ap);
|
|
fprintf(stderr, "\n");
|
|
va_end(ap);
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|