scc

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

strtok.c (350B)


      1 #include <string.h>
      2 
      3 #undef strtok
      4 
      5 char *
      6 strtok(char * restrict s1, const char * restrict s2)
      7 {
      8 	static char *line;
      9 
     10 	if (s1)
     11 		line = s1;
     12 	else if (!line)
     13 		return NULL;
     14 
     15 	s1 = line + strspn(line, s2);
     16 	if (*s1 == '\0')
     17 		return line = NULL;
     18 
     19 	line = s1 + strcspn(s1, s2);
     20 	if (*line == '\0')
     21 		line = NULL;
     22 	else
     23 		*line++ = '\0';
     24 
     25 	return s1;
     26 }