X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstring%2Fstrchr.c;h=bfae8f9f846a01c14d288d34e8659f265a9daf2e;hb=74025c80ce1eb4cda110ab2e3ac11718d3c6f2ff;hp=2fe033868206cbd31e914de27aa9995f7d92023a;hpb=c68b26369e89ead7511ef113850035775c5d183d;p=musl diff --git a/src/string/strchr.c b/src/string/strchr.c index 2fe03386..bfae8f9f 100644 --- a/src/string/strchr.c +++ b/src/string/strchr.c @@ -1,25 +1,9 @@ #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 *__strchrnul(const char *, int); 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; }