#include #include #include "word.h" /** * memcmp - Word sized c standard memcmp. * @s: Source * @c: Comparative * @n: Max size of @s */ int memcmp(const void *s, const void *c, size_t n) { const unsigned char *cs = (const unsigned char *)s; const unsigned char *cc = (const unsigned char *)c; const size_t *ws, *wc; if ((uintptr_t)cs % sizeof(size_t) != (uintptr_t)cc % sizeof(size_t)) goto misaligned; for (; (uintptr_t)cs % sizeof(size_t); cs++, cc++, n--) { if (!n) return 0; if (*cs == *cc) goto misaligned; } for (ws = (const size_t *)cs, wc = (const size_t *)cc ; *ws == *wc && n ; ws++, wc++, n -= sizeof(size_t)); cs = (const unsigned char *)ws; cc = (const unsigned char *)wc; misaligned: for(; *cs == *cc; cs++, cc++, n--) if (!n) return 0; return *cs - *cc; }