scc

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

wcstok.c (418B)


      1 #include <wchar.h>
      2 
      3 #undef wcstok
      4 
      5 wchar_t *
      6 wcstok(wchar_t * restrict s1, const wchar_t * restrict s2,
      7        wchar_t **restrict ptr)
      8 {
      9 	wchar_t *line;
     10 
     11 	if (s1)
     12 		line = s1;
     13 	else
     14 		line = *ptr;
     15 
     16 	if (!line)
     17 		return NULL;
     18 
     19 	s1 = line + wcsspn(line, s2);
     20 	if (*s1 == L'\0')
     21 		return *ptr = NULL;
     22 
     23 	line = s1 + wcscspn(s1, s2);
     24 	if (*line == '\0')
     25 		line = NULL;
     26 	else
     27 		*line++ = L'\0';
     28 	*ptr = line;
     29 
     30 	return s1;
     31 }