Mercurial > sdl-ios-xcode
changeset 2184:8f8516e79a13
Merged Ryan's patch from revision 3238 in SDL 1.2
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 12 Jul 2007 08:07:30 +0000 |
parents | 9f31740cad2e |
children | 2032348afed1 |
files | src/stdlib/SDL_iconv.c |
diffstat | 1 files changed, 20 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/stdlib/SDL_iconv.c Thu Jul 12 07:55:18 2007 +0000 +++ b/src/stdlib/SDL_iconv.c Thu Jul 12 08:07:30 2007 +0000 @@ -137,9 +137,10 @@ }; static const char * -getlocale() +getlocale(char *buffer, size_t bufsize) { const char *lang; + char *ptr; lang = SDL_getenv("LC_ALL"); if (!lang) { @@ -154,7 +155,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 @@ -163,12 +177,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) {