diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp index b73f9e1640..579a23045b 100644 --- a/Userland/Libraries/LibCore/Stream.cpp +++ b/Userland/Libraries/LibCore/Stream.cpp @@ -148,6 +148,19 @@ bool File::exists(StringView filename) return !Core::System::stat(filename).is_error(); } +ErrorOr> File::standard_input() +{ + return File::adopt_fd(STDIN_FILENO, OpenMode::Read, ShouldCloseFileDescriptor::No); +} +ErrorOr> File::standard_output() +{ + return File::adopt_fd(STDOUT_FILENO, OpenMode::Write, ShouldCloseFileDescriptor::No); +} +ErrorOr> File::standard_error() +{ + return File::adopt_fd(STDERR_FILENO, OpenMode::Write, ShouldCloseFileDescriptor::No); +} + ErrorOr> File::open_file_or_standard_stream(StringView filename, OpenMode mode) { if (!filename.is_empty() && filename != "-"sv) @@ -155,9 +168,9 @@ ErrorOr> File::open_file_or_standard_stream(StringView filen switch (mode) { case OpenMode::Read: - return File::adopt_fd(STDIN_FILENO, mode); + return standard_input(); case OpenMode::Write: - return File::adopt_fd(STDOUT_FILENO, mode); + return standard_output(); default: VERIFY_NOT_REACHED(); } diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h index ecb68615a0..d30de3788a 100644 --- a/Userland/Libraries/LibCore/Stream.h +++ b/Userland/Libraries/LibCore/Stream.h @@ -198,6 +198,9 @@ public: static ErrorOr> adopt_fd(int fd, OpenMode, ShouldCloseFileDescriptor = ShouldCloseFileDescriptor::Yes); static bool exists(StringView filename); + static ErrorOr> standard_input(); + static ErrorOr> standard_output(); + static ErrorOr> standard_error(); static ErrorOr> open_file_or_standard_stream(StringView filename, OpenMode mode); File(File&& other) { operator=(move(other)); }