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
|
This patch adds error() API implementation for non-glibc system C libs
Upstream-Status: Pending
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
misc-utils/test_uuidd.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 61 insertions(+), 1 deletion(-)
diff --git a/misc-utils/test_uuidd.c b/misc-utils/test_uuidd.c
index 36f3b3d..7d579ce 100644
--- a/misc-utils/test_uuidd.c
+++ b/misc-utils/test_uuidd.c
@@ -23,7 +23,6 @@
*
* make uuidd uuidgen localstatedir=/var
*/
-#include <error.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
@@ -38,6 +37,17 @@
#include "xalloc.h"
#include "strutils.h"
+#ifdef __GLIBC__
+#include <error.h>
+#else
+extern void (*error_print_progname)(void);
+extern unsigned int error_message_count;
+extern int error_one_per_line;
+
+void error(int, int, const char *, ...);
+void error_at_line(int, int, const char *, unsigned int, const char *, ...);
+#endif
+
#define LOG(level,args) if (loglev >= level) { fprintf args; }
size_t nprocesses = 4;
@@ -256,6 +266,56 @@ static void object_dump(size_t idx, object_t *obj)
fprintf(stderr, "}\n");
}
+#ifndef __GLIBC__
+extern char *__progname;
+
+void (*error_print_progname)(void) = 0;
+unsigned int error_message_count = 0;
+int error_one_per_line = 0;
+
+static void eprint(int status, int e, const char *file, unsigned int line, const char *fmt, va_list ap)
+{
+ if (file && error_one_per_line) {
+ static const char *oldfile;
+ static unsigned int oldline;
+ if (line == oldline && strcmp(file, oldfile) == 0)
+ return;
+ oldfile = file;
+ oldline = line;
+ }
+ if (error_print_progname)
+ error_print_progname();
+ else
+ fprintf(stderr, "%s: ", __progname);
+ if (file)
+ fprintf(stderr, "%s:%u: ", file, line);
+ vfprintf(stderr, fmt, ap);
+ if (e)
+ fprintf(stderr, ": %s", strerror(e));
+ putc('\n', stderr);
+ fflush(stderr);
+ error_message_count++;
+ if (status)
+ exit(status);
+}
+
+void error(int status, int e, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap,fmt);
+ eprint(status, e, 0, 0, fmt, ap);
+ va_end(ap);
+}
+
+void error_at_line(int status, int e, const char *file, unsigned int line, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap,fmt);
+ eprint(status, e, file, line, fmt, ap);
+ va_end(ap);
+}
+#endif /* __GLIBC__ */
+
int main(int argc, char *argv[])
{
size_t i, nfailed = 0, nignored = 0;
--
2.8.3
|