aboutsummaryrefslogtreecommitdiffstats
path: root/testing/ympd/musl-missing-errorh.patch
blob: 960ca3fc112bde471c9aa11a369c547f0068dfa4 (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
--- ympd-1.2.2/htdocs/mkdata.c
+++ ympd-1.2.2/htdocs/mkdata.c
@@ -7,7 +7,11 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#if HAVE_ERROR_H
 #include <error.h>
+#else
+#include <stdarg.h>
+#endif
 #include <errno.h>
 #include <string.h>
 
@@ -53,6 +57,60 @@
     return "text/plain";
 }
 
+/*
+ * Program name.
+ */
+#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
+# ifdef HAVE___PROGNAME
+extern char *__progname;
+#  define program_invocation_short_name __progname
+# else
+#  ifdef HAVE_GETEXECNAME
+#   define program_invocation_short_name \
+		prog_inv_sh_nm_from_file(getexecname(), 0)
+#  else
+#   define program_invocation_short_name \
+		prog_inv_sh_nm_from_file(__FILE__, 1)
+#  endif
+static char prog_inv_sh_nm_buf[256];
+static inline char *prog_inv_sh_nm_from_file(char *f, char stripext)
+{
+	char *t;
+
+	if ((t = strrchr(f, '/')) != NULL)
+		t++;
+	else
+		t = f;
+
+	strncpy(prog_inv_sh_nm_buf, t, sizeof(prog_inv_sh_nm_buf) - 1);
+	prog_inv_sh_nm_buf[sizeof(prog_inv_sh_nm_buf) - 1] = '\0';
+
+	if (stripext && (t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL)
+		*t = '\0';
+
+	return prog_inv_sh_nm_buf;
+}
+# endif
+#endif
+
+#ifndef HAVE_ERROR_H
+/* Emulate the error() function from glibc */
+__attribute__((__format__(__printf__, 3, 4)))
+static void error(int status, int errnum, const char *format, ...)
+{
+        va_list argp;
+        fprintf(stderr, "%s: ", program_invocation_short_name);
+        va_start(argp, format);
+        vfprintf(stderr, format, argp);
+        va_end(argp);
+        if (errnum != 0)
+                fprintf(stderr, ": error code %d", errnum);
+        fprintf(stderr, "\n");
+        if (status != 0)
+                exit(status);
+}
+#endif
+
 int main(int argc, char *argv[])
 {
     int i, j, buf;
@@ -92,3 +150,4 @@
     fputs(footer, stdout);
     return EXIT_SUCCESS;
 }
+