Merged Ryan's patch from revision 3238 in SDL 1.2
authorSam Lantinga <slouken@libsdl.org>
Thu, 12 Jul 2007 08:07:30 +0000
changeset 21848f8516e79a13
parent 2183 9f31740cad2e
child 2185 2032348afed1
Merged Ryan's patch from revision 3238 in SDL 1.2
src/stdlib/SDL_iconv.c
     1.1 --- a/src/stdlib/SDL_iconv.c	Thu Jul 12 07:55:18 2007 +0000
     1.2 +++ b/src/stdlib/SDL_iconv.c	Thu Jul 12 08:07:30 2007 +0000
     1.3 @@ -137,9 +137,10 @@
     1.4  };
     1.5  
     1.6  static const char *
     1.7 -getlocale()
     1.8 +getlocale(char *buffer, size_t bufsize)
     1.9  {
    1.10      const char *lang;
    1.11 +    char *ptr;
    1.12  
    1.13      lang = SDL_getenv("LC_ALL");
    1.14      if (!lang) {
    1.15 @@ -154,7 +155,20 @@
    1.16      if (!lang || !*lang || SDL_strcmp(lang, "C") == 0) {
    1.17          lang = "ASCII";
    1.18      }
    1.19 -    return lang;
    1.20 +
    1.21 +    /* We need to trim down strings like "en_US.UTF-8@blah" to "UTF-8" */
    1.22 +    ptr = SDL_strchr(lang, '.');
    1.23 +    if (ptr != NULL) {
    1.24 +        lang = ptr + 1;
    1.25 +    }
    1.26 +
    1.27 +    SDL_strlcpy(buffer, lang, bufsize);
    1.28 +    ptr = SDL_strchr(buffer, '@');
    1.29 +    if (ptr != NULL) {
    1.30 +        *ptr = '\0';            /* chop end of string. */
    1.31 +    }
    1.32 +
    1.33 +    return buffer;
    1.34  }
    1.35  
    1.36  SDL_iconv_t
    1.37 @@ -163,12 +177,14 @@
    1.38      int src_fmt = ENCODING_UNKNOWN;
    1.39      int dst_fmt = ENCODING_UNKNOWN;
    1.40      int i;
    1.41 +    char fromcode_buffer[64];
    1.42 +    char tocode_buffer[64];
    1.43  
    1.44      if (!fromcode || !*fromcode) {
    1.45 -        fromcode = getlocale();
    1.46 +        fromcode = getlocale(fromcode_buffer, sizeof(fromcode_buffer));
    1.47      }
    1.48      if (!tocode || !*tocode) {
    1.49 -        fromcode = getlocale();
    1.50 +        tocode = getlocale(tocode_buffer, sizeof(tocode_buffer));
    1.51      }
    1.52      for (i = 0; i < SDL_arraysize(encodings); ++i) {
    1.53          if (SDL_strcasecmp(fromcode, encodings[i].name) == 0) {