[MPlayer-dev-eng] [PATCH] implement the setlocale feature

Fengguang Wu fengguang.wu at gmail.com
Mon Jun 19 06:55:36 CEST 2006


On Sun, Jun 18, 2006 at 06:26:50PM -0400, Rich Felker wrote:
> On Sun, Jun 18, 2006 at 11:49:03PM +0200, joerg at britannica.bec.de wrote:
> > On Sun, Jun 18, 2006 at 11:34:41PM +0200, Dominik 'Rathann' Mierzejewski wrote:
> > > On Sunday, 18 June 2006 at 23:02, Ivan Kalvachev wrote:
> > > [...]
> > > > 2. What kind of bug is the setlocale() change fixing? Doesn't it beat
> > > > the purpose of using nl_langinfo()??
> > > 
> > > I was under the impression that we didn't want any setlocale() calls
> > > at all because they break various things.
> > 
> > Calling setlocale is necessary to get the correct data from nl_langinfo,
> > e.g. the charset that is supposed to get written.

Yes, without the added setlocale(), nl_langinfo() returns the ASCII
charset:

        On startup of the main program, the portable "C" locale is
        selected as default.  A  program  may  be  made portable to
        all locales by calling setlocale(LC_ALL, "" ) after program
        initialization

> > I know about the complains from Rich, but calling setlocale() once to
> > get the correct information and calling it for a second time to force
> > the C/POSIX locale avoids most of the issues.
> 
> Yes and this is already done in the only place it's needed, mp_msg
> init. This asf crap does not need to know nl_langinfo(CODESET).
> Instead it needs to always use UTF-8. This can be done without even
> using iconv since the source data is UTF-16 and easily converted
> directly.

The video server here returns GBK encoded mms urls. However, if utf8
is the preferred "correct way", I can write a simple wrapper to
do the GBK <-> UTF8 conversion.

But the current behavior is broken and unrepairable: it takes only ASCII!

Attached a patch using UTF-8 unconditionally, comments are welcome.

Thanks,
Fengguang Wu
-------------- next part --------------
Index: libmpdemux/asf_mmst_streaming.c
===================================================================
--- libmpdemux/asf_mmst_streaming.c	(revision 18754)
+++ libmpdemux/asf_mmst_streaming.c	(working copy)
@@ -25,16 +25,9 @@
 #include <winsock2.h>
 #endif
 
-#ifndef USE_SETLOCALE
-#undef USE_ICONV
-#endif
-
 #ifdef USE_ICONV
 #include <iconv.h>
-#ifdef USE_LANGINFO
-#include <langinfo.h>
 #endif
-#endif
 
 #include "url.h"
 #include "asf.h"
@@ -552,12 +545,8 @@
 
   /* prepare for the url encoding conversion */
 #ifdef USE_ICONV
-#ifdef USE_LANGINFO
-  url_conv = iconv_open("UTF-16LE",nl_langinfo(CODESET));
-#else
-  url_conv = iconv_open("UTF-16LE", NULL);
+  url_conv = iconv_open("UTF-16LE", "UTF-8");
 #endif
-#endif
 
   snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1->hostname);
   string_utf16 (data, str, strlen(str));


More information about the MPlayer-dev-eng mailing list