43 ms·
I think it isn't documented, but the console is a special case. The default mode of stdout is _O_TEXT. _write(), which is used internally by stdio, performs en
by xeeeeeeeeeeenu 3y ago
I think it isn't documented, but the console is a special case. The default mode of stdout is _O_TEXT.
_write(), which is used internally by stdio, performs encoding translation if all of the following are true:
- The current locale isn't "C".
- The _O_TEXT flag is set.
- The fd points to the console.
When you redirect the stdout (e.g. with > in a shell), it's no longer considered a console handle, so the translation won't be applied.
Personally, I think it was a weird design decision to include encoding and CRLF translation in what Microsoft calls "low-level I/O".
- jlokier 3y agoWindows isn't unusual for the CRLF translation part. Unix based operating systems, such as Linux, MacOS and the BSDs, do something similar. When writing to a terminal device, which can be a console device, the terminal driver performs CRLF conversions and other special character handling depending on the terminal settings. If an application wants to disable these character operations on a terminal device it has to explicitly turn them off, which is a bit like using _O_BINARY on Windows. CRLF conversions aren't done in the application's stdio code, but the effect is similar to a Windows console fd.