blob: 9783396639ff80beea817d4be1a226a8fba8ea94 [file] [log] [blame]
Andrew Geisslereff27472021-10-29 15:35:00 -05001From 9b9d717f484ec913cdd3804e43489b3dc18bd77c Mon Sep 17 00:00:00 2001
Andrew Geissler6ce62a22020-11-30 19:58:47 -06002From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 31 Oct 2020 22:14:05 -0700
4Subject: [PATCH] tools: Add error.h for non-glibc case
5
6error is glibc specific API, so this patch will mostly not accepted
7upstream given that elfutils has been closely tied to glibc
8
9Upstream-Status: Inappropriate [workaround for musl]
10
11Signed-off-by: Khem Raj <raj.khem@gmail.com>
Andrew Geisslereff27472021-10-29 15:35:00 -050012
Andrew Geissler6ce62a22020-11-30 19:58:47 -060013---
Andrew Geisslereff27472021-10-29 15:35:00 -050014 tools/elfdeps.c | 6 +++++-
15 tools/error.h | 27 +++++++++++++++++++++++++++
16 2 files changed, 32 insertions(+), 1 deletion(-)
Andrew Geissler6ce62a22020-11-30 19:58:47 -060017 create mode 100644 tools/error.h
18
Andrew Geissler6ce62a22020-11-30 19:58:47 -060019diff --git a/tools/elfdeps.c b/tools/elfdeps.c
Andrew Geisslereff27472021-10-29 15:35:00 -050020index d205935bb..3a8945b33 100644
Andrew Geissler6ce62a22020-11-30 19:58:47 -060021--- a/tools/elfdeps.c
22+++ b/tools/elfdeps.c
23@@ -5,10 +5,14 @@
24 #include <unistd.h>
25 #include <stdlib.h>
26 #include <fcntl.h>
27-#include <error.h>
28 #include <errno.h>
29 #include <popt.h>
30 #include <gelf.h>
31+#ifdef __GLIBC__
32+#include <error.h>
33+#else
34+#include "error.h"
35+#endif
36
37 #include <rpm/rpmstring.h>
38 #include <rpm/argv.h>
39diff --git a/tools/error.h b/tools/error.h
40new file mode 100644
41index 000000000..ef06827a0
42--- /dev/null
43+++ b/tools/error.h
44@@ -0,0 +1,27 @@
45+#ifndef _ERROR_H_
46+#define _ERROR_H_
47+
48+#include <stdarg.h>
49+#include <stdio.h>
50+#include <stdlib.h>
51+#include <string.h>
52+#include <errno.h>
53+
54+static unsigned int error_message_count = 0;
55+
56+static inline void error(int status, int errnum, const char* format, ...)
57+{
58+ va_list ap;
59+ fprintf(stderr, "%s: ", program_invocation_name);
60+ va_start(ap, format);
61+ vfprintf(stderr, format, ap);
62+ va_end(ap);
63+ if (errnum)
64+ fprintf(stderr, ": %s", strerror(errnum));
65+ fprintf(stderr, "\n");
66+ error_message_count++;
67+ if (status)
68+ exit(status);
69+}
70+
71+#endif /* _ERROR_H_ */