blob: e78514b814757c2ed1dd3a73e6436d1182d7f9fc [file] [log] [blame]
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001From b3952bd5e28f2a4d86c7377de239db8fa7237e14 Mon Sep 17 00:00:00 2001
2From: 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>
12---
13 tools/debugedit.c | 6 +++++-
14 tools/elfdeps.c | 6 +++++-
15 tools/error.h | 27 +++++++++++++++++++++++++++
16 tools/sepdebugcrcfix.c | 6 +++++-
17 4 files changed, 42 insertions(+), 3 deletions(-)
18 create mode 100644 tools/error.h
19
20diff --git a/tools/debugedit.c b/tools/debugedit.c
21index 9f8dcd0fb..852f46073 100644
22--- a/tools/debugedit.c
23+++ b/tools/debugedit.c
24@@ -26,7 +26,6 @@
25 #include <byteswap.h>
26 #include <endian.h>
27 #include <errno.h>
28-#include <error.h>
29 #include <limits.h>
30 #include <string.h>
31 #include <stdlib.h>
32@@ -40,6 +39,11 @@
33
34 #include <gelf.h>
35 #include <dwarf.h>
36+#ifdef __GLIBC__
37+#include <error.h>
38+#else
39+#include "error.h"
40+#endif
41
42
43 /* Unfortunately strtab manipulation functions were only officially added
44diff --git a/tools/elfdeps.c b/tools/elfdeps.c
45index 6d9094874..f69e60997 100644
46--- a/tools/elfdeps.c
47+++ b/tools/elfdeps.c
48@@ -5,10 +5,14 @@
49 #include <unistd.h>
50 #include <stdlib.h>
51 #include <fcntl.h>
52-#include <error.h>
53 #include <errno.h>
54 #include <popt.h>
55 #include <gelf.h>
56+#ifdef __GLIBC__
57+#include <error.h>
58+#else
59+#include "error.h"
60+#endif
61
62 #include <rpm/rpmstring.h>
63 #include <rpm/argv.h>
64diff --git a/tools/error.h b/tools/error.h
65new file mode 100644
66index 000000000..ef06827a0
67--- /dev/null
68+++ b/tools/error.h
69@@ -0,0 +1,27 @@
70+#ifndef _ERROR_H_
71+#define _ERROR_H_
72+
73+#include <stdarg.h>
74+#include <stdio.h>
75+#include <stdlib.h>
76+#include <string.h>
77+#include <errno.h>
78+
79+static unsigned int error_message_count = 0;
80+
81+static inline void error(int status, int errnum, const char* format, ...)
82+{
83+ va_list ap;
84+ fprintf(stderr, "%s: ", program_invocation_name);
85+ va_start(ap, format);
86+ vfprintf(stderr, format, ap);
87+ va_end(ap);
88+ if (errnum)
89+ fprintf(stderr, ": %s", strerror(errnum));
90+ fprintf(stderr, "\n");
91+ error_message_count++;
92+ if (status)
93+ exit(status);
94+}
95+
96+#endif /* _ERROR_H_ */
97diff --git a/tools/sepdebugcrcfix.c b/tools/sepdebugcrcfix.c
98index fba460014..2be9c1fd8 100644
99--- a/tools/sepdebugcrcfix.c
100+++ b/tools/sepdebugcrcfix.c
101@@ -29,9 +29,13 @@
102 #include <endian.h>
103 #include <stdio.h>
104 #include <stdlib.h>
105-#include <error.h>
106 #include <libelf.h>
107 #include <gelf.h>
108+#ifdef __GLIBC__
109+#include <error.h>
110+#else
111+#include "error.h"
112+#endif
113
114 #ifndef _
115 #define _(x) x
116--
1172.29.2
118