blob: bc812e2234a128408f2f63efbca55e6a32bd7680 [file] [log] [blame]
#include <string.h>
#include <stdint.h>
#include <limits.h>
#define ALIGN (sizeof(size_t))
#define ONES ((size_t)-1/UCHAR_MAX)
#define HIGHS (ONES * (UCHAR_MAX/2+1))
#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
#if defined(USE_COBALT_CUSTOMIZATIONS)
#ifdef __GNUC__
__attribute__((no_sanitize("address")))
#endif // __GNUC__
#endif // defined(USE_COBALT_CUSTOMIZATIONS)
size_t strlen(const char *s)
{
const char *a = s;
#ifdef __GNUC__
typedef size_t __attribute__((__may_alias__)) word;
const word *w;
for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a;
for (w = (const void *)s; !HASZERO(*w); w++);
s = (const void *)w;
#endif
for (; *s; s++);
return s-a;
}