X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstring%2Fstrchr.c;h=3cbc828bebf705ae570e1bfd0c2b518f929c054c;hb=c00cdefa1da17f60b3179704528582ef320e61b8;hp=e606f4fee48f3155c22e426f69d9495b60979dd9;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/string/strchr.c b/src/string/strchr.c index e606f4fe..3cbc828b 100644 --- a/src/string/strchr.c +++ b/src/string/strchr.c @@ -1,23 +1,7 @@ #include -#include -#include -#include - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) char *strchr(const char *s, int c) { - c = (char)c; - if (!c) return (char *)s + strlen(s); - for (; ((uintptr_t)s & ALIGN) && *s && *s != c; s++); - if (*s && *s != c) { - const size_t *w; - size_t k = ONES * c; - for (w = (const void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++); - for (s = (const void *)w; *s && *s != c; s++); - } - return *s ? (char *)s : 0; + char *r = __strchrnul(s, c); + return *(unsigned char *)r == (unsigned char)c ? r : 0; }