summaryrefslogtreecommitdiff
path: root/libc/string/strtok.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/string/strtok.c')
-rw-r--r--libc/string/strtok.c58
1 files changed, 25 insertions, 33 deletions
diff --git a/libc/string/strtok.c b/libc/string/strtok.c
index c23c5b85e..51bc6038a 100644
--- a/libc/string/strtok.c
+++ b/libc/string/strtok.c
@@ -30,42 +30,34 @@ static char *olds = 0;
x = strtok(NULL, "="); // x = NULL
// s = "abc\0-def\0"
*/
-char *
-strtok(s, delim)
-register char *s;
-register const char *delim;
+char *strtok( register char *s, register const char *delim)
{
- char *token;
+ char *token;
- if (s == 0)
- {
- if (olds == 0)
- {
- return 0;
+ if (s == 0) {
+ if (olds == 0) {
+ return 0;
+ } else
+ s = olds;
}
- else
- s = olds;
- }
- /* Scan leading delimiters. */
- s += strspn(s, delim);
- if (*s == '\0')
- {
- olds = 0;
- return 0;
- }
+ /* Scan leading delimiters. */
+ s += strspn(s, delim);
+ if (*s == '\0') {
+ olds = 0;
+ return 0;
+ }
- /* Find the end of the token. */
- token = s;
- s = strpbrk(token, delim);
- if (s == 0)
- /* This token finishes the string. */
- olds = 0;
- else
- {
- /* Terminate the token and make OLDS point past it. */
- *s = '\0';
- olds = s + 1;
- }
- return token;
+ /* Find the end of the token. */
+ token = s;
+ s = strpbrk(token, delim);
+ if (s == 0)
+ /* This token finishes the string. */
+ olds = 0;
+ else {
+ /* Terminate the token and make OLDS point past it. */
+ *s = '\0';
+ olds = s + 1;
+ }
+ return token;
}