diff options
author | Tao Bao <tbao@google.com> | 2016-11-29 19:04:12 +0100 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-11-29 19:04:12 +0100 |
commit | 8762a560fcc841a44bd571ce51f9d0e2f985cb6d (patch) | |
tree | 073af2fb4db947ed990c3184da780e028a032b98 /otafault | |
parent | Merge "Add ota_close(unique_fd&) and ota_fclose(std::unique_ptr<FILE>&)." am: eed7f607cf (diff) | |
parent | Merge "Remove ota_close(int) and ota_fclose(FILE*)." (diff) | |
download | android_bootable_recovery-8762a560fcc841a44bd571ce51f9d0e2f985cb6d.tar android_bootable_recovery-8762a560fcc841a44bd571ce51f9d0e2f985cb6d.tar.gz android_bootable_recovery-8762a560fcc841a44bd571ce51f9d0e2f985cb6d.tar.bz2 android_bootable_recovery-8762a560fcc841a44bd571ce51f9d0e2f985cb6d.tar.lz android_bootable_recovery-8762a560fcc841a44bd571ce51f9d0e2f985cb6d.tar.xz android_bootable_recovery-8762a560fcc841a44bd571ce51f9d0e2f985cb6d.tar.zst android_bootable_recovery-8762a560fcc841a44bd571ce51f9d0e2f985cb6d.zip |
Diffstat (limited to 'otafault')
-rw-r--r-- | otafault/ota_io.cpp | 20 | ||||
-rw-r--r-- | otafault/ota_io.h | 16 |
2 files changed, 22 insertions, 14 deletions
diff --git a/otafault/ota_io.cpp b/otafault/ota_io.cpp index 874cb1d5c..f5b01136f 100644 --- a/otafault/ota_io.cpp +++ b/otafault/ota_io.cpp @@ -70,23 +70,31 @@ FILE* ota_fopen(const char* path, const char* mode) { 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); } +void OtaCloser::Close(int fd) { + __ota_close(fd); +} + int ota_close(unique_fd& fd) { - return ota_close(fd.release()); + return __ota_close(fd.release()); } -int ota_fclose(FILE* fh) { - filename_cache.erase((intptr_t)fh); +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) { diff --git a/otafault/ota_io.h b/otafault/ota_io.h index 45d17b1bb..395b4230e 100644 --- a/otafault/ota_io.h +++ b/otafault/ota_io.h @@ -40,10 +40,6 @@ int ota_open(const char* path, int oflags, mode_t mode); FILE* ota_fopen(const char* filename, const char* mode); -int ota_close(int fd); - -int ota_fclose(FILE* fh); - size_t ota_fread(void* ptr, size_t size, size_t nitems, FILE* stream); ssize_t ota_read(int fd, void* buf, size_t nbyte); @@ -55,15 +51,19 @@ ssize_t ota_write(int fd, const void* buf, size_t nbyte); int ota_fsync(int fd); struct OtaCloser { - static void Close(int fd) { - ota_close(fd); - } + static void Close(int); }; using unique_fd = android::base::unique_fd_impl<OtaCloser>; int ota_close(unique_fd& fd); -int ota_fclose(std::unique_ptr<FILE, int (*)(FILE*)>& fh); +struct OtaFcloser { + void operator()(FILE*); +}; + +using unique_file = std::unique_ptr<FILE, OtaFcloser>; + +int ota_fclose(unique_file& fh); #endif |