diff options
Diffstat (limited to 'otafault/ota_io.cpp')
-rw-r--r-- | otafault/ota_io.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/otafault/ota_io.cpp b/otafault/ota_io.cpp index 2efd3004a..f5b01136f 100644 --- a/otafault/ota_io.cpp +++ b/otafault/ota_io.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include <map> +#include "ota_io.h" #include <errno.h> #include <fcntl.h> @@ -22,8 +22,10 @@ #include <sys/stat.h> #include <unistd.h> +#include <map> +#include <memory> + #include "config.h" -#include "ota_io.h" static std::map<intptr_t, const char*> filename_cache; static std::string read_fault_file_name = ""; @@ -68,17 +70,33 @@ 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); } -int ota_fclose(FILE* fh) { - filename_cache.erase((intptr_t)fh); +void OtaCloser::Close(int fd) { + __ota_close(fd); +} + +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); } +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) { if (should_fault_inject(OTAIO_READ)) { auto cached = filename_cache.find((intptr_t)stream); |