summaryrefslogtreecommitdiff
path: root/libc/string/strtok.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-10-07 23:37:03 +0000
committerEric Andersen <andersen@codepoet.org>2000-10-07 23:37:03 +0000
commitfbb4007ac88656122f9319dea4563a3a4fd40e82 (patch)
treeca4265ac43d139b3fd02ba32bfe6d5e12cadb65c /libc/string/strtok.c
parentb8f03a94957c913fa0d8588c41b0332b49310ff0 (diff)
Update and simplification.
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;
}