diff options
-rw-r--r-- | src/include/stdlib.h | 7 | ||||
-rw-r--r-- | src/include/string.h | 11 | ||||
-rw-r--r-- | src/library/Makefile | 2 | ||||
-rw-r--r-- | src/library/std/string.c | 39 |
4 files changed, 58 insertions, 1 deletions
diff --git a/src/include/stdlib.h b/src/include/stdlib.h new file mode 100644 index 0000000..b232649 --- /dev/null +++ b/src/include/stdlib.h @@ -0,0 +1,7 @@ +#ifndef _DEF_STDLIB_H +#define _DEF_STDLIB_H + +//includes malloc/free +#include <gc/mem.h> + +#endif diff --git a/src/include/string.h b/src/include/string.h new file mode 100644 index 0000000..15ec3f3 --- /dev/null +++ b/src/include/string.h @@ -0,0 +1,11 @@ +#ifndef _DEF_STRING_H +#define _DEF_STRING_H + +#include <gc/syscall.h> + +void *memcpy(void *dest, const void *src, int count); +uint8_t *memset(uint8_t *dest, uint8_t val, int count); +uint16_t *memsetw(uint16_t *dest, uint16_t val, int count); +int strlen(const char *str); + +#endif diff --git a/src/library/Makefile b/src/library/Makefile index f7161b6..1451c26 100644 --- a/src/library/Makefile +++ b/src/library/Makefile @@ -9,7 +9,7 @@ LDFLAGS = -r Library = grapes.o Objects = gc/syscall.o gc/server.o \ gc/mem.o gc/shm.o \ - std/mutex.o \ + std/mutex.o std/string.o \ start.o all: $(Library) diff --git a/src/library/std/string.c b/src/library/std/string.c new file mode 100644 index 0000000..869256a --- /dev/null +++ b/src/library/std/string.c @@ -0,0 +1,39 @@ +#include <string.h> + +int strlen(const char *str) { + int i = 0; + while (str[i++]); + return i; +} + +void *memcpy(void *vd, const void *vs, int count) { + uint8_t *dest = (uint8_t*)vd, *src = (uint8_t*)vs; + uint32_t 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; +} + +uint8_t *memset(uint8_t *dest, uint8_t val, int count) { + int i; + for (i = 0; i < count; i++) { + dest[i] = val; + } + return dest; +} + +uint16_t *memsetw(uint16_t *dest, uint16_t val, int count) { + int i; + for (i = 0; i < count; i++) { + dest[i] = val; + } + return dest; +} |