summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/debugedit/files/0001-tools-Add-error.h-for-non-glibc-case.patch
blob: f6d64cb4e7d54cb5cb5fca35b31a57621a7bc277 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
From 4c797d3b559ba51bd9ccd9a2036245819acce843 Mon Sep 17 00:00:00 2001
From: Chen Qi <Qi.Chen@windriver.com>
Date: Thu, 23 Mar 2023 10:54:21 +0800
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

This is a OE specific workaround for musl.

Upstream-Status: Inappropriate [OE Specific]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 tools/debugedit.c      |  7 ++++++-
 tools/error.h          | 27 +++++++++++++++++++++++++++
 tools/sepdebugcrcfix.c |  7 ++++++-
 3 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 tools/error.h

diff --git a/tools/debugedit.c b/tools/debugedit.c
index 668777a..a72c3c0 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -25,7 +25,6 @@
 #include <byteswap.h>
 #include <endian.h>
 #include <errno.h>
-#include <error.h>
 #include <limits.h>
 #include <string.h>
 #include <stdlib.h>
@@ -40,6 +39,12 @@
 #include <gelf.h>
 #include <dwarf.h>
 
+#ifdef __GLIBC__
+#include <error.h>
+#else
+#include "error.h"
+#endif
+
 #ifndef MAX
 #define MAX(m, n) ((m) < (n) ? (n) : (m))
 #endif
diff --git a/tools/error.h b/tools/error.h
new file mode 100644
index 0000000..9b24418
--- /dev/null
+++ b/tools/error.h
@@ -0,0 +1,27 @@
+#ifndef _ERROR_H_
+#define _ERROR_H_
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+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_ */
diff --git a/tools/sepdebugcrcfix.c b/tools/sepdebugcrcfix.c
index da50e6c..c4a9d56 100644
--- a/tools/sepdebugcrcfix.c
+++ b/tools/sepdebugcrcfix.c
@@ -29,10 +29,15 @@
 #include <endian.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <error.h>
 #include <libelf.h>
 #include <gelf.h>
 
+#ifdef __GLIBC__
+#include <error.h>
+#else
+#include "error.h"
+#endif
+
 #ifndef _
 #define _(x) x
 #endif
-- 
2.17.1