src/stdlib/SDL_iconv.c
changeset 2143 e906da4414a3
parent 2142 ca80c942e69c
child 2182 cc2597da0840
     1.1 --- a/src/stdlib/SDL_iconv.c	Wed Jul 04 07:08:16 2007 +0000
     1.2 +++ b/src/stdlib/SDL_iconv.c	Wed Jul 04 08:01:04 2007 +0000
     1.3 @@ -773,6 +773,27 @@
     1.4  
     1.5  #endif /* !HAVE_ICONV */
     1.6  
     1.7 +static const char *
     1.8 +getlocale()
     1.9 +{
    1.10 +    const char *lang;
    1.11 +
    1.12 +    lang = SDL_getenv("LC_ALL");
    1.13 +    if (!lang) {
    1.14 +        lang = SDL_getenv("LC_CTYPE");
    1.15 +    }
    1.16 +    if (!lang) {
    1.17 +        lang = SDL_getenv("LC_MESSAGES");
    1.18 +    }
    1.19 +    if (!lang) {
    1.20 +        lang = SDL_getenv("LANG");
    1.21 +    }
    1.22 +    if (!lang || SDL_strcmp(lang, "C") == 0) {
    1.23 +        lang = "ASCII";
    1.24 +    }
    1.25 +    return lang;
    1.26 +}
    1.27 +
    1.28  char *
    1.29  SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
    1.30                   size_t inbytesleft)
    1.31 @@ -784,6 +805,12 @@
    1.32      size_t outbytesleft;
    1.33      size_t retCode = 0;
    1.34  
    1.35 +    if (!fromcode || !*fromcode) {
    1.36 +        fromcode = getlocale();
    1.37 +    }
    1.38 +    if (!tocode || !*tocode) {
    1.39 +        tocode = getlocale();
    1.40 +    }
    1.41      cd = SDL_iconv_open(tocode, fromcode);
    1.42      if (cd == (SDL_iconv_t) - 1) {
    1.43          return NULL;