Files
Upsilon/liba/src/memmove.c
Romain Goyet 2898ec916c [liba] Add memmove to string.h
Change-Id: I99b412dc7404e2711dbf7753f0d619694dee3d19
2017-08-04 17:56:23 +02:00

22 lines
436 B
C

#include <string.h>
void * memmove(void * dst, const void * src, size_t n) {
char * destination = (char *)dst;
char * source = (char *)src;
if (source < destination && destination < source + n) {
/* Copy backwards to avoid overwrites */
source += n;
destination += n;
while (n--) {
*--destination = *--source;
}
} else {
while (n--) {
*destination++ = *source++;
}
}
return dst;
}