mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01:00
fixed GH #2624: Poco::FileChannel/Poco:LogFileImpl::writeImpl() on Windows should translate \n to \r\n.
This commit is contained in:
parent
0f49493d0e
commit
958ce15bb5
@ -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<DWORD>(logText.size()), &bytesWritten, NULL);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
if (flush)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user