memcmp.c (230B)
1 #include <string.h> 2 3 #undef memcmp 4 5 int 6 memcmp(const void *s1, const void *s2, size_t n) 7 { 8 const unsigned char *s = s1; 9 const unsigned char *t = s2; 10 11 for (; n > 0 && *s == *t; --n) 12 ++s, ++t; 13 14 return (n > 0) ? *s - *t : 0; 15 }