ports/devel/elfutils/files/patch-lib_error.c
Conrad Meyer 552479055e Add elfutils 0.163
Elfutils is a collection of utilities, including: stack (to show
backtraces); nm (for listing symbols from object files); size (for
listing the section sizes of an object or archive file); strip (for
discarding symbols); readelf (to see the raw ELF file structures);
elflint (to check for well-formed ELF files); and elfcompress (to
compress or decompress ELF sections).

It also provides libraries to allow other programs to manipulate ELF and
DWARF data.

WWW:	https://fedorahosted.org/elfutils/

Reviewed by:	bdrewery
Sponsored by:	EMC / Isilon Storage Division
Differential Revision:	https://reviews.freebsd.org/D7206
2016-07-13 17:48:54 +00:00

67 lines
1.2 KiB
C

--- 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++;
+}
+