summaryrefslogtreecommitdiff
path: root/src/libc/err.c
diff options
context:
space:
mode:
authordzwdz2023-08-14 18:51:07 +0200
committerdzwdz2023-08-14 18:51:07 +0200
commit642b5fb0007b64c77d186fcb018d571152ee1d47 (patch)
tree1c466461f3602d306be309a053edae558ef2568e /src/libc/err.c
parent8050069c57b729c18c19b1a03ab6e4bf63b4735e (diff)
reorganization: first steps
Diffstat (limited to 'src/libc/err.c')
-rw-r--r--src/libc/err.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/libc/err.c b/src/libc/err.c
new file mode 100644
index 0000000..7a220fe
--- /dev/null
+++ b/src/libc/err.c
@@ -0,0 +1,50 @@
+#include <err.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+_Noreturn void err(int ret, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ vwarn(fmt, args);
+ va_end(args);
+ exit(ret);
+}
+
+_Noreturn void errx(int ret, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ vwarnx(fmt, args);
+ va_end(args);
+ exit(ret);
+}
+
+void warn(const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ vwarn(fmt, args);
+ va_end(args);
+}
+
+void warnx(const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ vwarnx(fmt, args);
+ va_end(args);
+}
+
+void vwarn(const char *fmt, va_list args) {
+ fprintf(stderr, "%s: ", getprogname());
+ if (fmt) {
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, ": ");
+ }
+ fprintf(stderr, "%s\n", strerror(errno));
+}
+
+void vwarnx(const char *fmt, va_list args) {
+ fprintf(stderr, "%s: ", getprogname());
+ if (fmt) vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+}