implement memmove

This commit is contained in:
2025-12-24 12:55:43 +01:00
parent f79a8e7e25
commit cabb0fabd5

View File

@@ -29,5 +29,19 @@ void *memcpy(void *restrict dst, const void *restrict src, usize n)
void *memmove(void *dst, const void *src, usize n) void *memmove(void *dst, const void *src, usize n)
{ {
/* TODO: Moves memory area, allowing overlap. As though an array is used. */ const u8 *ssrc = src;
u8 *sdst = dst;
/* If the destination is before, or equal to the source,
* we needn't worry about accidentally overriding the source
* before it is written to the destination. */
if (sdst > ssrc) {
sdst += n;
ssrc += n;
while (n--) *(--sdst) = *(--ssrc);
} else {
while (n--) *(sdst++) = *(ssrc++);
}
return dst;
} }