#include #include #include #include "word.h" /** * memchr - Word sized c standard memchr. * @s: Source * @c: Character * @n: Max size of @s */ void *memchr(const void *s, int c, size_t n) { const unsigned char *cs = (const unsigned char *)s; const size_t *w; c = (unsigned char)c; for (; (uintptr_t)cs % sizeof(size_t); cs++, n--) { if (!n) return NULL; if (*cs == c) return (void *)cs; } for (w = (const size_t *)cs; !word_has_char(*w, c); w++, n--) if (!n) return NULL; for (cs = (const unsigned char *)w; *cs != c; cs++, n--) if (!n) return NULL; return (void *)cs; }