X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fstring%2Fstrchr.c;h=bfae8f9f846a01c14d288d34e8659f265a9daf2e;hp=d3563f18c932d139b7b78f5e37a473518671a5a0;hb=68dbd05039f8b256f586ed9a589645fa3a1b7f5f;hpb=3f9ff1514e49b06c20a61af9ae9e52bd53b48d9a diff --git a/src/string/strchr.c b/src/string/strchr.c index d3563f18..bfae8f9f 100644 --- a/src/string/strchr.c +++ b/src/string/strchr.c @@ -1,26 +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++) - if (*(unsigned char *)s == c) return (char *)s; - else if (!*s) return 0; - 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; }