> Date: Fri, 16 Jan 2026 15:31:42 +0100
> From: Patrice Dumas <[email protected]>
> Cc: [email protected], [email protected]
> 
> > > 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.
> 
> We already have different encodings set to the locale, but it is not
> completly clear to me where GetConsoleOutputCP or GetACP should be used.

You are right, this is tricky.

> Could you please correct and complete the following information:
> 
> * decode command-line, including file names passed on the command line
>   we would like to decode (sometime we do not decode file names) -> ?

Use the codepage returned by GetACP for thse.

> * decode environment variables (we do not decode file names
>   passed as environment variables in some cases) -> GetACP

Yes.

> * error and warning messages translations encoding -> GetACP

The messages are encoded in the codepage returned by GetACP.

> * encode command line before executing the command line -> ?

GetACP

> * error and warning messages output encoding -> GetConsoleOutputCP

Yes.  Basically, any text you write to the console.

> * encode input file names and output file names on the filesystem -> GetACP

Yes.

> Another information I would need is the equivalent in Perl of
> determining that the console page is UTF-8.  In C it is like:
>   UINT cp = GetACP ();
>   if (cp == CP_UTF8)
>     ....
> 
> What the (cp == CP_UTF8) comparison should be on the string returned by
> GetACP or GetConsoleOutputCP?

The value of CP_UTF8 is 65001, and both GetACP and GetConsoleOutputCP
return it when the corresponding encoding is UTF-8.  Both of these
functions return an integer, not a string.

Reply via email to