This patch adds GNU libc extension function error()
as specified at https://linux.die.net/man/3/error.
This function is used by core utils programs on Linux.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
---
 Makefile          |  1 +
 libc/misc/error.c | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
 create mode 100644 libc/misc/error.c

diff --git a/Makefile b/Makefile
index a433074d..2f68d964 100644
--- a/Makefile
+++ b/Makefile
@@ -1325,6 +1325,7 @@ $(out)/musl/src/math/llroundl.o: conf-opt := $(conf-opt) 
-O0
 musl += misc/a64l.o
 libc += misc/basename.o
 musl += misc/dirname.o
+libc += misc/error.o
 libc += misc/ffs.o
 musl += misc/get_current_dir_name.o
 libc += misc/gethostid.o
diff --git a/libc/misc/error.c b/libc/misc/error.c
new file mode 100644
index 00000000..9995b678
--- /dev/null
+++ b/libc/misc/error.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2019 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+extern char *program_invocation_name;
+
+void
+error (int status, int errnum, const char *message, ...)
+{
+    fflush(stdout);
+
+    fprintf(stderr, "%s: ", program_invocation_name);
+
+    va_list args;
+    int ret;
+    va_start(args, message);
+    ret = vfprintf(stderr, message, args);
+    va_end(args);
+
+    if (errnum) {
+        fprintf(stderr, ": %s", strerror(errnum));
+    }
+
+    fprintf(stderr, "\n" );
+
+    if (status) {
+        exit(status);
+    }
+}
-- 
2.20.1

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to