Commit 2ec3b961 authored by Alexandre Julliard's avatar Alexandre Julliard

msvcrt: Make strtok and wcstok thread-safe by using the per-thread data.

parent f9e5b0f5
......@@ -93,7 +93,9 @@ extern DWORD msvcrt_tls_index;
struct __thread_data {
int thread_errno;
unsigned long thread_doserrno;
char *strtok_next; /* next ptr for strtok() */
unsigned char *mbstok_next; /* next ptr for mbstok() */
MSVCRT_wchar_t *wcstok_next; /* next ptr for wcstok() */
char *efcvt_buffer; /* buffer for ecvt/fcvt */
char *asctime_buffer; /* buffer for asctime */
MSVCRT_wchar_t *wasctime_buffer; /* buffer for wasctime */
......
......@@ -714,7 +714,7 @@
@ cdecl strspn(str str)
@ cdecl strstr(str str)
@ cdecl strtod(str ptr)
@ cdecl strtok(str str)
@ cdecl strtok(str str) MSVCRT_strtok
@ cdecl strtol(str ptr long)
@ cdecl strtoul(str ptr long)
@ cdecl strxfrm(ptr str long)
......@@ -754,7 +754,7 @@
@ cdecl wcsspn(wstr wstr) ntdll.wcsspn
@ cdecl wcsstr(wstr wstr) ntdll.wcsstr
@ cdecl wcstod(wstr ptr) MSVCRT_wcstod
@ cdecl wcstok(wstr wstr) ntdll.wcstok
@ cdecl wcstok(wstr wstr) MSVCRT_wcstok
@ cdecl wcstol(wstr ptr long) ntdll.wcstol
@ cdecl wcstombs(ptr ptr long) ntdll.wcstombs
@ cdecl wcstoul(wstr ptr long) ntdll.wcstoul
......
......@@ -97,6 +97,27 @@ char* _strset(char* str, int value)
}
/*********************************************************************
* strtok (MSVCRT.@)
*/
char *MSVCRT_strtok( char *str, const char *delim )
{
thread_data_t *data = msvcrt_get_thread_data();
char *ret;
if (!str)
if (!(str = data->strtok_next)) return NULL;
while (*str && strchr( delim, *str )) str++;
if (!*str) return NULL;
ret = str++;
while (*str && !strchr( delim, *str )) str++;
if (*str) *str++ = 0;
data->strtok_next = str;
return ret;
}
/*********************************************************************
* _swab (MSVCRT.@)
*/
void MSVCRT__swab(char* src, char* dst, int len)
......
......@@ -825,6 +825,27 @@ MSVCRT_wchar_t* MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t*
}
/*********************************************************************
* wcstok (MSVCRT.@)
*/
MSVCRT_wchar_t *MSVCRT_wcstok( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *delim )
{
thread_data_t *data = msvcrt_get_thread_data();
MSVCRT_wchar_t *ret;
if (!str)
if (!(str = data->wcstok_next)) return NULL;
while (*str && strchrW( delim, *str )) str++;
if (!*str) return NULL;
ret = str++;
while (*str && !strchrW( delim, *str )) str++;
if (*str) *str++ = 0;
data->wcstok_next = str;
return ret;
}
/*********************************************************************
* wctomb (MSVCRT.@)
*/
INT MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment