mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibCore: Add File::{stdin, stdout, stderr}()
This should make it easier to get a Core::File for standard streams.
This commit is contained in:
parent
6c2d0dea91
commit
f69b419c05
Notes:
sideshowbarker
2024-07-19 03:22:30 +09:00
Author: https://github.com/petelliott
Commit: f69b419c05
Pull-request: https://github.com/SerenityOS/serenity/pull/3214
Issue: https://github.com/SerenityOS/serenity/issues/3171
Issue: https://github.com/SerenityOS/serenity/issues/3187
Reviewed-by: https://github.com/Dexesttp
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/awesomekling
2 changed files with 34 additions and 0 deletions
|
@ -203,4 +203,34 @@ String File::read_link(const StringView& link_path)
|
|||
|
||||
#endif
|
||||
|
||||
static RefPtr<File> stdin_file;
|
||||
static RefPtr<File> stdout_file;
|
||||
static RefPtr<File> stderr_file;
|
||||
|
||||
NonnullRefPtr<File> File::stdin()
|
||||
{
|
||||
if (!stdin_file) {
|
||||
stdin_file = File::construct();
|
||||
stdin_file->open(STDIN_FILENO, IODevice::ReadOnly, ShouldCloseFileDescription::No);
|
||||
}
|
||||
return *stdin_file;
|
||||
}
|
||||
|
||||
NonnullRefPtr<File> File::stdout()
|
||||
{
|
||||
if (!stdout_file) {
|
||||
stdout_file = File::construct();
|
||||
stdout_file->open(STDOUT_FILENO, IODevice::WriteOnly, ShouldCloseFileDescription::No);
|
||||
}
|
||||
return *stdout_file;
|
||||
}
|
||||
|
||||
NonnullRefPtr<File> File::stderr()
|
||||
{
|
||||
if (!stderr_file) {
|
||||
stderr_file = File::construct();
|
||||
stderr_file->open(STDERR_FILENO, IODevice::WriteOnly, ShouldCloseFileDescription::No);
|
||||
}
|
||||
return *stderr_file;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue