summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) {