2001-03-06 03:17:54 -05:00
|
|
|
/* public domain rewrite of memcmp(3) */
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-10-26 22:55:18 -04:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2003-11-18 09:34:18 -05:00
|
|
|
void *
|
2005-10-26 22:55:18 -04:00
|
|
|
memmove(void *d, const void *s, size_t n)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2005-10-26 22:55:18 -04:00
|
|
|
char *dst = (char *)d;
|
|
|
|
const char *src = (const char *)s;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-03-06 03:17:54 -05:00
|
|
|
if (src < dst) {
|
|
|
|
src += n;
|
|
|
|
dst += n;
|
2005-10-26 22:55:18 -04:00
|
|
|
for (; n; --n)
|
2001-03-06 03:17:54 -05:00
|
|
|
*--dst = *--src;
|
|
|
|
}
|
|
|
|
else if (dst < src)
|
2005-10-26 22:55:18 -04:00
|
|
|
for (; n; --n)
|
2001-03-06 03:17:54 -05:00
|
|
|
*dst++ = *src++;
|
2005-10-26 22:55:18 -04:00
|
|
|
return d;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|