1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:47:45 +00:00

LibCore: Add File::OpenMode::DontCreate

Some applications may not want to have the ability to create a
file if it doesn't exist, but still be able to read and write
from it. The easy solution here would be just to not apply
O_CREAT when creating the flags, but to prevent breaking a ton
of applications, having a `DontCreate` mode is the best for now.
This commit is contained in:
Caoimhe 2023-06-02 23:30:32 +01:00 committed by Andreas Kling
parent 9e6d91032e
commit 2344bb6c57
2 changed files with 8 additions and 0 deletions

View file

@ -87,6 +87,13 @@ int File::open_mode_to_options(OpenMode mode)
flags |= O_CLOEXEC;
if (!has_flag(mode, OpenMode::Nonblocking))
flags |= O_NONBLOCK;
// Some open modes, like `ReadWrite` imply the ability to create the file if it doesn't exist.
// Certain applications may not want this privledge, and for compability reasons, this is
// the easiest way to add this option.
if (has_flag(mode, OpenMode::DontCreate))
flags &= ~O_CREAT;
return flags;
}