diff options
| author | dsl <dsl@NetBSD.org> | 2004-10-27 19:12:31 +0000 |
|---|---|---|
| committer | dsl <dsl@NetBSD.org> | 2004-10-27 19:12:31 +0000 |
| commit | d6329c55cd6f714968cd1d659e31ec3ebf1ab125 (patch) | |
| tree | 3a6ec0c0d2abb4e61ece870eae1d87f7265b502c /lib/libc/string | |
| parent | fc23d32c7dada6cb61e53d0f3bb71ff0c4456b05 (diff) | |
Implement strtok() in terms of strtok_r()
Diffstat (limited to 'lib/libc/string')
| -rw-r--r-- | lib/libc/string/strtok.c | 57 |
1 files changed, 6 insertions, 51 deletions
diff --git a/lib/libc/string/strtok.c b/lib/libc/string/strtok.c index d5d9e2baf1f..4fc6214680c 100644 --- a/lib/libc/string/strtok.c +++ b/lib/libc/string/strtok.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtok.c,v 1.11 2003/08/07 16:43:53 agc Exp $ */ +/* $NetBSD: strtok.c,v 1.12 2004/10/27 19:12:31 dsl Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,62 +34,17 @@ #if 0 static char sccsid[] = "@(#)strtok.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: strtok.c,v 1.11 2003/08/07 16:43:53 agc Exp $"); +__RCSID("$NetBSD: strtok.c,v 1.12 2004/10/27 19:12:31 dsl Exp $"); #endif #endif /* LIBC_SCCS and not lint */ -#include <assert.h> +#include <namespace.h> #include <string.h> char * -strtok(s, delim) - char *s; - const char *delim; +strtok(char *s, const char *delim) { - const char *spanp; - int c, sc; - char *tok; - static char *last; + static char *lasts; - /* s may be NULL */ - _DIAGASSERT(delim != NULL); - - if (s == NULL && (s = last) == NULL) - return (NULL); - - /* - * Skip (span) leading delimiters (s += strspn(s, delim), sort of). - */ -cont: - c = *s++; - for (spanp = 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 = delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - last = s; - return (tok); - } - } while (sc != 0); - } - /* NOTREACHED */ + return strtok_r(s, delim, &lasts); } |
