From 9b9d717f484ec913cdd3804e43489b3dc18bd77c Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Sat, 31 Oct 2020 22:14:05 -0700 Subject: [PATCH] tools: Add error.h for non-glibc case error is glibc specific API, so this patch will mostly not accepted upstream given that elfutils has been closely tied to glibc Upstream-Status: Inappropriate [workaround for musl] Signed-off-by: Khem Raj --- tools/elfdeps.c | 6 +++++- tools/error.h | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tools/error.h diff --git a/tools/elfdeps.c b/tools/elfdeps.c index d205935bb..3a8945b33 100644 --- a/tools/elfdeps.c +++ b/tools/elfdeps.c @@ -5,10 +5,14 @@ #include #include #include -#include #include #include #include +#ifdef __GLIBC__ +#include +#else +#include "error.h" +#endif #include #include diff --git a/tools/error.h b/tools/error.h new file mode 100644 index 000000000..ef06827a0 --- /dev/null +++ b/tools/error.h @@ -0,0 +1,27 @@ +#ifndef _ERROR_H_ +#define _ERROR_H_ + +#include +#include +#include +#include +#include + +static unsigned int error_message_count = 0; + +static inline void error(int status, int errnum, const char* format, ...) +{ + va_list ap; + fprintf(stderr, "%s: ", program_invocation_name); + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); + if (errnum) + fprintf(stderr, ": %s", strerror(errnum)); + fprintf(stderr, "\n"); + error_message_count++; + if (status) + exit(status); +} + +#endif /* _ERROR_H_ */