src/stdlib/SDL_iconv.c
branchSDL-1.2
changeset 3998 098ac044cd2f
parent 3997 6a4f3a32c2e6
child 4053 0aadbc81c497
     1.1 --- a/src/stdlib/SDL_iconv.c	Wed Jul 04 04:27:47 2007 +0000
     1.2 +++ b/src/stdlib/SDL_iconv.c	Wed Jul 04 07:54:06 2007 +0000
     1.3 @@ -772,6 +772,26 @@
     1.4  
     1.5  #endif /* !HAVE_ICONV */
     1.6  
     1.7 +static const char *getlocale()
     1.8 +{
     1.9 +	const char *lang;
    1.10 +
    1.11 +	lang = SDL_getenv("LC_ALL");
    1.12 +	if ( !lang ) {
    1.13 +		lang = SDL_getenv("LC_CTYPE");
    1.14 +	}
    1.15 +	if ( !lang ) {
    1.16 +		lang = SDL_getenv("LC_MESSAGES");
    1.17 +	}
    1.18 +	if ( !lang ) {
    1.19 +		lang = SDL_getenv("LANG");
    1.20 +	}
    1.21 +	if ( !lang || SDL_strcmp(lang, "C") == 0 ) {
    1.22 +		lang = "ASCII";
    1.23 +	}
    1.24 +	return lang;
    1.25 +}
    1.26 +
    1.27  char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
    1.28  {
    1.29  	SDL_iconv_t cd;
    1.30 @@ -781,6 +801,12 @@
    1.31  	size_t outbytesleft;
    1.32  	size_t retCode = 0;
    1.33  
    1.34 +	if ( !fromcode || !*fromcode ) {
    1.35 +		fromcode = getlocale();
    1.36 +	}
    1.37 +	if ( !tocode || !*tocode ) {
    1.38 +		tocode = getlocale();
    1.39 +	}
    1.40  	cd = SDL_iconv_open(tocode, fromcode);
    1.41  	if ( cd == (SDL_iconv_t)-1 ) {
    1.42  		return NULL;