diff options
author | Jakob Kaivo <jkk@ung.org> | 2024-01-31 21:00:08 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2024-01-31 21:00:08 -0500 |
commit | d242a498377350add06ba70da2f7ce1d2c593cc1 (patch) | |
tree | 910357a0f1741f7613b99f376e8df9f610747f42 /src/string | |
parent | 8b7854890447d4250aa8e0c17aea6f498276ba2e (diff) |
implement both directions directly rather than punting to memcpy()
Diffstat (limited to 'src/string')
-rw-r--r-- | src/string/memmove.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/string/memmove.c b/src/string/memmove.c index 22677b6d..5d6dd3e0 100644 --- a/src/string/memmove.c +++ b/src/string/memmove.c @@ -10,16 +10,17 @@ void * memmove(void *s1, const void *s2, size_t n) ASSERT_NONNULL(s2); if (s1 < s2) { - return memcpy(s1, s2, n); - } - - /* reverse memcpy() */ - while (n > 0) { + for (size_t i = 0; i < n; i++) { + ((char*)s1)[i] = ((char*)s2)[i]; + } + } else { + while (n > 0) { + ((char*)s1)[n] = ((char*)s2)[n]; + n--; + } + /* last byte */ ((char*)s1)[n] = ((char*)s2)[n]; - n--; } - /* last byte */ - ((char*)s1)[n] = ((char*)s2)[n]; /* RETURN_ALWAYS(ARGUMENT(s1)); |