Fixup wsetlocale to use wcstring

This commit is contained in:
ridiculousfish 2012-01-31 21:06:52 -08:00
parent eef1e3e77e
commit bb19fe703a
4 changed files with 10 additions and 20 deletions

View File

@ -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 );

View File

@ -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, ... )

View File

@ -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.

View File

@ -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 );
}
}