msvcrt: Make strtok and wcstok thread-safe by using the per-thread data.
This commit is contained in:
parent
f9e5b0f5f0
commit
2ec3b96135
|
@ -93,7 +93,9 @@ extern DWORD msvcrt_tls_index;
|
||||||
struct __thread_data {
|
struct __thread_data {
|
||||||
int thread_errno;
|
int thread_errno;
|
||||||
unsigned long thread_doserrno;
|
unsigned long thread_doserrno;
|
||||||
|
char *strtok_next; /* next ptr for strtok() */
|
||||||
unsigned char *mbstok_next; /* next ptr for mbstok() */
|
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 *efcvt_buffer; /* buffer for ecvt/fcvt */
|
||||||
char *asctime_buffer; /* buffer for asctime */
|
char *asctime_buffer; /* buffer for asctime */
|
||||||
MSVCRT_wchar_t *wasctime_buffer; /* buffer for wasctime */
|
MSVCRT_wchar_t *wasctime_buffer; /* buffer for wasctime */
|
||||||
|
|
|
@ -714,7 +714,7 @@
|
||||||
@ cdecl strspn(str str)
|
@ cdecl strspn(str str)
|
||||||
@ cdecl strstr(str str)
|
@ cdecl strstr(str str)
|
||||||
@ cdecl strtod(str ptr)
|
@ cdecl strtod(str ptr)
|
||||||
@ cdecl strtok(str str)
|
@ cdecl strtok(str str) MSVCRT_strtok
|
||||||
@ cdecl strtol(str ptr long)
|
@ cdecl strtol(str ptr long)
|
||||||
@ cdecl strtoul(str ptr long)
|
@ cdecl strtoul(str ptr long)
|
||||||
@ cdecl strxfrm(ptr str long)
|
@ cdecl strxfrm(ptr str long)
|
||||||
|
@ -754,7 +754,7 @@
|
||||||
@ cdecl wcsspn(wstr wstr) ntdll.wcsspn
|
@ cdecl wcsspn(wstr wstr) ntdll.wcsspn
|
||||||
@ cdecl wcsstr(wstr wstr) ntdll.wcsstr
|
@ cdecl wcsstr(wstr wstr) ntdll.wcsstr
|
||||||
@ cdecl wcstod(wstr ptr) MSVCRT_wcstod
|
@ 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 wcstol(wstr ptr long) ntdll.wcstol
|
||||||
@ cdecl wcstombs(ptr ptr long) ntdll.wcstombs
|
@ cdecl wcstombs(ptr ptr long) ntdll.wcstombs
|
||||||
@ cdecl wcstoul(wstr ptr long) ntdll.wcstoul
|
@ cdecl wcstoul(wstr ptr long) ntdll.wcstoul
|
||||||
|
|
|
@ -96,6 +96,27 @@ char* _strset(char* str, int value)
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* 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.@)
|
* _swab (MSVCRT.@)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -824,6 +824,27 @@ MSVCRT_wchar_t* MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t*
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* 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.@)
|
* wctomb (MSVCRT.@)
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue