From e253854269ce2ab54c0d7cfcc2ec4cb721f9ded1 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 17 Sep 2016 11:32:09 -1000 Subject: [PATCH] Ensure FileWriter creates new files when overwrite unset --- src/athena/FileWriter.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/athena/FileWriter.cpp b/src/athena/FileWriter.cpp index 02857af..484059f 100644 --- a/src/athena/FileWriter.cpp +++ b/src/athena/FileWriter.cpp @@ -51,12 +51,26 @@ void FileWriter::open(bool overwrite) if (overwrite) m_fileHandle = _wfopen(m_filename.c_str(), L"w+b"); else + { m_fileHandle = _wfopen(m_filename.c_str(), L"r+b"); + if (m_fileHandle) + { + fclose(m_fileHandle); + m_fileHandle = _wfopen(m_filename.c_str(), L"r+b"); + } + } #else if (overwrite) m_fileHandle = fopen(m_filename.c_str(), "w+b"); else - m_fileHandle = fopen(m_filename.c_str(), "r+b"); + { + m_fileHandle = fopen(m_filename.c_str(), "a+b"); + if (m_fileHandle) + { + fclose(m_fileHandle); + m_fileHandle = fopen(m_filename.c_str(), "r+b"); + } + } #endif if (!m_fileHandle)