diff src/stdlib/SDL_iconv.c @ 3998:098ac044cd2f SDL-1.2

Fixed bug #447 Xlib uses the native locale, not latin1 ... the question is... what does the server use? :)
author Sam Lantinga <slouken@libsdl.org>
date Wed, 04 Jul 2007 07:54:06 +0000
parents 6a4f3a32c2e6
children 0aadbc81c497
line wrap: on
line diff
--- a/src/stdlib/SDL_iconv.c	Wed Jul 04 04:27:47 2007 +0000
+++ b/src/stdlib/SDL_iconv.c	Wed Jul 04 07:54:06 2007 +0000
@@ -772,6 +772,26 @@
 
 #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)
 {
 	SDL_iconv_t cd;
@@ -781,6 +801,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;