diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 1999-11-09 11:19:47 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 1999-11-09 11:19:47 +0000 |
commit | 3e415b576cf8e06454cdb4069c2727b17460102f (patch) | |
tree | acaa7b9f2d1d3afccee0b00e9c26777725d9692e /lib/libc | |
parent | 773e33a81bb0d8f0adc9a147f29b1c49438718f8 (diff) |
Implement strtok_r.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/string/strtok.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/libc/string/strtok.c b/lib/libc/string/strtok.c index 2fce04c3ad9..d925dc75d03 100644 --- a/lib/libc/string/strtok.c +++ b/lib/libc/string/strtok.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: strtok.c,v 1.2 1996/08/19 08:34:28 tholo Exp $"; +static char *rcsid = "$OpenBSD: strtok.c,v 1.3 1999/11/09 11:19:46 art Exp $"; #endif /* LIBC_SCCS and not lint */ #include <string.h> @@ -42,13 +42,23 @@ strtok(s, delim) register char *s; register const char *delim; { + static char *last; + + return strtok_r(s, delim, &last); +} + +char * +strtok_r(s, delim, last) + register char *s; + register const char *delim; + char **last; +{ register char *spanp; register int c, sc; char *tok; - static char *last; - if (s == NULL && (s = last) == NULL) + if (s == NULL && (s = *last) == NULL) return (NULL); /* @@ -62,7 +72,7 @@ cont: } if (c == 0) { /* no non-delimiter characters */ - last = NULL; + *last = NULL; return (NULL); } tok = s - 1; @@ -80,7 +90,7 @@ cont: s = NULL; else s[-1] = 0; - last = s; + *last = s; return (tok); } } while (sc != 0); |