comparison 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
comparison
equal deleted inserted replaced
2142:ca80c942e69c 2143:e906da4414a3
771 return 0; 771 return 0;
772 } 772 }
773 773
774 #endif /* !HAVE_ICONV */ 774 #endif /* !HAVE_ICONV */
775 775
776 static const char *
777 getlocale()
778 {
779 const char *lang;
780
781 lang = SDL_getenv("LC_ALL");
782 if (!lang) {
783 lang = SDL_getenv("LC_CTYPE");
784 }
785 if (!lang) {
786 lang = SDL_getenv("LC_MESSAGES");
787 }
788 if (!lang) {
789 lang = SDL_getenv("LANG");
790 }
791 if (!lang || SDL_strcmp(lang, "C") == 0) {
792 lang = "ASCII";
793 }
794 return lang;
795 }
796
776 char * 797 char *
777 SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, 798 SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
778 size_t inbytesleft) 799 size_t inbytesleft)
779 { 800 {
780 SDL_iconv_t cd; 801 SDL_iconv_t cd;
782 size_t stringsize; 803 size_t stringsize;
783 char *outbuf; 804 char *outbuf;
784 size_t outbytesleft; 805 size_t outbytesleft;
785 size_t retCode = 0; 806 size_t retCode = 0;
786 807
808 if (!fromcode || !*fromcode) {
809 fromcode = getlocale();
810 }
811 if (!tocode || !*tocode) {
812 tocode = getlocale();
813 }
787 cd = SDL_iconv_open(tocode, fromcode); 814 cd = SDL_iconv_open(tocode, fromcode);
788 if (cd == (SDL_iconv_t) - 1) { 815 if (cd == (SDL_iconv_t) - 1) {
789 return NULL; 816 return NULL;
790 } 817 }
791 818