aboutsummaryrefslogtreecommitdiff
path: root/src/libc
diff options
context:
space:
mode:
authorNicholas <nbnoll@eml.cc>2021-11-20 10:53:19 -0800
committerNicholas <nbnoll@eml.cc>2021-11-20 10:53:19 -0800
commita9bfe650038afea8b751175cac16f6027345e45f (patch)
tree9a7f9feb76a64bb3efe573036d80b7bdbf8a59a5 /src/libc
parent1c8d4e69205fd875f6bec3fa3bd929c2e7f52f62 (diff)
Chore: reorganize libutf and libfmt into base
I found the split to be arbitrary. Better to include the functionality in the standard library. I also split the headers to allow for more granular inclusion (but the library is still monolithic). The only ugliness is the circular dependency introduced with libutf's generated functions. We put explicit prereqs with the necessary object files instead.
Diffstat (limited to 'src/libc')
-rw-r--r--src/libc/rules.mk20
-rw-r--r--src/libc/stdio.c59
-rw-r--r--src/libc/string.c80
3 files changed, 0 insertions, 159 deletions
diff --git a/src/libc/rules.mk b/src/libc/rules.mk
deleted file mode 100644
index 34e0912..0000000
--- a/src/libc/rules.mk
+++ /dev/null
@@ -1,20 +0,0 @@
-include share/push.mk
-
-# Iterate through subdirectory tree
-
-# Local sources
-SRCS_$(d) := $(wildcard $(d)/*.c)
-LIBS_$(d) := $(d)/libc_n.a
-BINS_$(d) :=
-
-include share/paths.mk
-
-# Local rules
-$(LIBS_$(d)): TCFLAGS = -ffreestanding -fno-builtin -nostdlib
-$(LIBS_$(d)): $(OBJS_$(d))
- $(ARCHIVE)
-
-$(BINS_$(d)): $(OBJ_DIR)/libn/test.o
- $(LINK)
-
-include share/pop.mk
diff --git a/src/libc/stdio.c b/src/libc/stdio.c
deleted file mode 100644
index 8bbbe9a..0000000
--- a/src/libc/stdio.c
+++ /dev/null
@@ -1,59 +0,0 @@
-#include <u.h>
-#include <libc.h>
-
-int
-printf(byte* fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
-
- int nw, rem, peek, len;
- byte *str, c;
-
- while (*fmt) {
- rem = INT_MAX - nw;
-
- if (fmt[0] != '%' || fmt[1] == '%') {
- if (fmt[0] == '%') fmt++;
-
- for (peek = 1; fmt[peek] && fmt[peek] != '%'; peek++) {
- ;
- }
- if (rem < peek) return -1;
- // TODO: Print here.
- fmt += peek;
- nw += peek;
- continue;
- }
-
- str = fmt++;
-
- switch (*fmt++) {
- case 'c':
- c = va_arg(args, int);
- if (rem < 0) return -1;
- // TODO: Print here
- nw++;
- break;
-
- case 's':
- str = va_arg(args, byte*);
- len = strlen(str);
- if (rem < len) return -1;
- // TODO: Print here
- nw += len;
- break;
- default:
- fmt = str;
- len = strlen(fmt);
- if (rem < len) return -1;
- // TODO: Print here
- nw += len;
- fmt += len;
- break;
- }
- }
-
- va_end(args);
- return nw;
-}
diff --git a/src/libc/string.c b/src/libc/string.c
deleted file mode 100644
index 0e41efa..0000000
--- a/src/libc/string.c
+++ /dev/null
@@ -1,80 +0,0 @@
-#include <u.h>
-#include <libc.h>
-
-void*
-memcopy(void *dst, void *src, intptr n)
-{
- byte *e, *s, *d;
-
- d = dst;
- e = d + n;
- for (s = src ; d != e; ++s, ++d) {
- *d = *s;
- }
-
- return dst;
-}
-
-void*
-memmove(void *dst, void *src, intptr n)
-{
- byte *e, *s, *d;
- s = src;
- d = dst;
-
- if (d < s) {
- e = d + n;
- for (; d != e; ++s, ++d)
- *d = *s;
-
- } else {
- e = d;
- d += n;
- s += n;
- for (; d != e; --s, --d)
- d[-1] = s[-1];
- }
-
- return dst;
-}
-
-void*
-memset(void *buf, int val, intptr n)
-{
- byte *b, *e;
- b = buf;
- e = b + n;
- for (; b != e; b++) {
- *b = (byte)val;
- }
-
- return buf;
-}
-
-int
-memcmp(void *lhs, void *rhs, intptr n)
-{
- byte *bl, *br, *e;
-
- br = rhs;
- e = br + n;
- for (bl = lhs; br != e; ++bl, ++br) {
- if (*bl < *br)
- return -1;
- else if (*bl > *br)
- return 1;
- }
-
- return 0;
-}
-
-int
-strlen(byte* s)
-{
- byte* b;
- for (b = s; *b; b++) {
- ;
- }
-
- return b - s;
-}