diff --git a/programs/develop/ktcc/trunk/libc.obj/include/string.h b/programs/develop/ktcc/trunk/libc.obj/include/string.h index 5f36de123..76618c84e 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/string.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/string.h @@ -32,6 +32,7 @@ DLLAPI char* strrchr(const char* s, int c); DLLAPI size_t strspn(const char* s1, const char* s2); DLLAPI char* strstr(const char* s1, const char* s2); DLLAPI char* strtok(char* s1, const char* s2); +DLLAPI char* strtok_r(char* s1, const char* s2, char** saveptr); DLLAPI char* strerror(int errnum); DLLAPI size_t strlen(const char* s); DLLAPI char* strrev(char* str); diff --git a/programs/develop/ktcc/trunk/libc.obj/source/libc.c b/programs/develop/ktcc/trunk/libc.obj/source/libc.c index 5f1123eca..748483014 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/libc.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/libc.c @@ -203,6 +203,7 @@ ksys_dll_t EXPORTS[] = { { "strspn", &strspn }, { "strstr", &strstr }, { "strtok", &strtok }, + { "strtok_r", &strtok_r }, { "strxfrm", &strxfrm }, { "strpbrk", &strpbrk }, { "__errno", &__errno }, diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c index 84c39df9a..7d2330951 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c @@ -1,14 +1,12 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include -char* strtok(char* s, const char* delim) +char* strtok_r(char* s, const char* delim, char** last) { - const char* spanp; + char *spanp, *tok; int c, sc; - char* tok; - static char* last; - if (s == NULL && (s = last) == NULL) + if (s == NULL && (s = *last) == NULL) return (NULL); /* @@ -16,13 +14,13 @@ char* strtok(char* s, const char* delim) */ cont: c = *s++; - for (spanp = delim; (sc = *spanp++) != 0;) { + for (spanp = (char*)delim; (sc = *spanp++) != 0;) { if (c == sc) goto cont; } if (c == 0) { /* no non-delimiter characters */ - last = NULL; + *last = NULL; return (NULL); } tok = s - 1; @@ -33,17 +31,24 @@ cont: */ for (;;) { c = *s++; - spanp = delim; + spanp = (char*)delim; do { if ((sc = *spanp++) == c) { if (c == 0) s = NULL; else - s[-1] = 0; - last = s; + s[-1] = '\0'; + *last = s; return (tok); } } while (sc != 0); } /* NOTREACHED */ } + +char *strtok(char *s, const char *delim) +{ + static char *last; + + return (strtok_r(s, delim, &last)); +}