[Libreoffice-commits] core.git: shell/source

Stephan Bergmann sbergman at redhat.com
Thu Mar 23 09:50:04 UTC 2017


 shell/source/backends/localebe/localebackend.cxx |   27 +++++++++++------------
 1 file changed, 14 insertions(+), 13 deletions(-)

New commits:
commit 77c2b0a33eeeeaa5fa5f672d9236405247ebcfa0
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Mar 23 10:48:54 2017 +0100

    In Unix ImplGetLocale, read env vars instead of calling setlocale
    
    ...to avoid the general problems with the latter (MT issues; changing global
    state)
    
    Change-Id: I21eb129b7e1422089b3449763f64f461371ffff1

diff --git a/shell/source/backends/localebe/localebackend.cxx b/shell/source/backends/localebe/localebackend.cxx
index 36d1bf456667..8f518e46de6a 100644
--- a/shell/source/backends/localebe/localebackend.cxx
+++ b/shell/source/backends/localebe/localebackend.cxx
@@ -154,21 +154,22 @@ namespace /* private */
 #else
 
 #include <rtl/ustrbuf.hxx>
-#include <locale.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
 
-/*
- * Note: setlocale is not at all thread safe, so is this code. It could
- * especially interfere with the stuff VCL is doing, so make sure this
- * is called from the main thread only.
- */
-
-static OUString ImplGetLocale(int category)
+static OUString ImplGetLocale(char const * category)
 {
-    const char *locale = setlocale(category, "");
+    const char *locale = std::getenv("LC_ALL");
+    if (locale == nullptr || *locale == '\0') {
+        locale = std::getenv(category);
+        if (locale == nullptr || *locale == '\0') {
+            locale = std::getenv("LANG");
+        }
+    }
 
     // Return "en-US" for C locales
-    if( (locale == nullptr) || ( locale[0] == 'C' && locale[1] == '\0' ) )
+    if( (locale == nullptr) || *locale == '\0' || std::strcmp(locale, "C") == 0
+        || std::strcmp(locale, "POSIX") == 0 )
         return OUString( "en-US"  );
 
 
@@ -227,7 +228,7 @@ OUString LocaleBackend::getLocale()
 #elif defined (MACOSX)
     return ImplGetLocale("AppleLocale");
 #else
-    return ImplGetLocale(LC_CTYPE);
+    return ImplGetLocale("LC_CTYPE");
 #endif
 }
 
@@ -239,7 +240,7 @@ OUString LocaleBackend::getUILocale()
 #elif defined(MACOSX)
     return ImplGetLocale("AppleLanguages");
 #else
-    return ImplGetLocale(LC_MESSAGES);
+    return ImplGetLocale("LC_MESSAGES");
 #endif
 }
 


More information about the Libreoffice-commits mailing list