- fix isleadbyte
- implement mbrlen
- avoid race condition when creatong global ANSI locale
svn path=/trunk/; revision=57907
@ 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
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;
*/
int isleadbyte(int c)
{
- return _isctype( c, _MLEAD );
+ return _isctype( c, _LEADBYTE );
}
*
*/
+#include <precomp.h>
#include <mbstring.h>
-#include <stdlib.h>
-
-int isleadbyte(int byte);
/*
* @implemented
}
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;
+}
+