diff --git a/src/kernel/libroot/posix/string/strtok.c b/src/kernel/libroot/posix/string/strtok.c index d5538d3f7d..1db66098d9 100644 --- a/src/kernel/libroot/posix/string/strtok.c +++ b/src/kernel/libroot/posix/string/strtok.c @@ -6,27 +6,38 @@ #include #include - static char *___strtok = NULL; char * -strtok(char *s, char const *ct) +strtok_r(char *s, char const *ct, char **save_ptr) { char *sbegin, *send; + + if (!s && !save_ptr) + return NULL; - sbegin = s ? s : ___strtok; + sbegin = s ? s : *save_ptr; if (!sbegin) { return NULL; } sbegin += strspn(sbegin,ct); if (*sbegin == '\0') { - ___strtok = NULL; + if (save_ptr) + *save_ptr = NULL; return NULL; } send = strpbrk(sbegin, ct); if (send && *send != '\0') *send++ = '\0'; - ___strtok = send; + if (save_ptr) + *save_ptr = send; return sbegin; } + +char * +strtok(char *s, char const *ct) +{ + return strtok_r(s, ct, &___strtok); +} +