Piotr Caban : msvcrt: Add _wsetlocale implementation.

Alexandre Julliard julliard at winehq.org
Thu Aug 29 13:18:14 CDT 2013


Module: wine
Branch: master
Commit: 33d697c001049b6c20203d3332299dfc4c5af6c9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=33d697c001049b6c20203d3332299dfc4c5af6c9

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Thu Aug 29 12:07:03 2013 +0200

msvcrt: Add _wsetlocale implementation.

---

 dlls/msvcrt/locale.c |   48 ++++++++++++++++++++++++++++++++++--------------
 dlls/msvcrt/msvcrt.h |    1 +
 2 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c
index 14ccd0a..4e8467a 100644
--- a/dlls/msvcrt/locale.c
+++ b/dlls/msvcrt/locale.c
@@ -407,20 +407,6 @@ static inline char* construct_lc_all(MSVCRT_pthreadlocinfo locinfo) {
 
 
 /*********************************************************************
- *		wsetlocale (MSVCRT.@)
- */
-MSVCRT_wchar_t* CDECL MSVCRT__wsetlocale(int category, const MSVCRT_wchar_t* locale)
-{
-  static MSVCRT_wchar_t fake[] = {
-    'E','n','g','l','i','s','h','_','U','n','i','t','e','d',' ',
-    'S','t','a','t','e','s','.','1','2','5','2',0 };
-
-  FIXME("%d %s\n", category, debugstr_w(locale));
-
-  return fake;
-}
-
-/*********************************************************************
  *		_Getdays (MSVCRT.@)
  */
 char* CDECL _Getdays(void)
@@ -1435,6 +1421,40 @@ char* CDECL MSVCRT_setlocale(int category, const char* locale)
     return locinfo->lc_category[category].locale;
 }
 
+/*********************************************************************
+ *		_wsetlocale (MSVCRT.@)
+ */
+MSVCRT_wchar_t* CDECL MSVCRT__wsetlocale(int category, const MSVCRT_wchar_t* wlocale)
+{
+    static MSVCRT_wchar_t current_lc_all[MAX_LOCALE_LENGTH];
+
+    char *locale = NULL;
+    const char *ret;
+    MSVCRT_size_t len;
+
+    if(wlocale) {
+        len = MSVCRT_wcstombs(NULL, wlocale, 0);
+        if(len == -1)
+            return NULL;
+
+        locale = MSVCRT_malloc(++len);
+        if(!locale)
+            return NULL;
+
+        MSVCRT_wcstombs(locale, wlocale, len);
+    }
+
+    LOCK_LOCALE;
+    ret = MSVCRT_setlocale(category, locale);
+    MSVCRT_free(locale);
+
+    if(ret && MSVCRT_mbstowcs(current_lc_all, ret, MAX_LOCALE_LENGTH)==-1)
+        ret = NULL;
+
+    UNLOCK_LOCALE;
+    return ret ? current_lc_all : NULL;
+}
+
 /* _configthreadlocale - not exported in native msvcrt */
 int CDECL _configthreadlocale(int type)
 {
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index 35e9c7d..98922af 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -953,6 +953,7 @@ int            __cdecl _ismbclegal(unsigned int c);
 int            __cdecl _ismbstrail(const unsigned char* start, const unsigned char* str);
 int            __cdecl MSVCRT_mbtowc(MSVCRT_wchar_t*,const char*,MSVCRT_size_t);
 MSVCRT_size_t  __cdecl MSVCRT_mbstowcs(MSVCRT_wchar_t*,const char*,MSVCRT_size_t);
+MSVCRT_size_t  __cdecl MSVCRT_wcstombs(char*,const MSVCRT_wchar_t*,MSVCRT_size_t);
 MSVCRT_intptr_t __cdecl MSVCRT__spawnve(int,const char*,const char* const *,const char* const *);
 MSVCRT_intptr_t __cdecl MSVRT__spawnvpe(int,const char*,const char* const *,const char* const *);
 MSVCRT_intptr_t __cdecl MSVCRT__wspawnve(int,const MSVCRT_wchar_t*,const MSVCRT_wchar_t* const *,const MSVCRT_wchar_t* const *);




More information about the wine-cvs mailing list