mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-16 06:56:41 +02: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();
|
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;
|
DWORD bytesWritten;
|
||||||
BOOL res = WriteFile(_hFile, text.data(), (DWORD) text.size(), &bytesWritten, NULL);
|
BOOL res = WriteFile(_hFile, logText.data(), static_cast<DWORD>(logText.size()), &bytesWritten, NULL);
|
||||||
if (!res) throw WriteFileException(_path);
|
|
||||||
res = WriteFile(_hFile, "\r\n", 2, &bytesWritten, NULL);
|
|
||||||
if (!res) throw WriteFileException(_path);
|
if (!res) throw WriteFileException(_path);
|
||||||
if (flush)
|
if (flush)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user