[CRT]
authorJérôme Gardou <jerome.gardou@reactos.org>
Thu, 13 Dec 2012 16:32:17 +0000 (16:32 +0000)
committerJérôme Gardou <jerome.gardou@reactos.org>
Thu, 13 Dec 2012 16:32:17 +0000 (16:32 +0000)
 - fix isleadbyte
 - implement mbrlen
 - avoid race condition when creatong global ANSI locale

svn path=/trunk/; revision=57907

reactos/dll/win32/msvcrt/msvcrt.spec
reactos/lib/sdk/crt/locale/locale.c
reactos/lib/sdk/crt/mbstring/islead.c
reactos/lib/sdk/crt/mbstring/mbclen.c

index b8451fa..4c3131b 100644 (file)
 @ cdecl -i386 longjmp(ptr long)
 @ cdecl malloc(long)
 @ cdecl mblen(ptr long)
 @ 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
 # stub mbrtowc
 # stub mbsdup_dbg
 # stub mbsrtowcs
index 0aebb4b..1c7f76f 100644 (file)
@@ -1483,6 +1483,9 @@ void __init_global_locale()
     unsigned i;
     
     LOCK_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;
     global_locale = MSVCRT__create_locale(0, "C");
     
     MSVCRT___lc_codepage = MSVCRT_locale->locinfo->lc_codepage;
index c471e7c..44c1f22 100644 (file)
@@ -6,6 +6,6 @@
  */
 int isleadbyte(int c)
 {
  */
 int isleadbyte(int c)
 {
-    return _isctype( c, _MLEAD );
+    return _isctype( c, _LEADBYTE );
 
 }
 
 }
index e186674..364c6e9 100644 (file)
@@ -9,10 +9,8 @@
  *
  */
 
  *
  */
 
+#include <precomp.h>
 #include <mbstring.h>
 #include <mbstring.h>
-#include <stdlib.h>
-
-int isleadbyte(int byte);
 
 /*
  * @implemented
 
 /*
  * @implemented
@@ -40,3 +38,33 @@ int mblen( const char *str, size_t size )
   }
   return 0;
 }
   }
   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;
+}
+