Remove ota_close(int) and ota_fclose(FILE*).
We should always use unique_fd or unique_file to hold the FD or FILE*
pointer when opening via ota_(f)open functions.
This CL avoids accidentally closing raw FDs or FILE* pointers that are
managed by unique_fd/unique_file.
Test: recovery_component_test passes.
Change-Id: If58eb8b5c5da507563f85efd5d56276472a1c957
diff --git a/otafault/ota_io.cpp b/otafault/ota_io.cpp
index 874cb1d..f5b0113 100644
--- a/otafault/ota_io.cpp
+++ b/otafault/ota_io.cpp
@@ -70,23 +70,31 @@
return fh;
}
-int ota_close(int fd) {
+static int __ota_close(int fd) {
// descriptors can be reused, so make sure not to leave them in the cache
filename_cache.erase(fd);
return close(fd);
}
-int ota_close(unique_fd& fd) {
- return ota_close(fd.release());
+void OtaCloser::Close(int fd) {
+ __ota_close(fd);
}
-int ota_fclose(FILE* fh) {
- filename_cache.erase((intptr_t)fh);
+int ota_close(unique_fd& fd) {
+ return __ota_close(fd.release());
+}
+
+static int __ota_fclose(FILE* fh) {
+ filename_cache.erase(reinterpret_cast<intptr_t>(fh));
return fclose(fh);
}
-int ota_fclose(std::unique_ptr<FILE, int (*)(FILE*)>& fh) {
- return ota_fclose(fh.release());
+void OtaFcloser::operator()(FILE* f) {
+ __ota_fclose(f);
+};
+
+int ota_fclose(unique_file& fh) {
+ return __ota_fclose(fh.release());
}
size_t ota_fread(void* ptr, size_t size, size_t nitems, FILE* stream) {