Last active
August 29, 2015 14:27
-
-
Save stu9458/28de97f4c786398426b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__strtok_r(char *s, const char *delim, char **last) | |
{ | |
char *spanp, *tok; | |
int c, sc; | |
if (s == NULL && (s = *last) == NULL) | |
return (NULL); | |
/* | |
* Skip (span) leading delimiters (s += strspn(s, delim), sort of). | |
*/ | |
cont: | |
c = *s++; | |
for (spanp = (char *)delim; (sc = *spanp++) != 0;) { | |
if (c == sc) | |
goto cont; | |
} | |
if (c == 0) { /* no non-delimiter characters */ | |
*last = NULL; | |
return (NULL); | |
} | |
tok = s - 1; | |
/* | |
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of). | |
* Note that delim must have one NUL; we stop if we see that, too. | |
*/ | |
for (;;) { | |
c = *s++; | |
spanp = (char *)delim; | |
do { | |
if ((sc = *spanp++) == c) { | |
if (c == 0) | |
s = NULL; | |
else | |
s[-1] = '\0'; | |
*last = s; | |
return (tok); | |
} | |
} while (sc != 0); | |
} | |
/* NOTREACHED */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment