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