From b8a9630e9e23826464f74893c1d0d78d61839b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Thu, 7 May 2020 15:58:55 +0200 Subject: [PATCH] Add a Release method for file wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL adds a Release method for the FileWrapper class that allows it to release the wrapped FILE* object without closing it. Bug: b/155316201 Change-Id: If9ef4345724705dc7c66183f17bd8daadbdd00b6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174720 Commit-Queue: Per Ã…hgren Reviewed-by: Karl Wiberg Reviewed-by: Mirko Bonadei Reviewed-by: Niels Moller Cr-Commit-Position: refs/heads/master@{#31183} --- rtc_base/system/file_wrapper.cc | 6 ++++++ rtc_base/system/file_wrapper.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/rtc_base/system/file_wrapper.cc b/rtc_base/system/file_wrapper.cc index 5409d74ef6..2828790e09 100644 --- a/rtc_base/system/file_wrapper.cc +++ b/rtc_base/system/file_wrapper.cc @@ -118,4 +118,10 @@ bool FileWrapper::Close() { return success; } +FILE* FileWrapper::Release() { + FILE* file = file_; + file_ = nullptr; + return file; +} + } // namespace webrtc diff --git a/rtc_base/system/file_wrapper.h b/rtc_base/system/file_wrapper.h index 63d1c17c11..24c333a6c3 100644 --- a/rtc_base/system/file_wrapper.h +++ b/rtc_base/system/file_wrapper.h @@ -66,6 +66,12 @@ class FileWrapper final { // Calling Close on an already closed file does nothing and returns success. bool Close(); + // Releases and returns the wrapped file without closing it. This call passes + // the ownership of the file to the caller, and the wrapper is no longer + // responsible for closing it. Similarly the previously wrapped file is no + // longer available for the wrapper to use in any aspect. + FILE* Release(); + // Write any buffered data to the underlying file. Returns true on success, // false on write error. Note: Flushing when closing, is not required. bool Flush();