summaryrefslogtreecommitdiff
path: root/lib/libc/err
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-14 18:10:13 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-14 19:28:34 +0100
commit872cf03f26c2801ae6c3008ce5fa0d7856f5f85d (patch)
tree94809812b71ee286eb5b74c70e4d08fc4c8dc057 /lib/libc/err
parentec769a83bde09c76bd6ad9ee7f391036dba5cd97 (diff)
libc: implement err/warn functions
Diffstat (limited to 'lib/libc/err')
-rw-r--r--lib/libc/err/Kbuild8
-rw-r--r--lib/libc/err/err.c10
-rw-r--r--lib/libc/err/errx.c10
-rw-r--r--lib/libc/err/verr.c9
-rw-r--r--lib/libc/err/verrx.c9
-rw-r--r--lib/libc/err/vwarn.c16
-rw-r--r--lib/libc/err/vwarnx.c16
-rw-r--r--lib/libc/err/warn.c10
-rw-r--r--lib/libc/err/warnx.c10
9 files changed, 98 insertions, 0 deletions
diff --git a/lib/libc/err/Kbuild b/lib/libc/err/Kbuild
new file mode 100644
index 00000000..e60623f5
--- /dev/null
+++ b/lib/libc/err/Kbuild
@@ -0,0 +1,8 @@
+obj-y += err.o
+obj-y += errx.o
+obj-y += verr.o
+obj-y += verrx.o
+obj-y += vwarn.o
+obj-y += vwarnx.o
+obj-y += warn.o
+obj-y += warnx.o
diff --git a/lib/libc/err/err.c b/lib/libc/err/err.c
new file mode 100644
index 00000000..5b1b2b02
--- /dev/null
+++ b/lib/libc/err/err.c
@@ -0,0 +1,10 @@
+#include <err.h>
+#include <stdarg.h>
+
+__dead void err(int eval, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ verr(eval, fmt, ap);
+ va_end(ap);
+}
diff --git a/lib/libc/err/errx.c b/lib/libc/err/errx.c
new file mode 100644
index 00000000..0afe999e
--- /dev/null
+++ b/lib/libc/err/errx.c
@@ -0,0 +1,10 @@
+#include <err.h>
+#include <stdarg.h>
+
+__dead void errx(int eval, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ verrx(eval, fmt, ap);
+ va_end(ap);
+}
diff --git a/lib/libc/err/verr.c b/lib/libc/err/verr.c
new file mode 100644
index 00000000..d769c15c
--- /dev/null
+++ b/lib/libc/err/verr.c
@@ -0,0 +1,9 @@
+#include <err.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+__dead void verr(int eval, const char *fmt, va_list args)
+{
+ vwarn(fmt, args);
+ exit(eval);
+}
diff --git a/lib/libc/err/verrx.c b/lib/libc/err/verrx.c
new file mode 100644
index 00000000..d769c15c
--- /dev/null
+++ b/lib/libc/err/verrx.c
@@ -0,0 +1,9 @@
+#include <err.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+__dead void verr(int eval, const char *fmt, va_list args)
+{
+ vwarn(fmt, args);
+ exit(eval);
+}
diff --git a/lib/libc/err/vwarn.c b/lib/libc/err/vwarn.c
new file mode 100644
index 00000000..2f485d93
--- /dev/null
+++ b/lib/libc/err/vwarn.c
@@ -0,0 +1,16 @@
+#include <stdarg.h>
+#include <stdio.h>
+
+extern char *__progname;
+
+void vwarn(const char *fmt, va_list args)
+{
+ fprintf(stderr, "%s: ", __progname);
+
+ if (fmt != NULL) {
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, ": ");
+ }
+
+ perror(NULL);
+}
diff --git a/lib/libc/err/vwarnx.c b/lib/libc/err/vwarnx.c
new file mode 100644
index 00000000..2f485d93
--- /dev/null
+++ b/lib/libc/err/vwarnx.c
@@ -0,0 +1,16 @@
+#include <stdarg.h>
+#include <stdio.h>
+
+extern char *__progname;
+
+void vwarn(const char *fmt, va_list args)
+{
+ fprintf(stderr, "%s: ", __progname);
+
+ if (fmt != NULL) {
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, ": ");
+ }
+
+ perror(NULL);
+}
diff --git a/lib/libc/err/warn.c b/lib/libc/err/warn.c
new file mode 100644
index 00000000..4f12995a
--- /dev/null
+++ b/lib/libc/err/warn.c
@@ -0,0 +1,10 @@
+#include <err.h>
+#include <stdarg.h>
+
+void warn(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vwarn(fmt, ap);
+ va_end(ap);
+}
diff --git a/lib/libc/err/warnx.c b/lib/libc/err/warnx.c
new file mode 100644
index 00000000..fa0e6fda
--- /dev/null
+++ b/lib/libc/err/warnx.c
@@ -0,0 +1,10 @@
+#include <err.h>
+#include <stdarg.h>
+
+void warnx(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vwarnx(fmt, ap);
+ va_end(ap);
+}