From fbfc078e9f44c1c1e95c9c484f1d5650bcf631b7 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sat, 27 Jul 2024 16:57:39 -0400 Subject: lots and lots of userspace stuff --- euler/source/std/cstring.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 euler/source/std/cstring.cpp (limited to 'euler/source/std/cstring.cpp') diff --git a/euler/source/std/cstring.cpp b/euler/source/std/cstring.cpp new file mode 100644 index 0000000..3e5a56c --- /dev/null +++ b/euler/source/std/cstring.cpp @@ -0,0 +1,36 @@ +#include + +extern "C" void *memset(void *dest, int ch, size_t count) { + unsigned char c = static_cast(ch); + unsigned char *d = (unsigned char *)dest; + for (size_t i = 0; i < count; ++i) + d[i] = c; + return dest; +} + +extern "C" void *memcpy(void *dest, const void *src, size_t count) { + unsigned char *d = (unsigned char *)dest; + const unsigned char *s = (const unsigned char *)src; + for (size_t i = 0; i < count; ++i) + d[i] = s[i]; + return dest; +} + +extern "C" int strcmp(const char *lhs, const char *rhs) { + const unsigned char *l = (const unsigned char *)lhs; + const unsigned char *r = (const unsigned char *)rhs; + while (*l == *r) { + if (*l == 0) + return 0; + ++l; + ++r; + } + return *l < *r ? -1 : 1; +} + +extern "C" size_t strlen(const char *str) { + size_t len = 0; + while (str[len] != '\0') + ++len; + return len; +} -- cgit v1.2.3