Use WriteConsoleW() in priv_fwrite() too (#3607)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
jq dumps JSON to the Windows console as UTF-16 with WriteConsoleW(), but priv_fwrite() still writes the raw UTF-8 bytes with WriteFile(), which the console decodes with its output code page. So `jq .k` prints non-ASCII correctly while `jq -r .k` prints mojibake, and the same goes for -j, --raw-output0, --seq, halt_error and the `stderr` builtin. The tty flag is computed once, from stdout, and passed to writes aimed at stderr too, so ask the handle instead: with stdout on a console and stderr redirected, WriteConsoleW() failed on the file handle and the output was dropped. One byte-level change: with stdout on a console and stderr redirected, halt_error and the `stderr` builtin now go through the CRT, so bare LF becomes CRLF and an existing CRLF becomes CR CRLF. Use -b for byte-exact output on that stream.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+39 added−40 removed
- other:+39 added−40 removed