mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 01:10:28 +03:00
LibCore: Add File::open_file_or_standard_stream()
This commit is contained in:
parent
b66ceafaba
commit
1c5f6003d7
Notes:
sideshowbarker
2024-07-17 07:19:53 +09:00
Author: https://github.com/demostanis Commit: https://github.com/SerenityOS/serenity/commit/1c5f6003d7 Pull-request: https://github.com/SerenityOS/serenity/pull/14674 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/AtkinsSJ Reviewed-by: https://github.com/MacDue ✅ Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/timschumi
@ -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;
|
||||
|
@ -185,6 +185,8 @@ public:
|
||||
static ErrorOr<NonnullOwnPtr<File>> adopt_fd(int fd, OpenMode);
|
||||
static bool exists(StringView filename);
|
||||
|
||||
static ErrorOr<NonnullOwnPtr<File>> open_file_or_standard_stream(StringView filename, OpenMode mode);
|
||||
|
||||
File(File&& other) { operator=(move(other)); }
|
||||
|
||||
File& operator=(File&& other)
|
||||
|
Loading…
Reference in New Issue
Block a user