diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-09 15:48:13 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-09 15:48:55 +0200 |
commit | b149dd7584094e442c1590036786828d94cc2734 (patch) | |
tree | c6770eb081d58d09c4f8dfcbc1fb05a6e769928e /Libraries | |
parent | c452aa891fd08d292811b75974a81921c85a7e66 (diff) | |
download | serenity-b149dd7584094e442c1590036786828d94cc2734.zip |
LibC: Provide generic versions of memcpy() and memset() for non-i386 builds.
We don't actually do any non-i386 builds at the moment, this is just gently
steering in a nice direction for the future. :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibC/string.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Libraries/LibC/string.cpp b/Libraries/LibC/string.cpp index 905e967d51..76e9a51aeb 100644 --- a/Libraries/LibC/string.cpp +++ b/Libraries/LibC/string.cpp @@ -1,7 +1,8 @@ -#include "ctype.h" +#include <AK/Platform.h> #include <AK/StdLibExtras.h> #include <AK/Types.h> #include <assert.h> +#include <ctype.h> #include <errno.h> #include <signal.h> #include <stdio.h> @@ -132,6 +133,7 @@ int memcmp(const void* v1, const void* v2, size_t n) return 0; } +#if ARCH(I386) void* memcpy(void* dest_ptr, const void* src_ptr, size_t n) { if (n >= 1024) @@ -182,6 +184,24 @@ void* memset(void* dest_ptr, int c, size_t n) : "memory"); return dest_ptr; } +#else +void* memcpy(void* dest_ptr, const void* src_ptr, size_t n) +{ + auto* dest = (u8*)dest_ptr; + auto* src = (const u8*)src_ptr; + for (size_t i = 0; i < n; ++i) + dest[i] = src[i]; + return dest_ptr; +} + +void* memset(void* dest_ptr, int c, size_t n) +{ + auto* dest = (u8*)dest_ptr; + for (size_t i = 0; i < n; ++i) + dest[i] = (u8)c; + return dest_ptr; +} +#endif void* memmove(void* dest, const void* src, size_t n) { |