mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 15:45:25 +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:
committed by
Andreas Kling
parent
6c2d0dea91
commit
f69b419c05
@@ -203,4 +203,34 @@ String File::read_link(const StringView& link_path)
|
|||||||
|
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ public:
|
|||||||
};
|
};
|
||||||
bool open(int fd, IODevice::OpenMode, ShouldCloseFileDescription);
|
bool open(int fd, IODevice::OpenMode, ShouldCloseFileDescription);
|
||||||
|
|
||||||
|
static NonnullRefPtr<File> stdin();
|
||||||
|
static NonnullRefPtr<File> stdout();
|
||||||
|
static NonnullRefPtr<File> stderr();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
File(Object* parent = nullptr)
|
File(Object* parent = nullptr)
|
||||||
: IODevice(parent)
|
: IODevice(parent)
|
||||||
|
|||||||
Reference in New Issue
Block a user