From 501aeb540a2ec1faf68893c0c70c3520109242a9 Mon Sep 17 00:00:00 2001 From: ocean Date: Thu, 27 Oct 2005 02:55:18 +0000 Subject: * missing.h, missing/memcmp.c, missing/memmove.c: ANSI compatible interface. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@9470 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- missing/memcmp.c | 9 ++++----- missing/memmove.c | 17 ++++++++--------- 2 files changed, 12 insertions(+), 14 deletions(-) (limited to 'missing') diff --git a/missing/memcmp.c b/missing/memcmp.c index 9edc9c13b..5b3ad3817 100644 --- a/missing/memcmp.c +++ b/missing/memcmp.c @@ -1,16 +1,15 @@ /* public domain rewrite of memcmp(3) */ +#include + int -memcmp(s1,s2,len) - char *s1; - char *s2; - register int len; +memcmp(const void *s1, const void *s2, size_t len) { register unsigned char *a = (unsigned char*)s1; register unsigned char *b = (unsigned char*)s2; register int tmp; - while (len--) { + for (; len; --len) { if (tmp = *a++ - *b++) return tmp; } diff --git a/missing/memmove.c b/missing/memmove.c index c9d67d8b4..19c5f1884 100644 --- a/missing/memmove.c +++ b/missing/memmove.c @@ -1,22 +1,21 @@ /* public domain rewrite of memcmp(3) */ +#include + void * -memmove (d, s, n) - void *d, *s; - int n; +memmove(void *d, const void *s, size_t n) { - char *dst = d; - char *src = s; - void *ret = dst; + char *dst = (char *)d; + const char *src = (const char *)s; if (src < dst) { src += n; dst += n; - while (n--) + for (; n; --n) *--dst = *--src; } else if (dst < src) - while (n--) + for (; n; --n) *dst++ = *src++; - return ret; + return d; } -- cgit