From: Ben Pfaff Date: Wed, 18 Aug 2004 00:11:22 +0000 (+0000) Subject: Add memcmp(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=540641a18c65c05df757ced2f225ade578da15aa;p=pintos-anon Add memcmp(). Use unsigned char instead of uint8_t for string functions. --- diff --git a/src/lib/lib.c b/src/lib/lib.c index d439f5d..0c590e3 100644 --- a/src/lib/lib.c +++ b/src/lib/lib.c @@ -10,7 +10,7 @@ void * memset (void *dst_, int value, size_t cnt) { - uint8_t *dst = dst_; + unsigned char *dst = dst_; while (cnt-- > 0) *dst++ = value; @@ -21,8 +21,8 @@ memset (void *dst_, int value, size_t cnt) void * memcpy (void *dst_, const void *src_, size_t cnt) { - uint8_t *dst = dst_; - const uint8_t *src = src_; + unsigned char *dst = dst_; + const unsigned char *src = src_; while (cnt-- > 0) *dst++ = *src++; @@ -33,8 +33,8 @@ memcpy (void *dst_, const void *src_, size_t cnt) void * memmove (void *dst_, const void *src_, size_t cnt) { - uint8_t *dst = dst_; - const uint8_t *src = src_; + unsigned char *dst = dst_; + const unsigned char *src = src_; if (dst < src) { @@ -55,8 +55,8 @@ memmove (void *dst_, const void *src_, size_t cnt) void * memchr (const void *block_, int ch_, size_t size) { - const uint8_t *block = block_; - uint8_t ch = ch_; + const unsigned char *block = block_; + unsigned char ch = ch_; for (; size-- > 0; block++) if (*block == ch) @@ -65,6 +65,18 @@ memchr (const void *block_, int ch_, size_t size) return NULL; } +int +memcmp (const void *a_, const void *b_, size_t size) +{ + const unsigned char *a = a_; + const unsigned char *b = b_; + + for (; size-- > 0; a++, b++) + if (*a != *b) + return *a > *b ? +1 : -1; + return 0; +} + size_t strlcpy (char *dst, const char *src, size_t size) { diff --git a/src/lib/lib.h b/src/lib/lib.h index 29dc17c..2f788be 100644 --- a/src/lib/lib.h +++ b/src/lib/lib.h @@ -11,6 +11,7 @@ void *memset (void *, int, size_t); void *memcpy (void *, const void *, size_t); void *memmove (void *, const void *, size_t); void *memchr (const void *, int, size_t); +int memcmp (const void *, const void *, size_t); char *strchr (const char *, int); size_t strlcpy (char *, const char *, size_t);