diff options
Diffstat (limited to 'src/lib/libc/string/strtok.c')
| -rw-r--r-- | src/lib/libc/string/strtok.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/lib/libc/string/strtok.c b/src/lib/libc/string/strtok.c index 2fce04c3ad..d925dc75d0 100644 --- a/src/lib/libc/string/strtok.c +++ b/src/lib/libc/string/strtok.c | |||
| @@ -32,7 +32,7 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | static char *rcsid = "$OpenBSD: strtok.c,v 1.2 1996/08/19 08:34:28 tholo Exp $"; | 35 | static char *rcsid = "$OpenBSD: strtok.c,v 1.3 1999/11/09 11:19:46 art Exp $"; |
| 36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 37 | 37 | ||
| 38 | #include <string.h> | 38 | #include <string.h> |
| @@ -42,13 +42,23 @@ strtok(s, delim) | |||
| 42 | register char *s; | 42 | register char *s; |
| 43 | register const char *delim; | 43 | register const char *delim; |
| 44 | { | 44 | { |
| 45 | static char *last; | ||
| 46 | |||
| 47 | return strtok_r(s, delim, &last); | ||
| 48 | } | ||
| 49 | |||
| 50 | char * | ||
| 51 | strtok_r(s, delim, last) | ||
| 52 | register char *s; | ||
| 53 | register const char *delim; | ||
| 54 | char **last; | ||
| 55 | { | ||
| 45 | register char *spanp; | 56 | register char *spanp; |
| 46 | register int c, sc; | 57 | register int c, sc; |
| 47 | char *tok; | 58 | char *tok; |
| 48 | static char *last; | ||
| 49 | 59 | ||
| 50 | 60 | ||
| 51 | if (s == NULL && (s = last) == NULL) | 61 | if (s == NULL && (s = *last) == NULL) |
| 52 | return (NULL); | 62 | return (NULL); |
| 53 | 63 | ||
| 54 | /* | 64 | /* |
| @@ -62,7 +72,7 @@ cont: | |||
| 62 | } | 72 | } |
| 63 | 73 | ||
| 64 | if (c == 0) { /* no non-delimiter characters */ | 74 | if (c == 0) { /* no non-delimiter characters */ |
| 65 | last = NULL; | 75 | *last = NULL; |
| 66 | return (NULL); | 76 | return (NULL); |
| 67 | } | 77 | } |
| 68 | tok = s - 1; | 78 | tok = s - 1; |
| @@ -80,7 +90,7 @@ cont: | |||
| 80 | s = NULL; | 90 | s = NULL; |
| 81 | else | 91 | else |
| 82 | s[-1] = 0; | 92 | s[-1] = 0; |
| 83 | last = s; | 93 | *last = s; |
| 84 | return (tok); | 94 | return (tok); |
| 85 | } | 95 | } |
| 86 | } while (sc != 0); | 96 | } while (sc != 0); |
