]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
handle libc implementations which do not provide `error.h`
authorSaleem Abdulrasool <abdulras@google.com>
Fri, 20 Aug 2021 20:28:23 +0000 (20:28 +0000)
committerMark Wielaard <mark@klomp.org>
Fri, 27 Aug 2021 15:31:32 +0000 (17:31 +0200)
Introduce a configure time check for the presence of `error.h`.  In the
case that `error.h` is not available, we can fall back to `err.h`.
Although `err.h` is not a C standard header (it is a BSD extension),
many libc implementations provide.  If there are targets which do not
provide an implementation of `err.h`, it would be possible to further
extend the implementation to be more portable.

This resolves bug #21008.

Signed-off-by: Saleem Abdulrasool <abdulras@google.com>
ChangeLog
configure.ac
lib/ChangeLog
lib/system.h

index 12b8f403816bf7ec883b8a69a2d0827ad2e98905..6d920b9347992c37a7cbcf89b5b752206125d5a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2021-08-20  Saleem Abdulrasool  <abdulras@google.com>
+
+       * Add AC_CHECK_HEADERS for error.h and err.h.
+
 2021-07-28  Mark Wielaard  <mark@klomp.org>
 
        * configure.ac (AC_CHECK_DECLS): Add reallocarray check.
index 7caff2c581be6f8038e10b19b6f0b93624c9414e..177bb1a2d40dddaa7becad4dd45983ce6cf66bb2 100644 (file)
@@ -431,6 +431,9 @@ AC_CHECK_DECLS([reallocarray],[],[],
 
 AC_CHECK_FUNCS([process_vm_readv])
 
+AC_CHECK_HEADERS([error.h])
+AC_CHECK_HEADERS([err.h])
+
 old_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS -D_GNU_SOURCE"
 AC_FUNC_STRERROR_R()
index a95f80417bab5806fc7234c7300cf524ecee6636..589953cf36c1df50fcf3d2b001dc1b4fa4ec7c8f 100644 (file)
@@ -1,3 +1,8 @@
+2021-08-20  Saleem Abdulrasool  <abdulras@google.com>
+
+       * system.h: Check for HAVE_ERROR_H and HAVE_ERR_H and define
+       error_message_cont and error if necessary.
+
 2021-08-20  Saleem Abdulrasool  <abdulras@google.com>
 
        * fixedsizehash.h: Remove sys/cdefs.h include. Unconditionally
index 58d9deee638f615c3241f4be0e5620ec64d78056..b963fd156391f2c1232bffb0a2fe2bb379d31b49 100644 (file)
@@ -29,8 +29,9 @@
 #ifndef LIB_SYSTEM_H
 #define LIB_SYSTEM_H   1
 
+#include <config.h>
+
 #include <errno.h>
-#include <error.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <sys/param.h>
 #include <byteswap.h>
 #include <unistd.h>
 #include <string.h>
+#include <stdarg.h>
 #include <stdlib.h>
 
+#if defined(HAVE_ERROR_H)
+#include <error.h>
+#elif defined(HAVE_ERR_H)
+#include <err.h>
+
+static int error_message_count = 0;
+
+static inline void error(int status, int errnum, const char *format, ...) {
+  va_list argp;
+
+  va_start(argp, format);
+  verr(status, format, argp);
+  va_end(argp);
+
+  if (status)
+    exit(status);
+  ++error_message_count;
+}
+#else
+#error "err.h or error.h must be available"
+#endif
+
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 # define LE32(n)       (n)
 # define LE64(n)       (n)