From bb19fe703a2711ddad1b381498fea2d703b92d91 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 31 Jan 2012 21:06:52 -0800 Subject: [PATCH] Fixup wsetlocale to use wcstring --- builtin.h | 2 +- common.cpp | 17 ++++------------- common.h | 2 +- env.cpp | 9 ++++----- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/builtin.h b/builtin.h index 5b48fe845..1083149de 100644 --- a/builtin.h +++ b/builtin.h @@ -157,7 +157,7 @@ void builtin_pop_io(parser_t &parser); /** - Return a one-line description of the specified builtin + Return a one-line description of the specified builtin. This is usually a truly constant string, so we should not wrap it in a wcstring. */ const wchar_t *builtin_get_desc( const wchar_t *b ); diff --git a/common.cpp b/common.cpp index 72d662396..6564a7ac5 100644 --- a/common.cpp +++ b/common.cpp @@ -573,12 +573,11 @@ wchar_t *quote_end( const wchar_t *pos ) } -const wchar_t *wsetlocale(int category, const wchar_t *locale) +wcstring wsetlocale(int category, const wchar_t *locale) { char *lang = locale?wcs2str( locale ):0; char * res = setlocale(category,lang); - free( lang ); /* @@ -588,17 +587,9 @@ const wchar_t *wsetlocale(int category, const wchar_t *locale) ellipsis_char = (strstr( ctype, ".UTF")||strstr( ctype, ".utf") )?L'\x2026':L'$'; if( !res ) - return 0; - - if( !setlocale_buff ) - { - setlocale_buff = sb_halloc( global_context); - } - - sb_clear( setlocale_buff ); - sb_printf( setlocale_buff, L"%s", res ); - - return (wchar_t *)setlocale_buff->buff; + return wcstring(); + else + return format_string(L"%s", res); } bool contains_internal( const wchar_t *a, ... ) diff --git a/common.h b/common.h index 66596f3ac..03114addf 100644 --- a/common.h +++ b/common.h @@ -434,7 +434,7 @@ void error_reset(); the user is using a Unicode character set, and if so, use the unicode ellipsis character as ellipsis, instead of '$'. */ -const wchar_t *wsetlocale( int category, const wchar_t *locale ); +wcstring wsetlocale( int category, const wchar_t *locale ); /** Checks if \c needle is included in the list of strings specified. A warning is printed if needle is zero. diff --git a/env.cpp b/env.cpp index d6c294a95..10ce3d8a4 100644 --- a/env.cpp +++ b/env.cpp @@ -296,7 +296,7 @@ static void handle_locale() { const env_var_t lc_all = env_get_string( L"LC_ALL" ); int i; - wchar_t *old = wcsdup(wsetlocale( LC_MESSAGES, NULL )); + const wcstring old_locale = wsetlocale( LC_MESSAGES, NULL ); /* Array of locale constants corresponding to the local variable names defined in locale_variable @@ -337,7 +337,8 @@ static void handle_locale() } } - if( wcscmp( wsetlocale( LC_MESSAGES, NULL ), old ) != 0 ) + const wcstring new_locale = wsetlocale(LC_MESSAGES, NULL); + if( old_locale != new_locale ) { /* @@ -357,9 +358,7 @@ static void handle_locale() { debug( 0, _(L"Changing language to English") ); } - } - free( old ); - + } }