diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-26 14:32:59 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-26 14:32:59 +0100 |
commit | aa49419173e860db5a4f4d4c9cbb8182fea394e9 (patch) | |
tree | 67b60ad1f9c85b674f41e4142a1dd42c5a18b01b | |
parent | 67d2875d604e6090ca96634e839ebe6fdf9eae10 (diff) | |
download | serenity-aa49419173e860db5a4f4d4c9cbb8182fea394e9.zip |
LibCore: Make CFile::open() truncate when opening something "WriteOnly"
Unless we're also opening to append (and/or if the file is required to
be a new file), CFile::open(WriteOnly) will now truncate the file.
-rw-r--r-- | Libraries/LibCore/CFile.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Libraries/LibCore/CFile.cpp b/Libraries/LibCore/CFile.cpp index dfa5b2c073..91c0a09258 100644 --- a/Libraries/LibCore/CFile.cpp +++ b/Libraries/LibCore/CFile.cpp @@ -34,6 +34,9 @@ bool CFile::open(CIODevice::OpenMode mode) flags |= O_RDONLY; } else if (mode & CIODevice::WriteOnly) { flags |= O_WRONLY | O_CREAT; + bool should_truncate = !((mode & CIODevice::Append) || (mode & CIODevice::MustBeNew)); + if (should_truncate) + flags |= O_TRUNC; } if (mode & CIODevice::Append) flags |= O_APPEND; |