summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-11-23 16:58:11 +0100
committerStephan Bergmann <sbergman@redhat.com>2014-11-23 16:58:11 +0100
commit6e0e616f13c2bb2ce8493ac8442773c9bd78f5a0 (patch)
treece0eed2194f5344f62eb7d8dc716133ec3585130 /sal
parentb170c6d23d0845c55498c53863f43e5a72c7459c (diff)
Erm, setenv, not putenv
...so no need to leak an OString (and no need for a static char const *locale, as osl_getProcessLocale calling _imp_getProcessLocale already takes care about that). Change-Id: Ic831415596fe44335a6b12b5d884e781368676b8
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/nlsupport.cxx47
1 files changed, 15 insertions, 32 deletions
diff --git a/sal/osl/unx/nlsupport.cxx b/sal/osl/unx/nlsupport.cxx
index 8283619bc1f9..4afccaa6e803 100644
--- a/sal/osl/unx/nlsupport.cxx
+++ b/sal/osl/unx/nlsupport.cxx
@@ -846,55 +846,38 @@ rtl_TextEncoding osl_getTextEncodingFromLocale( rtl_Locale * pLocale )
void _imp_getProcessLocale( rtl_Locale ** ppLocale )
{
- static char const *locale = NULL;
-
- /* basic thread safeness */
-// pthread_mutex_lock( &aLocalMutex );
-
- /* Only fetch the locale once and cache it */
- if ( NULL == locale )
+ rtl::OUString loc16(macosx_getLocale());
+ rtl::OString locale;
+ if (!loc16.convertToString(
+ &locale, RTL_TEXTENCODING_UTF8,
+ (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
+ | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
{
- rtl::OUString loc16(macosx_getLocale());
- rtl::OString loc8;
- if (loc16.convertToString(
- &loc8, RTL_TEXTENCODING_UTF8,
- (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
- | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
- {
- rtl_string_acquire(loc8.pData); // leak, for setenv
- locale = loc8.getStr();
- }
+ SAL_INFO("sal.osl", "Cannot convert \"" << loc16 << "\" to UTF-8");
}
/* handle the case where OS specific method of finding locale fails */
- if ( NULL == locale )
+ if ( locale.isEmpty() )
{
/* simulate behavior of setlocale */
locale = getenv( "LC_ALL" );
- if( NULL == locale )
+ if( locale.isEmpty() )
locale = getenv( "LC_CTYPE" );
- if( NULL == locale )
+ if( locale.isEmpty() )
locale = getenv( "LANG" );
- if( NULL == locale )
+ if( locale.isEmpty() )
locale = "C";
}
/* return the locale */
- *ppLocale = _parse_locale( locale );
-
- setenv( "LC_ALL", locale, 1);
- setenv("LC_CTYPE", locale, 1 );
- setenv("LANG", locale, 1 );
-
-#if OSL_DEBUG_LEVEL > 1
- OSL_TRACE("_imp_getProcessLocale() returning %s as current locale.", locale );
-#endif
-
-// pthread_mutex_unlock( &aLocalMutex );
+ *ppLocale = _parse_locale( locale.getStr() );
+ setenv( "LC_ALL", locale.getStr(), 1);
+ setenv("LC_CTYPE", locale.getStr(), 1 );
+ setenv("LANG", locale.getStr(), 1 );
}
#else
/*****************************************************************************