aboutsummaryrefslogtreecommitdiff
path: root/libc/mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/mem.c')
-rw-r--r--libc/mem.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/libc/mem.c b/libc/mem.c
new file mode 100644
index 0000000..58c337b
--- /dev/null
+++ b/libc/mem.c
@@ -0,0 +1,35 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#include <def.h>
+#include <print.h>
+#include <sys.h>
+
+void *memcpy(void *dst, const void *src, u32 n)
+{
+ const char *sp = (const char *)src;
+ char *dp = (char *)dst;
+ for (; n != 0; n--)
+ *dp++ = *sp++;
+ return dst;
+}
+
+void *memset(void *dst, char val, u32 n)
+{
+ char *temp = (char *)dst;
+ for (; n != 0; n--)
+ *temp++ = val;
+ return dst;
+}
+
+int memcmp(const void *s1, const void *s2, u32 n)
+{
+ const u8 *a = (const u8 *)s1;
+ const u8 *b = (const u8 *)s2;
+ for (u32 i = 0; i < n; i++) {
+ if (a[i] < b[i])
+ return -1;
+ else if (b[i] < a[i])
+ return 1;
+ }
+ return 0;
+}