blob: 57555b14c37e7d199f698857f026554aec9ce9f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <string.h>
char *strtok_r(char *restrict s, const char *restrict sep,
char **restrict state)
{
if (s == NULL) {
s = *state;
}
if (s == NULL) {
return NULL;
}
while (*s && strchr(sep, *s)) {
s++;
}
if (*s == '\0') {
*state = NULL;
return NULL;
}
char *start = s;
while (*s && strchr(sep, *s) == NULL) {
s++;
}
if (*s) {
*s = '\0';
*state = s + 1;
} else {
*state = NULL;
}
return start;
}
|