libc.obj: add strtok_r
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -203,6 +203,7 @@ ksys_dll_t EXPORTS[] = {
|
||||
{ "strspn", &strspn },
|
||||
{ "strstr", &strstr },
|
||||
{ "strtok", &strtok },
|
||||
{ "strtok_r", &strtok_r },
|
||||
{ "strxfrm", &strxfrm },
|
||||
{ "strpbrk", &strpbrk },
|
||||
{ "__errno", &__errno },
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <string.h>
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user