> Date: Fri, 16 Jan 2026 00:16:47 +0100
> From: Patrice Dumas <[email protected]>
> Cc: [email protected], [email protected]
> 
> > > #ifdef _WIN32         
> > >   if (!locale_encoding)
> > >     {
> > >       unsigned cp = GetACP ();          
> > >       xasprintf (&locale_encoding, "cp%u", cp);
> > >     }
> > > #endif
> > > 
> > > Should there be a change to that code too?
> > 
> > I think texi2any uses the locale's encoding for different purposes,
> > but it cannot do any harm to report codepage 65001 as "UTF-8", so yes.
> 
> What would be the change to Perl equivalent code?  The current code is:
> 
> if (!defined($locale_encoding) and $^O eq 'MSWin32') {
>   eval 'require Win32::API';
>   if (!$@) {
>     Win32::API::More->Import("kernel32", "int GetACP()");
>     my $CP = GetACP();
>     if (defined($CP)) {
>       $locale_encoding = 'cp'.$CP;

Yes, but I would (a) import GetConsoleOutputCP as well, and (b) use
GetConsoleOutputCP in preference to GetACP, if the former returns
non-zero.  That's because on Windows it is possible to change the
encoding understood by the terminal independently of the system
locale's codeset (which is what GetACP returns).

Note that the preference of GetConsoleOutputCP is only for text that
will eventually be output to the terminal.  In other cases, such as
encoding/decoding of file names or decoding system messages and values
of environment variables, the value returned by GetACP is the right
one.

Reply via email to