summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.xyz>2021-01-18 21:32:00 -0600
committerDanny Holman <dholman@gymli.xyz>2021-01-18 21:32:00 -0600
commit655452d663f6f9b32d450cc5d00c3005b7588ea1 (patch)
tree47ce51fe93e50b6d5eb98a7cccc041ad3a260efa /kernel
parentdc14ce95d1fa5bf9978b60d370189405ede9ee9c (diff)
kernel: finish implementing string functions
Finish implementing the functions from string.h in string.c. Signed-off-by: Danny Holman <dholman@gymli.xyz>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/string.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/kernel/string.c b/kernel/string.c
index 3610909..5b5957c 100644
--- a/kernel/string.c
+++ b/kernel/string.c
@@ -1,19 +1,53 @@
#include <kernel/string.h>
int memcmp(const void *str1, const void *str2, size_t n) {
- return 0;
+ unsigned char *p1 = str1;
+ unsigned char *p2 = str2;
+ int ret = 0;
+
+ if (str1 == str2)
+ return 0;
+
+ while (n > 0) {
+ if (*p1 != *p2) {
+ ret = (*p1 > *p2)?1:-1;
+ break;
+ }
+ n--;
+ p1++;
+ p2++;
+ }
+ return ret;
}
void* memcpy(void* __restrict dest, const void* __restrict src, size_t n) {
- return NULL;
+ if (dest == src)
+ return dest;
+
+ unsigned char *pdest = dest;
+ unsigned char const *psrc = src;
+ for (size_t i = 0; i < n; i++)
+ pdest[i] = psrc[i];
+ return dest;
}
void* memmove(void* __restrict dest, const void* __restrict src, size_t n) {
- return NULL;
+ if (dest == src)
+ return dest;
+
+ unsigned char const *psrc = src;
+ unsigned char buffer[n];
+
+ for (size_t i = 0; i < n; i++)
+ buffer[i] = psrc[i];
+ return memcpy(dest, (void*)buffer, n);
}
void* memset(void *str, int c, size_t n) {
- return NULL;
+ unsigned char *p = str;
+ for (size_t i = 0; i < n; i++)
+ p[i] = (unsigned char)c;
+ return str;
}
size_t strlen(const char *str) {