From 958ce15bb52198998644fe4af9110212bdbc64a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Thu, 23 Jan 2020 11:26:26 +0100 Subject: [PATCH] fixed GH #2624: Poco::FileChannel/Poco:LogFileImpl::writeImpl() on Windows should translate \n to \r\n. --- Foundation/src/LogFile_WIN32U.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Foundation/src/LogFile_WIN32U.cpp b/Foundation/src/LogFile_WIN32U.cpp index b89bf8ec0..f42b98a7c 100644 --- a/Foundation/src/LogFile_WIN32U.cpp +++ b/Foundation/src/LogFile_WIN32U.cpp @@ -44,10 +44,19 @@ void LogFileImpl::writeImpl(const std::string& text, bool flush) { if (INVALID_HANDLE_VALUE == _hFile) createFile(); + std::string logText; + logText.reserve(text.size() + 16); // keep some reserve for \n -> \r\n and terminating \r\n + for (char c: text) + { + if (c == '\n') + logText += "\r\n"; + else + logText += c; + } + logText += "\r\n"; + DWORD bytesWritten; - BOOL res = WriteFile(_hFile, text.data(), (DWORD) text.size(), &bytesWritten, NULL); - if (!res) throw WriteFileException(_path); - res = WriteFile(_hFile, "\r\n", 2, &bytesWritten, NULL); + BOOL res = WriteFile(_hFile, logText.data(), static_cast(logText.size()), &bytesWritten, NULL); if (!res) throw WriteFileException(_path); if (flush) {