On Saturday 25 January 2025 18:52:26 Lasse Collin wrote:
> On 2025-01-25 Lasse Collin wrote:
> > On 2025-01-25 Pali Rohár wrote:
> > > Also what could be different is that _findfirst may be affected by
> > > setlocale function as IIRC UCRT supports changing process locale but
> > > only for UCRT functions.
> > > 
> > > Another important thing is that FindFirstFile is affected by the
> > > AreFileApisANSI() function. Some info is in SetFileApisToOEM() spec:
> > > https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileapistooem
> > >   
> > 
> > I wonder how much this matters. If Win9x compatibility isn't needed,
> > the new dirent code would only use wide character functions
> > (_wfindfirst or FindFirstFileW). If I understand correctly, the
> > functions you mentioned won't affect the wide character APIs.
> 
> Even if wide char functions were always used to read filenames, perhaps
> AreFileApisANSI() needs to be taken into account in readdir() to
> determine if the wide char names should be converted to CP_ACP or
> CP_OEMCP?

Yes. This is what I mean. If you are using CRT's _findfirst() then it
will (hopefully) return filenames in narrow encoding, which is also need
for POSIX readdir(). If you are going to use FindFirstFileW() then it is
required to do conversion to the correct narrow encoding and the
encoding is affected by that SetFileApisToOEM() function. At least
CP_ACP and CP_OEMCP needs to be considered.

> WideCharToMultiByte() also has CP_THREAD_ACP on W2k and later. The docs
> of SetFileApisToOEM() and AreFileApisANSI() say that they are about the
> process code page, not thread. Maybe CP_ACP is correct then. I haven't
> tested.

If the thread (or process) is switched to OEM encoding then you cannot
use ANSI (=ACP). But I do not have details when and how this encoding
insanity is applied (if is really per-thread or just global process).
This CP_THREAD_ACP looks like even more complicated thing, specially how
it interact with the setlocale().

Also it is questionable if the _findfirst() and FindFirstFileA()
differs in encoding based on other CRT / WINAPI settings.

I have feeling that CRT's setlocale() may change the encoding used by
the CRT's _findfirst(), but does not affect WINAPI FindFirstFileA().

And in my opinion, POSIX readdir() should follow the encoding which is
used by the CRT _findfirst().


_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to