mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:27:35 +00:00
LibCore: Add File::open_file_or_standard_stream()
This commit is contained in:
parent
b66ceafaba
commit
1c5f6003d7
2 changed files with 17 additions and 0 deletions
|
@ -153,6 +153,21 @@ bool File::exists(StringView filename)
|
|||
return !Core::System::stat(filename).is_error();
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<File>> File::open_file_or_standard_stream(StringView filename, OpenMode mode)
|
||||
{
|
||||
if (!filename.is_empty() && filename != "-"sv)
|
||||
return File::open(filename, mode);
|
||||
|
||||
switch (mode) {
|
||||
case OpenMode::Read:
|
||||
return File::adopt_fd(STDIN_FILENO, mode);
|
||||
case OpenMode::Write:
|
||||
return File::adopt_fd(STDOUT_FILENO, mode);
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
int File::open_mode_to_options(OpenMode mode)
|
||||
{
|
||||
int flags = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue