diff --git a/LibCore/CFile.cpp b/LibCore/CFile.cpp index fa6c0d6a8d..47cee94f15 100644 --- a/LibCore/CFile.cpp +++ b/LibCore/CFile.cpp @@ -10,10 +10,18 @@ CFile::CFile(const String& filename) CFile::~CFile() { - if (mode() != NotOpen) + if (m_should_close_file_descriptor == ShouldCloseFileDescriptor::Yes && mode() != NotOpen) 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) { int flags = 0; diff --git a/LibCore/CFile.h b/LibCore/CFile.h index bbccf790f6..a78c850fe3 100644 --- a/LibCore/CFile.h +++ b/LibCore/CFile.h @@ -14,8 +14,12 @@ public: 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"; } private: String m_filename; + ShouldCloseFileDescriptor m_should_close_file_descriptor { ShouldCloseFileDescriptor::Yes }; };