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