[MPlayer-dev-eng] [PATCH] libmpdemux/asf_mmst_streaming.c: fixed calling iconv_open with correct encoding information

Wang WenRui wangwr at ustc.edu
Mon Apr 19 10:49:01 CEST 2004


Hi, Around 01 o'clock on 18 Apr, Wang WenRui wrote:
> Hi:
> 
>    But the committed code(not same as my patch) is not correct and
>    thus
Found that my first patch is changed here[1] because the not very
portable nl_langinfo. But the modification(and the current cvs) is not
correct. "setlocale(LC_CTYPE, NULL)" returns the full encoding
string(ex. "zh_CN.GBK") which is bad as the parameter to iconv_open,
where "nl_langinfo(CODESET)" returns the correct encoding string(ex.
"GBK").

For the portability issue, this is a piece of code from gnumeric:
get_locale_charset_name() returns the short encoding name can be passed
to iconv_open, call it after "setlocale(LC_CTYPE, "")".

	static char*
	get_locale_charset_name()
	{
	#ifndef HAVE_ICONV
		return "";
	#else
		static char* charset = NULL;

		if (charset)
			return charset;
			
	#ifdef _NL_CTYPE_CODESET_NAME
		charset = nl_langinfo (_NL_CTYPE_CODESET_NAME);
	#elif defined(CODESET)
		charset = nl_langinfo (CODESET);
	#elif
		{
			char* locale = setlocale(LC_CTYPE,NULL);
			char* tmp = strchr(locale,'.');
			if (tmp)
				charset = tmp+1;
		}
	#endif  
		if (!charset)
			charset = "ISO-8859-1";
		charset = g_strdup(charset);
		return charset;
	#endif
	}

[1] http://www1.mplayerhq.hu/pipermail/mplayer-dev-eng/2003-November/022129.html


>    not working. The from_code parameter of iconv_open is
>    "setlocale(LC_CTYPE, NULL)" which returns sth like "zh_CN.GBK" which
>    is not charset.  nl_langinfo(CODESET) should be used. It returns the
>    correct charset for conversion(GBK).
> 
>    The new patch against current cvs is in the attachment and is tested
>    working. Please commit it, thanks.  Please CC me, I am not on this
>    list.
> 
> [1] http://www1.mplayerhq.hu/pipermail/mplayer-dev-eng/2003-October/021030.html




More information about the MPlayer-dev-eng mailing list