Robust implementation for getting handles.

pull/3442/head
Mihir Patel 1 month ago
parent ce53eaed7f
commit 8a780f6dbc

@ -119,8 +119,7 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_ccode_(
const string_view_t &color_code) const { const string_view_t &color_code) const {
#ifdef _WIN32 #ifdef _WIN32
DWORD bytes_written = 0; DWORD bytes_written = 0;
HANDLE h = HANDLE h = reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(target_file_)));
(target_file_ == stdout) ? GetStdHandle(STD_OUTPUT_HANDLE) : GetStdHandle(STD_ERROR_HANDLE);
// WriteFile bypasses the extra \r injection // WriteFile bypasses the extra \r injection
WriteFile(h, color_code.data(), static_cast<DWORD>(color_code.size()), &bytes_written, nullptr); WriteFile(h, color_code.data(), static_cast<DWORD>(color_code.size()), &bytes_written, nullptr);
#else #else
@ -134,8 +133,7 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_range_(const memory_buf_t
size_t end) const { size_t end) const {
#ifdef _WIN32 #ifdef _WIN32
DWORD bytes_written = 0; DWORD bytes_written = 0;
HANDLE h = HANDLE h = reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(target_file_)));
(target_file_ == stdout) ? GetStdHandle(STD_OUTPUT_HANDLE) : GetStdHandle(STD_ERROR_HANDLE);
WriteFile(h, formatted.data() + start, static_cast<DWORD>(end - start), &bytes_written, WriteFile(h, formatted.data() + start, static_cast<DWORD>(end - start), &bytes_written,
nullptr); nullptr);
#else #else

Loading…
Cancel
Save