Implement memcmp

This commit is contained in:
Ali Mashtizadeh 2014-07-31 18:16:08 -07:00
parent e901bdc7ce
commit 008488413a
2 changed files with 19 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include <stdint.h>
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);

View File

@ -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;
}