1*90dca2bcSAugustin Cavalier #define _DEFAULT_SOURCE
246a6070bSAugustin Cavalier #include <string.h>
346a6070bSAugustin Cavalier
446a6070bSAugustin Cavalier #define BITOP(a,b,op) \
546a6070bSAugustin Cavalier ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
646a6070bSAugustin Cavalier
strcspn(const char * s,const char * c)746a6070bSAugustin Cavalier size_t strcspn(const char *s, const char *c)
846a6070bSAugustin Cavalier {
946a6070bSAugustin Cavalier const char *a = s;
1046a6070bSAugustin Cavalier size_t byteset[32/sizeof(size_t)];
1146a6070bSAugustin Cavalier
1246a6070bSAugustin Cavalier if (!c[0] || !c[1]) return strchrnul(s, *c)-a;
1346a6070bSAugustin Cavalier
1446a6070bSAugustin Cavalier memset(byteset, 0, sizeof byteset);
1546a6070bSAugustin Cavalier for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++);
1646a6070bSAugustin Cavalier for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++);
1746a6070bSAugustin Cavalier return s-a;
1846a6070bSAugustin Cavalier }
19