diff options
Diffstat (limited to 'src/userspace/mlibc/string')
-rw-r--r-- | src/userspace/mlibc/string/memcmp.c | 14 | ||||
-rw-r--r-- | src/userspace/mlibc/string/memcpy.c | 9 | ||||
-rw-r--r-- | src/userspace/mlibc/string/memset.c | 8 |
3 files changed, 31 insertions, 0 deletions
diff --git a/src/userspace/mlibc/string/memcmp.c b/src/userspace/mlibc/string/memcmp.c new file mode 100644 index 0000000..af2125c --- /dev/null +++ b/src/userspace/mlibc/string/memcmp.c @@ -0,0 +1,14 @@ +#include <stddef.h> + +int memcmp(const void *a_ptr, const void *b_ptr, size_t size) +{ + const unsigned char *a = (const unsigned char *) a_ptr; + const unsigned char *b = (const unsigned char *) b_ptr; + for (size_t i = 0; i < size; i++) { + if (a[i] < b[i]) + return -1; + else if (b[i] < a[i]) + return 1; + } + return 0; +}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/memcpy.c b/src/userspace/mlibc/string/memcpy.c new file mode 100644 index 0000000..e4e9c76 --- /dev/null +++ b/src/userspace/mlibc/string/memcpy.c @@ -0,0 +1,9 @@ +#include <stddef.h> + +void *memcpy(void *dest, const void *src, size_t count) +{ + const char *sp = (const char *) src; + char *dp = (char *) dest; + for (; count != 0; count--) *dp++ = *sp++; + return dest; +}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/memset.c b/src/userspace/mlibc/string/memset.c new file mode 100644 index 0000000..fb5ab80 --- /dev/null +++ b/src/userspace/mlibc/string/memset.c @@ -0,0 +1,8 @@ +#include <stddef.h> + +void *memset(void *dest, char val, size_t count) +{ + char *temp = (char *) dest; + for (; count != 0; count--) *temp++ = val; + return dest; +}
\ No newline at end of file |