Debian Codegraph @

libc-top-half/musl/src/string/strspn.c

raw
1 #if !defined(__wasm_simd128__) || !defined(__wasilibc_simd_string) || \
2 __clang_major__ == 19 || __clang_major__ == 20
3 // The SIMD implementation is in strspn_simd.c
4
5 #include <string.h>
6
7 #define BITOP(a,b,op) \
8 ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
9
10 size_t strspn(const char *s, const char *c)
11 {
12 const char *a = s;
13 size_t byteset[32/sizeof(size_t)] = { 0 };
14
15 if (!c[0]) return 0;
16 if (!c[1]) {
17 for (; *s == *c; s++);
18 return s-a;
19 }
20
21 for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++);
22 for (; *s && BITOP(byteset, *(unsigned char *)s, &); s++);
23 return s-a;
24 }
25
26 #endif