Re: [ping] [PATCH] Different outputs affected by locale

Eli Zaretskii
2014-06-12T17:48:58Z

> Date: Thu, 12 Jun 2014 18:23:34 +0100
> From: Pedro Alves <palves@redhat.com>
> CC: Tom Tromey <tromey@redhat.com>, Joel Brobecker <brobecker@adacore.com>, gdb-patches@sourceware.org
>
> On 06/12/2014 03:37 PM, Yao Qi wrote:
> > On 06/12/2014 07:36 PM, Pedro Alves wrote:
> >> What does "show host-charset" show on Windows, before and after
> >> you make GDB pick LC_CTYPE=C from the environment (with the
> >> setlocale gnulib module)?
> >
> > GDB on Windows gets host charset from GetACP(), in
> > charset.c:_initialize_charset ().
> >
> > #elif defined (USE_WIN32API)
> > {
> > /* "CP" + x<=5 digits + paranoia. */
> > static char w32_host_default_charset[16];
> >
> > snprintf (w32_host_default_charset, sizeof w32_host_default_charset,
> > "CP%d", GetACP());
> > auto_host_charset_name = w32_host_default_charset;
> > auto_target_charset_name = auto_host_charset_name;
> > }
> > #endif
> >
>
> I note gnulib's nl_langinfo replacement actually does
> the same thing.

And gnulib's nl_langinfo is wrong, btw, because one can use
'setlocale' to change the codeset, without any relation whatsoever to
the console encoding. (I sent a fix for that to gnulib's list just
yesterdat.)

> > GetACP doesn't depend on locale,
>
> Yeah, it's a mess, and those are really different
> things. The former is the system locale, while the latter
> the user locale.

That's true, but that's not the important issue here. The important
issue here is the fundamental difference between the Windows console
encoding and the current locale's codeset. The former affects how
Windows writes to the console, and in most cases changing the console
codepage (e.g., with SetConsoleCP or SetConsoleOutputCP) is a futile
exercise, because all it does is cause garbled display. The latter is
an important feature when you are dealing with programs that don't
intend using the codeset to display text to the user, but, for
example, to change the behavior of iswprint.

Using the console codepage when really the locale's codeset is needed
will only going to work for the default setup, not when you want or
need to change the locale.