aboutsummaryrefslogtreecommitdiff
path: root/kernel/lib
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2014-11-30 20:05:47 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2014-11-30 20:05:47 +0100
commita375561ca15a99dd7024e5b8170a3c8fcf25b892 (patch)
tree06ec9ff45e49400d67f73ce20b3236d8551916a5 /kernel/lib
parent54e7efbbd0e0c88d99bb6bddb82e9fc8d90eae50 (diff)
downloadkogata-a375561ca15a99dd7024e5b8170a3c8fcf25b892.tar.gz
kogata-a375561ca15a99dd7024e5b8170a3c8fcf25b892.zip
More library functions & renaming.
Diffstat (limited to 'kernel/lib')
-rw-r--r--kernel/lib/stdlib.c8
-rw-r--r--kernel/lib/string.c68
2 files changed, 68 insertions, 8 deletions
diff --git a/kernel/lib/stdlib.c b/kernel/lib/stdlib.c
deleted file mode 100644
index 6710da2..0000000
--- a/kernel/lib/stdlib.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <stdlib.h>
-
-size_t strlen(const char* str) {
- size_t ret = 0;
- while (str[ret] != 0)
- ret++;
- return ret;
-}
diff --git a/kernel/lib/string.c b/kernel/lib/string.c
new file mode 100644
index 0000000..da8f60e
--- /dev/null
+++ b/kernel/lib/string.c
@@ -0,0 +1,68 @@
+#include <string.h>
+
+
+size_t strlen(const char* str) {
+ size_t ret = 0;
+ while (str[ret] != 0)
+ ret++;
+ return ret;
+}
+
+char *strchr(const char *str, char c) {
+ while (*str) {
+ if (*str == c) return (char*)str;
+ str++;
+ }
+ return NULL;
+}
+
+char *strcpy(char *dest, const char *src) {
+ memcpy(dest, src, strlen(src) + 1);
+ return (char*)src;
+}
+
+char *strcat(char *dest, const char *src) {
+ char *dest2 = dest;
+ dest2 += strlen(dest) - 1;
+ while (*src) {
+ *dest2 = *src;
+ src++;
+ dest2++;
+ }
+ *dest2 = 0;
+ return dest;
+}
+
+int strcmp(const char *s1, const char *s2) {
+ while ((*s1) && (*s1 == *s2)) {
+ s1++;
+ s2++;
+ }
+ return (* (unsigned char*)s1 - *(unsigned char*)s2);
+}
+
+void *memcpy(void *vd, const void *vs, int count) {
+ uint8_t *dest = (uint8_t*)vd, *src = (uint8_t*)vs;
+ int f = count % 4, n = count / 4, i;
+ const uint32_t* s = (uint32_t*)src;
+ uint32_t* d = (uint32_t*)dest;
+ for (i = 0; i < n; i++) {
+ d[i] = s[i];
+ }
+ if (f != 0) {
+ for (i = count - f; i < count; i++) {
+ dest[i] = src[i];
+ }
+ }
+ return vd;
+}
+
+void *memset(void *dest, int val, int count) {
+ uint8_t *dest_c = (uint8_t*)dest;
+ int i;
+ for (i = 0; i < count; i++) {
+ dest_c[i] = val;
+ }
+ return dest;
+}
+