diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
| commit | fc00c656c96528112d05cf0edf8631bd5eaea446 (patch) | |
| tree | a6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/string/memmove.c | |
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/string/memmove.c')
| -rw-r--r-- | lib/libc/string/memmove.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/libc/string/memmove.c b/lib/libc/string/memmove.c new file mode 100644 index 00000000..88968185 --- /dev/null +++ b/lib/libc/string/memmove.c @@ -0,0 +1,21 @@ +#include <stddef.h> +#include <stdint.h> + +void *memmove(void *dst, const void *src, size_t n) +{ + uint8_t *d = dst; + const uint8_t *s = src; + + if (d == s || n == 0) + return dst; + + if ((uintptr_t)d < (uintptr_t)s) { + for (size_t i = 0; i < n; i++) + d[i] = s[i]; + } else { + for (size_t i = n; i != 0; i--) + d[i - 1] = s[i - 1]; + } + + return dst; +} |
