Author: jgardou
Date: Thu Dec 13 16:32:17 2012
New Revision: 57907
URL:
http://svn.reactos.org/svn/reactos?rev=57907&view=rev
Log:
[CRT]
- fix isleadbyte
- implement mbrlen
- avoid race condition when creatong global ANSI locale
Modified:
trunk/reactos/dll/win32/msvcrt/msvcrt.spec
trunk/reactos/lib/sdk/crt/locale/locale.c
trunk/reactos/lib/sdk/crt/mbstring/islead.c
trunk/reactos/lib/sdk/crt/mbstring/mbclen.c
Modified: trunk/reactos/dll/win32/msvcrt/msvcrt.spec
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msvcrt/msvcrt.sp…
==============================================================================
--- trunk/reactos/dll/win32/msvcrt/msvcrt.spec [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msvcrt/msvcrt.spec [iso-8859-1] Thu Dec 13 16:32:17 2012
@@ -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
Modified: trunk/reactos/lib/sdk/crt/locale/locale.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/locale/locale.…
==============================================================================
--- trunk/reactos/lib/sdk/crt/locale/locale.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/locale/locale.c [iso-8859-1] Thu Dec 13 16:32:17 2012
@@ -1483,6 +1483,9 @@
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;
Modified: trunk/reactos/lib/sdk/crt/mbstring/islead.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/islea…
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/islead.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/islead.c [iso-8859-1] Thu Dec 13 16:32:17 2012
@@ -6,6 +6,6 @@
*/
int isleadbyte(int c)
{
- return _isctype( c, _MLEAD );
+ return _isctype( c, _LEADBYTE );
}
Modified: trunk/reactos/lib/sdk/crt/mbstring/mbclen.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/mbcle…
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/mbclen.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/mbclen.c [iso-8859-1] Thu Dec 13 16:32:17 2012
@@ -9,10 +9,8 @@
*
*/
+#include <precomp.h>
#include <mbstring.h>
-#include <stdlib.h>
-
-int isleadbyte(int byte);
/*
* @implemented
@@ -40,3 +38,33 @@
}
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;
+}
+