aboutsummaryrefslogtreecommitdiff
path: root/src/libc/string.c
diff options
context:
space:
mode:
authorNicholas <nbnoll@eml.cc>2021-11-12 09:22:01 -0800
committerNicholas <nbnoll@eml.cc>2021-11-12 09:22:01 -0800
commitce05175372a9ddca1a225db0765ace1127a39293 (patch)
tree5988b4d4f6b402e4953945886fc90aae11203df6 /src/libc/string.c
parentb375f3cdedb5b0e08745d100b40e38d2f8396a58 (diff)
chore: simplified organizational structurelaptop
Diffstat (limited to 'src/libc/string.c')
-rw-r--r--src/libc/string.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/libc/string.c b/src/libc/string.c
new file mode 100644
index 0000000..0e41efa
--- /dev/null
+++ b/src/libc/string.c
@@ -0,0 +1,80 @@
+#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;
+}