src/stdlib/SDL_iconv.c
branchSDL-1.2
changeset 3998 098ac044cd2f
parent 3997 6a4f3a32c2e6
child 4053 0aadbc81c497
equal deleted inserted replaced
3997:6a4f3a32c2e6 3998:098ac044cd2f
   770 	return 0;
   770 	return 0;
   771 }
   771 }
   772 
   772 
   773 #endif /* !HAVE_ICONV */
   773 #endif /* !HAVE_ICONV */
   774 
   774 
       
   775 static const char *getlocale()
       
   776 {
       
   777 	const char *lang;
       
   778 
       
   779 	lang = SDL_getenv("LC_ALL");
       
   780 	if ( !lang ) {
       
   781 		lang = SDL_getenv("LC_CTYPE");
       
   782 	}
       
   783 	if ( !lang ) {
       
   784 		lang = SDL_getenv("LC_MESSAGES");
       
   785 	}
       
   786 	if ( !lang ) {
       
   787 		lang = SDL_getenv("LANG");
       
   788 	}
       
   789 	if ( !lang || SDL_strcmp(lang, "C") == 0 ) {
       
   790 		lang = "ASCII";
       
   791 	}
       
   792 	return lang;
       
   793 }
       
   794 
   775 char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
   795 char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
   776 {
   796 {
   777 	SDL_iconv_t cd;
   797 	SDL_iconv_t cd;
   778 	char *string;
   798 	char *string;
   779 	size_t stringsize;
   799 	size_t stringsize;
   780 	char *outbuf;
   800 	char *outbuf;
   781 	size_t outbytesleft;
   801 	size_t outbytesleft;
   782 	size_t retCode = 0;
   802 	size_t retCode = 0;
   783 
   803 
       
   804 	if ( !fromcode || !*fromcode ) {
       
   805 		fromcode = getlocale();
       
   806 	}
       
   807 	if ( !tocode || !*tocode ) {
       
   808 		tocode = getlocale();
       
   809 	}
   784 	cd = SDL_iconv_open(tocode, fromcode);
   810 	cd = SDL_iconv_open(tocode, fromcode);
   785 	if ( cd == (SDL_iconv_t)-1 ) {
   811 	if ( cd == (SDL_iconv_t)-1 ) {
   786 		return NULL;
   812 		return NULL;
   787 	}
   813 	}
   788 
   814