From 008488413a04bd446fdd26337f1336cb521c0c0d Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Thu, 31 Jul 2014 18:16:08 -0700 Subject: [PATCH] Implement memcmp --- include/string.h | 1 + sys/kern/libc.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/string.h b/include/string.h index 40d2175..8e87086 100644 --- a/include/string.h +++ b/include/string.h @@ -4,6 +4,7 @@ #include +int memcmp(const void *b1, const void *b2, size_t len); void *memcpy(void *dst, const void *src, size_t len); void *memset(void *dst, int c, size_t len); diff --git a/sys/kern/libc.c b/sys/kern/libc.c index 8b5afe5..dc7d0c7 100644 --- a/sys/kern/libc.c +++ b/sys/kern/libc.c @@ -91,3 +91,21 @@ memcpy(void *dst, const void *src, size_t length) return dst; } +int +memcmp(const void *b1, const void *b2, size_t length) +{ + int i; + const char *c1 = (const char *)b1; + const char *c2 = (const char *)b2; + + for (i = 0; i < length; i++) + { + if (*c1 != *c2) + return *c2 - *c1; + c1++; + c2++; + } + + return 0; +} +