fix ESRCH error handling for clock_getcpuclockid
[musl] / src / string / memchr.c
index a0472f7..65f0d78 100644 (file)
@@ -1,5 +1,4 @@
 #include <string.h>
-#include <stdlib.h>
 #include <stdint.h>
 #include <limits.h>
 
@@ -13,12 +12,16 @@ void *memchr(const void *src, int c, size_t n)
 {
        const unsigned char *s = src;
        c = (unsigned char)c;
+#ifdef __GNUC__
        for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--);
        if (n && *s != c) {
-               const size_t *w;
+               typedef size_t __attribute__((__may_alias__)) word;
+               const word *w;
                size_t k = ONES * c;
                for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS);
-               for (s = (const void *)w; n && *s != c; s++, n--);
+               s = (const void *)w;
        }
+#endif
+       for (; n && *s != c; s++, n--);
        return n ? (void *)s : 0;
 }