X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstring%2Fstrchr.c;h=3cbc828bebf705ae570e1bfd0c2b518f929c054c;hb=1ef37aa00ea830dfda76e04e3d941cafa74d8b76;hp=2fe033868206cbd31e914de27aa9995f7d92023a;hpb=c68b26369e89ead7511ef113850035775c5d183d;p=musl diff --git a/src/string/strchr.c b/src/string/strchr.c index 2fe03386..3cbc828b 100644 --- a/src/string/strchr.c +++ b/src/string/strchr.c @@ -1,25 +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) { - size_t *w, k; - - c = (unsigned char)c; - if (!c) return (char *)s + strlen(s); - - for (; ((uintptr_t)s & ALIGN) && *s; s++) - if (*(unsigned char *)s == c) return (char *)s; - k = ONES * c; - for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++); - for (s = (void *)w; *s; s++) - if (*(unsigned char *)s == c) return (char *)s; - return 0; + char *r = __strchrnul(s, c); + return *(unsigned char *)r == (unsigned char)c ? r : 0; }