summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-03-21 16:33:34 +0100
committerStephan Bergmann <sbergman@redhat.com>2017-03-21 16:33:34 +0100
commit17ca47da257d7633e816a5a1b935783d1f089b9f (patch)
tree61040bb0779c50426af6f02da17283078f9cd32e /sal
parent66ac0e2c0fd6068688b304abcc03399818eaed03 (diff)
On Linux etc., obtain locale value from env vars instead of setlocale
setlocale has the drawbacks that it is racy and that it sets global state, so better avoid it. The way LC_ALL, LC_CTYPE, LANG are honoured is as suggested by SUSv4, then falling back to "C". Change-Id: I606ecc01d37a0a9067a90e6dcce098009094493c
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/nlsupport.cxx27
1 files changed, 11 insertions, 16 deletions
diff --git a/sal/osl/unx/nlsupport.cxx b/sal/osl/unx/nlsupport.cxx
index 97c6c62cdc99..61090d969011 100644
--- a/sal/osl/unx/nlsupport.cxx
+++ b/sal/osl/unx/nlsupport.cxx
@@ -643,22 +643,17 @@ rtl_TextEncoding osl_getTextEncodingFromLocale( rtl_Locale * pLocale )
void imp_getProcessLocale( rtl_Locale ** ppLocale )
{
- char * locale;
-
- /* basic thread safeness */
- pthread_mutex_lock( &aLocalMutex );
-
- /* set the locale defined by the env vars */
- locale = setlocale( LC_CTYPE, "" );
-
- /* fallback to the current locale */
- if( nullptr == locale )
- locale = setlocale( LC_CTYPE, nullptr );
-
- /* return the LC_CTYPE locale */
- *ppLocale = parse_locale( locale );
-
- pthread_mutex_unlock( &aLocalMutex );
+ char const * locale = getenv("LC_ALL");
+ if (locale == nullptr || *locale == '\0') {
+ locale = getenv("LC_CTYPE");
+ if (locale == nullptr || *locale == '\0') {
+ locale = getenv("LANG");
+ if (locale == nullptr || *locale == '\0') {
+ locale = "C";
+ }
+ }
+ }
+ *ppLocale = parse_locale(locale);
}
/*****************************************************************************