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

Yao Qi
2014-06-11T02:22:45Z

On 06/09/2014 06:11 PM, Pedro Alves wrote:
> I think the test caught a real GDB bug on Windows, and we
> should fix GDB to make it look at the environment variables,
> as is expected of GNU programs. And that the best way
> to handle this is to import the gnulib setlocale module.

I've started setlocale module import, but during the work, I did some
experiments and the result is confusing me.

We import setlocale so that we can set locale through env var, assuming
that different locales affect the return value of iswprint (0xa2).
However, this assumption isn't true on Windows :(

I write the following program to check the return value of iswprint
under different locales.

On Linux, the output is reasonable
$ ./iswprint
4
C: 0
en_US.UTF-8: 1
C: 0

On Windows, iswprint always return true!
C:\>iswprint.win.exe
2
C: 16
English_United States.1252: 16
C: 16

iswprint return value depends on LC_CTYPE, but under LC_CTYPE=C,
iswprint (0xa2) behaves differently on Windows and Linux.

--
Yao (é½å°§)

#include <wchar.h>
#include <wctype.h>
#include <stdio.h>
#include <locale.h>

int
main (void)
{
wchar_t c = 0xa2;

printf ("%d\n", sizeof c);

printf ("%s: %d\n", setlocale (LC_CTYPE, NULL), iswprint (c));

setlocale (LC_CTYPE, "");
printf ("%s: %d\n", setlocale (LC_CTYPE, NULL), iswprint (c));

setlocale (LC_CTYPE, "C");
printf ("%s: %d\n", setlocale (LC_CTYPE, NULL), iswprint (c));

return 0;
}