# HG changeset patch # User Sam Lantinga # Date 1184227450 0 # Node ID 6ed1fded55ffbc53211d513ec0b759d2a4de8980 # Parent 64bf737873a237068bb4be6483ef9d5791b1851e Ryan's fix is still good for the built-in version of iconv_open() diff -r 64bf737873a2 -r 6ed1fded55ff src/stdlib/SDL_iconv.c --- a/src/stdlib/SDL_iconv.c Thu Jul 12 07:47:29 2007 +0000 +++ b/src/stdlib/SDL_iconv.c Thu Jul 12 08:04:10 2007 +0000 @@ -131,9 +131,10 @@ { "UCS-4", ENCODING_UCS4 }, }; -static const char *getlocale() +static const char *getlocale(char *buffer, size_t bufsize) { const char *lang; + char *ptr; lang = SDL_getenv("LC_ALL"); if ( !lang ) { @@ -148,7 +149,20 @@ if ( !lang || !*lang || SDL_strcmp(lang, "C") == 0 ) { lang = "ASCII"; } - return lang; + + /* We need to trim down strings like "en_US.UTF-8@blah" to "UTF-8" */ + ptr = SDL_strchr(lang, '.'); + if (ptr != NULL) { + lang = ptr + 1; + } + + SDL_strlcpy(buffer, lang, bufsize); + ptr = SDL_strchr(buffer, '@'); + if (ptr != NULL) { + *ptr = '\0'; /* chop end of string. */ + } + + return buffer; } SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode) @@ -156,12 +170,14 @@ int src_fmt = ENCODING_UNKNOWN; int dst_fmt = ENCODING_UNKNOWN; int i; + char fromcode_buffer[64]; + char tocode_buffer[64]; if ( !fromcode || !*fromcode ) { - fromcode = getlocale(); + fromcode = getlocale(fromcode_buffer, sizeof(fromcode_buffer)); } if ( !tocode || !*tocode ) { - fromcode = getlocale(); + tocode = getlocale(tocode_buffer, sizeof(tocode_buffer)); } for ( i = 0; i < SDL_arraysize(encodings); ++i ) { if ( SDL_strcasecmp(fromcode, encodings[i].name) == 0 ) {