mirror of
https://github.com/reactos/reactos.git
synced 2025-01-02 12:32:47 +00:00
[CRT]
- fix isleadbyte - implement mbrlen - avoid race condition when creatong global ANSI locale svn path=/trunk/; revision=57907
This commit is contained in:
parent
5a862da366
commit
ac12febb5b
4 changed files with 36 additions and 5 deletions
|
@ -1266,7 +1266,7 @@
|
|||
@ cdecl -i386 longjmp(ptr long)
|
||||
@ cdecl malloc(long)
|
||||
@ cdecl mblen(ptr long)
|
||||
# stub mbrlen
|
||||
@ cdecl mbrlen(ptr long ptr)
|
||||
# stub mbrtowc
|
||||
# stub mbsdup_dbg
|
||||
# stub mbsrtowcs
|
||||
|
|
|
@ -1483,6 +1483,9 @@ void __init_global_locale()
|
|||
unsigned i;
|
||||
|
||||
LOCK_LOCALE;
|
||||
/* Someone created it before us */
|
||||
if(global_locale)
|
||||
return;
|
||||
global_locale = MSVCRT__create_locale(0, "C");
|
||||
|
||||
MSVCRT___lc_codepage = MSVCRT_locale->locinfo->lc_codepage;
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
*/
|
||||
int isleadbyte(int c)
|
||||
{
|
||||
return _isctype( c, _MLEAD );
|
||||
return _isctype( c, _LEADBYTE );
|
||||
|
||||
}
|
||||
|
|
|
@ -9,10 +9,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
#include <mbstring.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int isleadbyte(int byte);
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
|
@ -40,3 +38,33 @@ int mblen( const char *str, size_t size )
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t __cdecl mbrlen(const char *str, size_t len, mbstate_t *state)
|
||||
{
|
||||
mbstate_t s = (state ? *state : 0);
|
||||
size_t ret;
|
||||
|
||||
if(!len || !str || !*str)
|
||||
return 0;
|
||||
|
||||
if(get_locinfo()->mb_cur_max == 1) {
|
||||
return 1;
|
||||
}else if(!s && isleadbyte((unsigned char)*str)) {
|
||||
if(len == 1) {
|
||||
s = (unsigned char)*str;
|
||||
ret = -2;
|
||||
}else {
|
||||
ret = 2;
|
||||
}
|
||||
}else if(!s) {
|
||||
ret = 1;
|
||||
}else {
|
||||
s = 0;
|
||||
ret = 2;
|
||||
}
|
||||
|
||||
if(state)
|
||||
*state = s;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue