aboutsummaryrefslogtreecommitdiff
path: root/sys/base/error
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-11-11 16:31:58 -0800
committerNicholas Noll <nbnoll@eml.cc>2021-11-11 16:31:58 -0800
commit9695ea005d4af93dcd60f74f10fd3c54499a182f (patch)
tree3e1a9abb9456ba07c0c97cd3d691f6a2df115791 /sys/base/error
parentc65794b50b1bc729e7a4e940b76a973afa3030b9 (diff)
chore: split up base library into individual files for smaller binaries
Diffstat (limited to 'sys/base/error')
-rw-r--r--sys/base/error/errorf.c13
-rw-r--r--sys/base/error/exits.c11
-rw-r--r--sys/base/error/internal.h3
-rw-r--r--sys/base/error/panicf.c16
-rw-r--r--sys/base/error/rules.mk6
-rw-r--r--sys/base/error/verrorf.c9
-rw-r--r--sys/base/error/vpanicf.c11
7 files changed, 69 insertions, 0 deletions
diff --git a/sys/base/error/errorf.c b/sys/base/error/errorf.c
new file mode 100644
index 0000000..193dd9d
--- /dev/null
+++ b/sys/base/error/errorf.c
@@ -0,0 +1,13 @@
+#include "internal.h"
+
+void
+errorf(byte* fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+
+ fprintf(stderr, "error: ");
+ vfprintf(stderr, fmt, args);
+
+ va_end(args);
+}
diff --git a/sys/base/error/exits.c b/sys/base/error/exits.c
new file mode 100644
index 0000000..6be7d3b
--- /dev/null
+++ b/sys/base/error/exits.c
@@ -0,0 +1,11 @@
+#include "internal.h"
+
+void
+exits(char *s)
+{
+ if(s == nil || *s == 0)
+ exit(0);
+
+ fputs(s, stderr);
+ exit(1);
+}
diff --git a/sys/base/error/internal.h b/sys/base/error/internal.h
new file mode 100644
index 0000000..88a8895
--- /dev/null
+++ b/sys/base/error/internal.h
@@ -0,0 +1,3 @@
+#include <u.h>
+#include <base.h>
+
diff --git a/sys/base/error/panicf.c b/sys/base/error/panicf.c
new file mode 100644
index 0000000..d698576
--- /dev/null
+++ b/sys/base/error/panicf.c
@@ -0,0 +1,16 @@
+#include "internal.h"
+
+void
+panicf(byte* fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+
+ printf("panic: ");
+ vprintf(fmt, args);
+ printf("\n");
+
+ va_end(args);
+
+ exit(1);
+}
diff --git a/sys/base/error/rules.mk b/sys/base/error/rules.mk
new file mode 100644
index 0000000..e3a9ce0
--- /dev/null
+++ b/sys/base/error/rules.mk
@@ -0,0 +1,6 @@
+SRCS_$(d)+=\
+ $(d)/error/exits.c \
+ $(d)/error/errorf.c \
+ $(d)/error/panicf.c \
+ $(d)/error/verrorf.c \
+ $(d)/error/vpanicf.c \
diff --git a/sys/base/error/verrorf.c b/sys/base/error/verrorf.c
new file mode 100644
index 0000000..15af064
--- /dev/null
+++ b/sys/base/error/verrorf.c
@@ -0,0 +1,9 @@
+#include "internal.h"
+
+void
+verrorf(byte* fmt, va_list args)
+{
+ printf("error: ");
+ vprintf(fmt, args);
+ printf("\n");
+}
diff --git a/sys/base/error/vpanicf.c b/sys/base/error/vpanicf.c
new file mode 100644
index 0000000..bea97ac
--- /dev/null
+++ b/sys/base/error/vpanicf.c
@@ -0,0 +1,11 @@
+#include "internal.h"
+
+void
+vpanicf(byte* fmt, va_list args)
+{
+ printf("panic: ");
+ vprintf(fmt, args);
+ printf("\n");
+
+ exit(1);
+}