mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:07:44 +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:
parent
9e6d91032e
commit
2344bb6c57
2 changed files with 8 additions and 0 deletions
|
@ -87,6 +87,13 @@ int File::open_mode_to_options(OpenMode mode)
|
||||||
flags |= O_CLOEXEC;
|
flags |= O_CLOEXEC;
|
||||||
if (!has_flag(mode, OpenMode::Nonblocking))
|
if (!has_flag(mode, OpenMode::Nonblocking))
|
||||||
flags |= O_NONBLOCK;
|
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;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
MustBeNew = 16,
|
MustBeNew = 16,
|
||||||
KeepOnExec = 32,
|
KeepOnExec = 32,
|
||||||
Nonblocking = 64,
|
Nonblocking = 64,
|
||||||
|
DontCreate = 128,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class ShouldCloseFileDescriptor {
|
enum class ShouldCloseFileDescriptor {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue