From cfd0ea197c93978d82b503b26284617aa2c3f645 Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 27 Sep 2020 18:32:08 +0300 Subject: [PATCH] Simplify WriteFile() usage under windows --- include/spdlog/sinks/wincolor_sink-inl.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/include/spdlog/sinks/wincolor_sink-inl.h b/include/spdlog/sinks/wincolor_sink-inl.h index 71e3a8ce..1551c902 100644 --- a/include/spdlog/sinks/wincolor_sink-inl.h +++ b/include/spdlog/sinks/wincolor_sink-inl.h @@ -151,17 +151,12 @@ void SPDLOG_INLINE wincolor_sink::write_to_file_(const memory_buf_ return; } - DWORD total_written = 0; - do + DWORD bytes_written = 0; + bool ok = ::WriteFile(out_handle_, formatted.data(), size, &bytes_written, nullptr) != 0; + if (!ok) { - DWORD bytes_written = 0; - bool ok = ::WriteFile(out_handle_, formatted.data() + total_written, size - total_written, &bytes_written, nullptr) != 0; - if (!ok || bytes_written == 0) - { - throw_spdlog_ex("wincolor_sink: write_to_file_ failed. GetLastError(): " + std::to_string(::GetLastError())); - } - total_written += bytes_written; - } while (total_written < size); + throw_spdlog_ex("wincolor_sink: write_to_file_ failed. GetLastError(): " + std::to_string(::GetLastError())); + } } // wincolor_stdout_sink