1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-24 01:05:08 +00:00

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.
This commit is contained in:
Andreas Kling 2019-11-26 14:32:59 +01:00
parent 67d2875d60
commit aa49419173

View file

@ -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;