diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-11-04 09:06:27 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-11-04 09:06:27 +0100 |
commit | 40390ebbd0c3e7363fec85e2c5ecd33fd3c36a63 (patch) | |
tree | 2a47786a1ed6b58e3f2cdc241a1322409671b7d1 /kernel/stdlib.c | |
parent | 53201e79cf34b288083c2e7e7fe95e9fe58fea0f (diff) | |
download | jeyzuos-40390ebbd0c3e7363fec85e2c5ecd33fd3c36a63.zip jeyzuos-40390ebbd0c3e7363fec85e2c5ecd33fd3c36a63.tar.gz |
kernel: add stdlib.[ch]
Diffstat (limited to 'kernel/stdlib.c')
-rw-r--r-- | kernel/stdlib.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/kernel/stdlib.c b/kernel/stdlib.c new file mode 100644 index 0000000..92fdec2 --- /dev/null +++ b/kernel/stdlib.c @@ -0,0 +1,33 @@ +#include "stdlib.h" + +void *memset(void *s, int c, size_t n) +{ + char *p = (char *) s; + + for (size_t i = 0; i < n; i++, p++) + *p = (char) c; + + return s; +} + +/* overlap is not handled */ +void *memcpy(void *dest, void *src, size_t n) +{ + char *s = (char *) src; + char *d = (char *) dest; + + for (size_t i = 0; i < n; i++, s++, d++) + *d = *s; + + return dest; +} + +int strncmp(const char *s1, const char *s2, size_t n) +{ + for (size_t i = 0; i < n; i++, s1++, s2++) { + if (*s1 < *s2) return -1; + if (*s1 > *s2) return 1; + } + + return 0; +} |