Implement memcmp
This commit is contained in:
parent
e901bdc7ce
commit
008488413a
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user