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