kernel32: Add support for detecting the user locale preference from the system on Mac OS X.

Robert Shearman rob at codeweavers.com
Mon Oct 9 07:51:33 CDT 2006


---
  dlls/kernel32/locale.c |   40 ++++++++++++++++++++++++++++++----------
  1 files changed, 30 insertions(+), 10 deletions(-)
-------------- next part --------------
diff --git a/dlls/kernel32/locale.c b/dlls/kernel32/locale.c
index 7d33a8f..9e66058 100644
--- a/dlls/kernel32/locale.c
+++ b/dlls/kernel32/locale.c
@@ -31,6 +31,11 @@ #include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
 
+#ifdef __APPLE__
+# include <CoreFoundation/CFLocale.h>
+# include <CoreFoundation/CFString.h>
+#endif
+
 #include "ntstatus.h"
 #define WIN32_NO_STATUS
 #include "windef.h"
@@ -503,17 +508,32 @@ static int charset_cmp( const void *name
  */
 static LCID get_env_lcid( UINT *unix_cp, const char *env_str )
 {
-    char *buf, *lang,*country,*charset,*dialect,*next;
+    char *buf,*lang,*country,*charset,*dialect,*next;
+    const char *lang_env;
     LCID ret = 0;
-
-    if (((lang = getenv( "LC_ALL" )) && *lang) ||
-        (env_str && (lang = getenv( env_str )) && *lang) ||
-        ((lang = getenv( "LANG" )) && *lang))
-    {
-        if (!strcmp(lang,"POSIX") || !strcmp(lang,"C")) goto done;
-
-        buf = RtlAllocateHeap( GetProcessHeap(), 0, strlen(lang) + 1 );
-        strcpy( buf, lang );
+    char user_locale[50] = { 0 };
+#ifdef __APPLE__
+    CFLocaleRef user_locale_ref = CFLocaleCopyCurrent();
+    CFStringRef user_locale_string_ref = CFLocaleGetIdentifier(user_locale_ref);
+
+    CFStringGetCString(user_locale_string_ref, user_locale,
+                       sizeof(user_locale) - strlen(".utf8"),
+                       kCFStringEncodingUTF8);
+    CFRelease(user_locale_ref);
+    /* charset on Mac OS X is always UTF8 */
+    if (user_locale[0])
+        strcat(user_locale, ".utf8");
+#endif
+
+    if (((lang_env = getenv( "LC_ALL" )) && *lang_env) ||
+        (env_str && (lang_env = getenv( env_str )) && *lang_env) ||
+        ((lang_env = getenv( "LANG" )) && *lang_env) ||
+        ((lang_env = user_locale) && *lang_env))
+    {
+        if (!strcmp(lang_env,"POSIX") || !strcmp(lang_env,"C")) goto done;
+
+        buf = RtlAllocateHeap( GetProcessHeap(), 0, strlen(lang_env) + 1 );
+        strcpy( buf, lang_env );
         lang=buf;
 
         do {


More information about the wine-patches mailing list