2022-03-21 21:51:23 -04:00
|
|
|
#include "global.h"
|
|
|
|
|
2024-11-11 19:46:25 -05:00
|
|
|
/**
|
|
|
|
* memmove: copies `len` bytes from memory starting at `src` to memory starting at `dest`.
|
|
|
|
*
|
|
|
|
* Unlike memcpy(), the regions of memory may overlap.
|
|
|
|
*
|
|
|
|
* @param dest address of start of buffer to write to
|
|
|
|
* @param src address of start of buffer to read from
|
|
|
|
* @param len number of bytes to copy.
|
|
|
|
*
|
|
|
|
* @return dest
|
|
|
|
*/
|
|
|
|
void* oot_memmove(void* dest, const void* src, size_t len) {
|
|
|
|
char* d = dest;
|
|
|
|
const char* s = src;
|
2022-03-21 21:51:23 -04:00
|
|
|
|
2024-11-11 19:46:25 -05:00
|
|
|
if (d == s) {
|
|
|
|
return dest;
|
2022-03-21 21:51:23 -04:00
|
|
|
}
|
2024-11-11 19:46:25 -05:00
|
|
|
if (d < s) {
|
|
|
|
while (len--) {
|
|
|
|
*d++ = *s++;
|
2022-03-21 21:51:23 -04:00
|
|
|
}
|
|
|
|
} else {
|
2024-11-11 19:46:25 -05:00
|
|
|
d += len - 1;
|
|
|
|
s += len - 1;
|
|
|
|
while (len--) {
|
|
|
|
*d-- = *s--;
|
2022-03-21 21:51:23 -04:00
|
|
|
}
|
|
|
|
}
|
2024-11-11 19:46:25 -05:00
|
|
|
return dest;
|
2022-03-21 21:51:23 -04:00
|
|
|
}
|