2020-12-28 19:15:37 +04:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
__declspec(noreturn)
|
|
|
|
#else
|
|
|
|
__attribute__((noreturn))
|
|
|
|
#endif
|
|
|
|
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, ": ");
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
fprintf(stderr, "%s\n", strerror(sverrno));
|
|
|
|
exit(eval);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
__declspec(noreturn)
|
|
|
|
#else
|
|
|
|
__attribute__((noreturn))
|
|
|
|
#endif
|
|
|
|
static inline void
|
|
|
|
errx(int eval, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
if (fmt != NULL)
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
exit(eval);
|
|
|
|
}
|
|
|
|
|
|
|
|
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, ": ");
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
fprintf(stderr, "%s\n", strerror(sverrno));
|
|
|
|
}
|
|
|
|
|
2022-04-25 00:29:35 +04:00
|
|
|
static inline void
|
|
|
|
vwarnx(const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
if (fmt != NULL)
|
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2020-12-28 19:15:37 +04:00
|
|
|
static inline void
|
|
|
|
warnx(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2022-04-25 00:29:35 +04:00
|
|
|
vwarnx(fmt, ap);
|
2020-12-28 19:15:37 +04:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|