mirror of
https://github.com/fmtlib/fmt.git
synced 2025-08-01 03:34:45 +02:00
Fix writing to stdout when redirected to NUL on Windows (#2080)
This commit is contained in:
@@ -2768,13 +2768,14 @@ FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) {
|
|||||||
if (_isatty(fd)) {
|
if (_isatty(fd)) {
|
||||||
detail::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size()));
|
detail::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size()));
|
||||||
auto written = detail::dword();
|
auto written = detail::dword();
|
||||||
if (!detail::WriteConsoleW(reinterpret_cast<void*>(_get_osfhandle(fd)),
|
if (detail::WriteConsoleW(reinterpret_cast<void*>(_get_osfhandle(fd)),
|
||||||
u16.c_str(), static_cast<uint32_t>(u16.size()),
|
u16.c_str(), static_cast<uint32_t>(u16.size()),
|
||||||
&written, nullptr)) {
|
&written, nullptr)) {
|
||||||
FMT_THROW(format_error("failed to write to console"));
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Fallback to fwrite on failure. It can happen if the output has been
|
||||||
|
// redirected to NUL.
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
detail::fwrite_fully(buffer.data(), 1, buffer.size(), f);
|
detail::fwrite_fully(buffer.data(), 1, buffer.size(), f);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user