1*46a6070bSAugustin Cavalier #define _GNU_SOURCE 2*46a6070bSAugustin Cavalier #include <string.h> 3*46a6070bSAugustin Cavalier 4*46a6070bSAugustin Cavalier #define BITOP(a,b,op) \ 5*46a6070bSAugustin Cavalier ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) 6*46a6070bSAugustin Cavalier 7*46a6070bSAugustin Cavalier size_t strcspn(const char *s, const char *c) 8*46a6070bSAugustin Cavalier { 9*46a6070bSAugustin Cavalier const char *a = s; 10*46a6070bSAugustin Cavalier size_t byteset[32/sizeof(size_t)]; 11*46a6070bSAugustin Cavalier 12*46a6070bSAugustin Cavalier if (!c[0] || !c[1]) return strchrnul(s, *c)-a; 13*46a6070bSAugustin Cavalier 14*46a6070bSAugustin Cavalier memset(byteset, 0, sizeof byteset); 15*46a6070bSAugustin Cavalier for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++); 16*46a6070bSAugustin Cavalier for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++); 17*46a6070bSAugustin Cavalier return s-a; 18*46a6070bSAugustin Cavalier } 19