summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-03-23 10:48:54 +0100
committerStephan Bergmann <sbergman@redhat.com>2017-03-23 10:48:54 +0100
commit77c2b0a33eeeeaa5fa5f672d9236405247ebcfa0 (patch)
treeb59c83c7f252d91f06e720a6c525c70c8c4ba727 /shell
parented76d1d3504c92bff6bb3e6417e4440572fcd959 (diff)
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
Diffstat (limited to 'shell')
-rw-r--r--shell/source/backends/localebe/localebackend.cxx27
1 files changed, 14 insertions, 13 deletions
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
}