[Libreoffice-commits] core.git: sal/osl

Stephan Bergmann sbergman at redhat.com
Tue Mar 21 15:36:34 UTC 2017


 sal/osl/unx/nlsupport.cxx |   27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

New commits:
commit 17ca47da257d7633e816a5a1b935783d1f089b9f
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Mar 21 16:33:34 2017 +0100

    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

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);
 }
 
 /*****************************************************************************


More information about the Libreoffice-commits mailing list