strcspn.c (355B)
1 #include <string.h> 2 3 #undef strcspn 4 5 size_t 6 strcspn(const char *s1, const char *s2) 7 { 8 const unsigned char *s = (const unsigned char *) s1; 9 const unsigned char *reject = (const unsigned char *) s2; 10 size_t n; 11 unsigned ch; 12 char map[__NUMCHARS] = {0}; 13 14 while (ch = *reject++) 15 map[ch] = 1; 16 17 for (n = 0; (ch = *s++) && !map[ch]; ++n) 18 ; 19 20 return n; 21 }