summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--libgcompat/error.c27
2 files changed, 28 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index b5fda64..2ff1495 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,7 @@ LIBGCOMPAT_INCLUDE = \
libgcompat/alias.h
LIBGCOMPAT_SRC = \
libgcompat/dlfcn.c \
+ libgcompat/error.c \
libgcompat/execinfo.c \
libgcompat/gnulib.c \
libgcompat/grp.c \
diff --git a/libgcompat/error.c b/libgcompat/error.c
new file mode 100644
index 0000000..c759b19
--- /dev/null
+++ b/libgcompat/error.c
@@ -0,0 +1,27 @@
+#define _GNU_SOURCE /* program_invocation_name */
+#include <errno.h> /* program_invocation_name */
+#include <stdarg.h> /* va_list, va_start, va_end */
+#include <stdio.h> /* fflush, fputc, fputs, stderr, stdout, vfprintf */
+#include <string.h> /* strerror */
+
+/**
+ * Print an error message.
+ *
+ * LSB 5.0: LSB-Core-generic/baselib-error-n.html
+ */
+void error(int status, int errnum, const char *format, ...)
+{
+ va_list ap;
+
+ fflush(stdout);
+ fputs(program_invocation_name, stderr);
+ fputs(": ", stderr);
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+ if (errnum != 0) {
+ fputs(": ", stderr);
+ fputs(strerror(errnum), stderr);
+ fputc('\n', stderr);
+ }
+}