iconv: add euro symbol to GBK as single byte 0x80
[musl.git] / src / string / strchrnul.c
blob39e2635b3064df1e2b15cb45d60c654238ad8f79
1 #include <string.h>
2 #include <stdint.h>
3 #include <limits.h>
5 #define ALIGN (sizeof(size_t))
6 #define ONES ((size_t)-1/UCHAR_MAX)
7 #define HIGHS (ONES * (UCHAR_MAX/2+1))
8 #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
10 char *__strchrnul(const char *s, int c)
12 c = (unsigned char)c;
13 if (!c) return (char *)s + strlen(s);
15 #ifdef __GNUC__
16 typedef size_t __attribute__((__may_alias__)) word;
17 const word *w;
18 for (; (uintptr_t)s % ALIGN; s++)
19 if (!*s || *(unsigned char *)s == c) return (char *)s;
20 size_t k = ONES * c;
21 for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++);
22 s = (void *)w;
23 #endif
24 for (; *s && *(unsigned char *)s != c; s++);
25 return (char *)s;
28 weak_alias(__strchrnul, strchrnul);