scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

strspn.c (327B)


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