diff options
author | 1999-11-09 11:19:46 +0000 | |
---|---|---|
committer | 1999-11-09 11:19:46 +0000 | |
commit | 72922f74f7d0e2b1dd369f12bd92a8b5961c4259 (patch) | |
tree | 6457de269849ef6d45798b0292a50e71718f0f92 /lib/libc/string | |
parent | Add OpenBSD tags. (diff) | |
download | wireguard-openbsd-72922f74f7d0e2b1dd369f12bd92a8b5961c4259.tar.xz wireguard-openbsd-72922f74f7d0e2b1dd369f12bd92a8b5961c4259.zip |
Implement strtok_r.
Diffstat (limited to 'lib/libc/string')
-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); |