patch-lib_error.c 1.18 KB
Newer Older
cem's avatar
cem committed
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
--- lib/error.c.orig	2016-07-13 06:58:54 UTC
+++ lib/error.c
@@ -0,0 +1,64 @@
+#include <err.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "error.h"
+
+unsigned int error_message_count;
+int error_one_per_line;
+void (*error_print_progname)(void) = NULL;
+
+static const char *lastfile;
+static unsigned lastline;
+
+/* Good enough. */
+
+void
+error_at_line(int status, int errnum, const char *fn, unsigned line,
+    const char *format, ...)
+{
+	va_list ap;
+	int serrno;
+
+	if (error_one_per_line != 0 && fn != NULL && fn == lastfile && line ==
+	    lastline)
+		return;
+
+	serrno = errno;
+	errno = errnum;
+
+	fflush(stdout);
+
+	if (error_print_progname != NULL) {
+		error_print_progname();
+		fprintf(stderr, ":");
+	}
+
+	if (fn != NULL) {
+		lastfile = fn;
+		lastline = line;
+
+		fprintf(stderr, "%s:%u: ", fn, line);
+	} else if (error_print_progname != NULL) {
+		fprintf(stderr, " ");
+	}
+
+	va_start(ap, format);
+	if (status) {
+		if (errnum)
+			verr(status, format, ap);
+		else
+			verrx(status, format, ap);
+	} else {
+		if (errnum)
+			vwarn(format, ap);
+		else
+			vwarnx(format, ap);
+	}
+	va_end(ap);
+
+	errno = serrno;
+	error_message_count++;
+}
+