mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:58:11 +00:00
LibCore: Make it possible to create a CFile for an existing file descriptor.
This commit is contained in:
parent
c392c0d799
commit
0a68e0046f
2 changed files with 13 additions and 1 deletions
|
@ -10,10 +10,18 @@ CFile::CFile(const String& filename)
|
||||||
|
|
||||||
CFile::~CFile()
|
CFile::~CFile()
|
||||||
{
|
{
|
||||||
if (mode() != NotOpen)
|
if (m_should_close_file_descriptor == ShouldCloseFileDescriptor::Yes && mode() != NotOpen)
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CFile::open(int fd, CIODevice::OpenMode mode, ShouldCloseFileDescriptor should_close)
|
||||||
|
{
|
||||||
|
set_fd(fd);
|
||||||
|
set_mode(mode);
|
||||||
|
m_should_close_file_descriptor = should_close;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CFile::open(CIODevice::OpenMode mode)
|
bool CFile::open(CIODevice::OpenMode mode)
|
||||||
{
|
{
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
|
@ -14,8 +14,12 @@ public:
|
||||||
|
|
||||||
virtual bool open(CIODevice::OpenMode) override;
|
virtual bool open(CIODevice::OpenMode) override;
|
||||||
|
|
||||||
|
enum class ShouldCloseFileDescriptor { No = 0, Yes };
|
||||||
|
bool open(int fd, CIODevice::OpenMode, ShouldCloseFileDescriptor);
|
||||||
|
|
||||||
virtual const char* class_name() const override { return "CFile"; }
|
virtual const char* class_name() const override { return "CFile"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_filename;
|
String m_filename;
|
||||||
|
ShouldCloseFileDescriptor m_should_close_file_descriptor { ShouldCloseFileDescriptor::Yes };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue