diff src/stdlib/SDL_iconv.c @ 2143:e906da4414a3

Fix for bug #447 merged from SDL 1.2
author Sam Lantinga <slouken@libsdl.org>
date Wed, 04 Jul 2007 08:01:04 +0000
parents ca80c942e69c
children cc2597da0840
line wrap: on
line diff
--- a/src/stdlib/SDL_iconv.c	Wed Jul 04 07:08:16 2007 +0000
+++ b/src/stdlib/SDL_iconv.c	Wed Jul 04 08:01:04 2007 +0000
@@ -773,6 +773,27 @@
 
 #endif /* !HAVE_ICONV */
 
+static const char *
+getlocale()
+{
+    const char *lang;
+
+    lang = SDL_getenv("LC_ALL");
+    if (!lang) {
+        lang = SDL_getenv("LC_CTYPE");
+    }
+    if (!lang) {
+        lang = SDL_getenv("LC_MESSAGES");
+    }
+    if (!lang) {
+        lang = SDL_getenv("LANG");
+    }
+    if (!lang || SDL_strcmp(lang, "C") == 0) {
+        lang = "ASCII";
+    }
+    return lang;
+}
+
 char *
 SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
                  size_t inbytesleft)
@@ -784,6 +805,12 @@
     size_t outbytesleft;
     size_t retCode = 0;
 
+    if (!fromcode || !*fromcode) {
+        fromcode = getlocale();
+    }
+    if (!tocode || !*tocode) {
+        tocode = getlocale();
+    }
     cd = SDL_iconv_open(tocode, fromcode);
     if (cd == (SDL_iconv_t) - 1) {
         return NULL;