diff --git a/configure.ac.tpl b/configure.ac.tpl index 99c2f6f..84d2f69 100644 --- a/configure.ac.tpl +++ b/configure.ac.tpl @@ -111,6 +111,8 @@ AC_CHECK_FUNC(funopen, AC_DEFINE(HAVE_FUNOPEN)) AC_CHECK_HEADER(sys/sysctl.h, AC_DEFINE(HAVE_SYS_SYSCTL_H)) +AC_CHECK_HEADER(err.h, AC_DEFINE(HAVE_ERR_H)) + AC_ARG_WITH([openssldir], AS_HELP_STRING([--with-openssldir], [Set the default openssl directory]), AC_DEFINE_UNQUOTED(OPENSSLDIR, "$withval") diff --git a/include/Makefile.am b/include/Makefile.am index 7f8cfbd..889f775 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,6 +1,7 @@ SUBDIRS = openssl -noinst_HEADERS = pqueue.h +noinst_HEADERS = err.h +noinst_HEADERS += pqueue.h noinst_HEADERS += stdlib.h noinst_HEADERS += string.h noinst_HEADERS += unistd.h diff --git a/include/err.h b/include/err.h new file mode 100644 index 0000000..0aba1db --- /dev/null +++ b/include/err.h @@ -0,0 +1,24 @@ +#ifdef HAVE_ERR_H + +#include_next + +#else + +#ifndef LIBCRYPTOCOMPAT_ERR_H +#define LIBCRYPTOCOMPAT_ERR_H + +#define err(exitcode, format, args...) \ + errx(exitcode, format ": %s", ## args, strerror(errno)) + +#define errx(exitcode, format, args...) \ + do { warnx(format, ## args); exit(exitcode); } while (0) + +#define warn(format, args...) \ + warnx(format ": %s", ## args, strerror(errno)) + +#define warnx(format, args...) \ + fprintf(stderr, format "\n", ## args) + +#endif + +#endif