shithub: scc

ref: 9332f34cf7bae72b9ccaa290cae5a1eec3f34f3d
dir: /src/libc/string/strtok.c/

View raw version
#include <string.h>
#undef strtok

char *
strtok(char * restrict s, const char * restrict delim)
{
	static char *line;

	if (s)
		line = s;
	if (!s && !line)
		return NULL;

	s = line + strspn(line, delim);
	if (*s == '\0')
		return line = NULL;

	line = s + strcspn(s, delim);
	if (*line != '\0')
		*line++ = '\0';
	else
		line = NULL;

	return s;
}