summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaleem Abdulrasool <abdulras@google.com>2021-08-20 20:28:23 +0000
committerMark Wielaard <mark@klomp.org>2021-08-27 17:31:32 +0200
commit76c84c137a82a7cacbc69b1696052491b3bb81cb (patch)
treecfcf4668bc54d3d75e12397b7c3aa1b40864cbf0
parentd0c72317dcde4c21e88e37dfd865335fc7f0c079 (diff)
downloadelfutils-76c84c137a82a7cacbc69b1696052491b3bb81cb.tar.gz
handle libc implementations which do not provide `error.h`
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>
-rw-r--r--ChangeLog4
-rw-r--r--configure.ac3
-rw-r--r--lib/ChangeLog5
-rw-r--r--lib/system.h26
4 files changed, 37 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 12b8f403..6d920b93 100644
--- 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.
diff --git a/configure.ac b/configure.ac
index 7caff2c5..177bb1a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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()
diff --git a/lib/ChangeLog b/lib/ChangeLog
index a95f8041..589953cf 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,5 +1,10 @@
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
define STROF and CONCAT macros.
diff --git a/lib/system.h b/lib/system.h
index 58d9deee..b963fd15 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -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>
@@ -38,8 +39,31 @@
#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)