iconv: add euro symbol to GBK as single byte 0x80
[musl.git] / src / string / strlen.c
blob309990f029f0c09b4c7c0405258b92ac8f93310d
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 size_t strlen(const char *s)
12 const char *a = s;
13 #ifdef __GNUC__
14 typedef size_t __attribute__((__may_alias__)) word;
15 const word *w;
16 for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a;
17 for (w = (const void *)s; !HASZERO(*w); w++);
18 s = (const void *)w;
19 #endif
20 for (; *s; s++);
21 return s-a;