src/stdlib/SDL_iconv.c
changeset 2143 e906da4414a3
parent 2142 ca80c942e69c
child 2182 cc2597da0840
--- 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;