diff options
author | Timothy <timmot@users.noreply.github.com> | 2021-07-04 14:42:51 +1000 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-04 11:44:47 +0430 |
commit | 60f84f3154300ecf85f118f837d01d8f918eaa46 (patch) | |
tree | 71e28d128e2daff8fde3bde918a983ac6f512846 /Userland/Libraries | |
parent | 2ef28602ba512ca12f6dfeb61ad188eb1c899729 (diff) | |
download | serenity-60f84f3154300ecf85f118f837d01d8f918eaa46.zip |
LibCore: Add method to leak fd from File
This will let other code use the fd while making sure the fd isn't
automatically closed by Core::File's destructor
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibCore/File.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/File.h | 1 |
2 files changed, 7 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/File.cpp b/Userland/Libraries/LibCore/File.cpp index a8e62d05a0..0f30a995cb 100644 --- a/Userland/Libraries/LibCore/File.cpp +++ b/Userland/Libraries/LibCore/File.cpp @@ -92,6 +92,12 @@ bool File::open_impl(OpenMode mode, mode_t permissions) return true; } +int File::leak_fd() +{ + m_should_close_file_descriptor = ShouldCloseFileDescriptor::No; + return fd(); +} + bool File::is_device() const { struct stat stat; diff --git a/Userland/Libraries/LibCore/File.h b/Userland/Libraries/LibCore/File.h index 5ce8161ae8..cb81920d1d 100644 --- a/Userland/Libraries/LibCore/File.h +++ b/Userland/Libraries/LibCore/File.h @@ -74,6 +74,7 @@ public: Yes }; bool open(int fd, OpenMode, ShouldCloseFileDescriptor); + [[nodiscard]] int leak_fd(); static NonnullRefPtr<File> standard_input(); static NonnullRefPtr<File> standard_output(); |