1#include <stdio.h>
2
3char *strsep(char **stringp, const char *delim)
4{
5	char *s, *tok;
6	const char *spanp;
7	int c, sc;
8
9	s = *stringp;
10	if (!s)
11		return NULL;
12
13	tok = s;
14	do {
15		c = *s++;
16		spanp = delim;
17		do {
18			sc = *spanp++;
19			if (sc == c) {
20				if (c == 0)
21					s = NULL;
22				else
23					s[-1] = 0;
24				*stringp = s;
25				return tok;
26			}
27		} while (sc != 0);
28	} while (1);
29}
30