Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merged Ryan's patch from revision 3238 in SDL 1.2
  • Loading branch information
slouken committed Jul 12, 2007
1 parent 3f8edfe commit e8f09b5
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/stdlib/SDL_iconv.c
Expand Up @@ -137,9 +137,10 @@ static struct
};

static const char *
getlocale()
getlocale(char *buffer, size_t bufsize)
{
const char *lang;
char *ptr;

lang = SDL_getenv("LC_ALL");
if (!lang) {
Expand All @@ -154,7 +155,20 @@ getlocale()
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
Expand All @@ -163,12 +177,14 @@ SDL_iconv_open(const char *tocode, const char *fromcode)
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) {
Expand Down

0 comments on commit e8f09b5

Please sign in to comment.