It is true that Microsoft's `fwide` does not conform to C standard, it simply
does nothing. However, Microsoft's _setmode[1] with _O_{U8TEXT,U16TEXT,WTEXT}
modes somewhat resembles `fwide`; it sets fd to "Unicode" translation mode.
Similarly to "wide-oriented streams", fds in "Unicode mode" cannot be used with
narrow I/O functions such as printf or getc.
I was thinking we could implement `fwide` around _setmode, however it does not
seem to be the case.
[1] https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode
- Kirill Makurin
________________________________
From: LIU Hao
Sent: Tuesday, October 21, 2025 7:58 PM
To: Kirill Makurin; Martin Storsjö; Pali Rohár
Cc: [email protected]
Subject: Re: [PATCH 5/5] crt: Add support to call freopen() with NULL path
在 2025-10-21 16:41, Kirill Makurin 写道:
> In this particular case it is quite unfortunate that (afaik) Windows is the
> only platform which cares
> about binary vs. non-binary I/O modes, but at the same time it does not
> implement standard way of doing this.
It's not just about the binary mode. On Linux, `freopen()` is the only way to
change the orientation of a
stream: After a narrow I/O function has been called on a stream, it makes the
stream narrow-oriented, and
further calls to wide functions on the same stream will fail; and after a wide
I/O function has been
called on a stream, it makes the stream wide-oriented, and further calls to
narrow functions will fail.
`freopen()` clears the orientation of a stream, to make it reusable.
It looks like Microsoft streams do not have orientation, and their `fwide()`
'doesn't conform to the C
Standard.' [1]
[1]
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fwide?view=msvc-170
> While it is good to be more conformant to ISO C, I believe it is better try
> to avoid situations when
> compiling the same code under MSVC and mingw-w64 will result in different
> behavior (unless it fixes an
> actual bug).
>
> I'm not sure about this either, I think I'd prefer keeping compatibility with
> MSVC if possible.
I think this makes sense, especially about UCRT.
--
Best regards,
LIU Hao
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public