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}
This commit is contained in:
Per Åhgren 2020-05-07 15:58:55 +02:00 committed by Commit Bot
parent 3b6afeeed0
commit b8a9630e9e
2 changed files with 12 additions and 0 deletions

View File

@ -118,4 +118,10 @@ bool FileWrapper::Close() {
return success;
}
FILE* FileWrapper::Release() {
FILE* file = file_;
file_ = nullptr;
return file;
}
} // namespace webrtc

View File

@ -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();