Add a Release method for file wrapper 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 <peah@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31183}
diff --git a/rtc_base/system/file_wrapper.cc b/rtc_base/system/file_wrapper.cc index 5409d74..2828790 100644 --- a/rtc_base/system/file_wrapper.cc +++ b/rtc_base/system/file_wrapper.cc
@@ -118,4 +118,10 @@ 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 63d1c17..24c333a 100644 --- a/rtc_base/system/file_wrapper.h +++ b/rtc_base/system/file_wrapper.h
@@ -66,6 +66,12 @@ // 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();