summaryrefslogtreecommitdiffstats
path: root/otafault
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-29 06:35:38 +0100
committerandroid-build-merger <android-build-merger@google.com>2016-11-29 06:35:38 +0100
commit8da96cb392290653bf47db457b2a1b05c2898e03 (patch)
tree41ce3c957eaf82c865e3dc2ad7cc9861804ebc56 /otafault
parentMerge "tests: Add testcases for EMMC targets." am: d226f28e87 am: fcfdda98da am: 5e52ac31d4 (diff)
parentMerge "Add ota_close(unique_fd&) and ota_fclose(std::unique_ptr<FILE>&)." am: eed7f607cf am: 839fbbdad3 (diff)
downloadandroid_bootable_recovery-8da96cb392290653bf47db457b2a1b05c2898e03.tar
android_bootable_recovery-8da96cb392290653bf47db457b2a1b05c2898e03.tar.gz
android_bootable_recovery-8da96cb392290653bf47db457b2a1b05c2898e03.tar.bz2
android_bootable_recovery-8da96cb392290653bf47db457b2a1b05c2898e03.tar.lz
android_bootable_recovery-8da96cb392290653bf47db457b2a1b05c2898e03.tar.xz
android_bootable_recovery-8da96cb392290653bf47db457b2a1b05c2898e03.tar.zst
android_bootable_recovery-8da96cb392290653bf47db457b2a1b05c2898e03.zip
Diffstat (limited to '')
-rw-r--r--otafault/ota_io.cpp14
-rw-r--r--otafault/ota_io.h6
2 files changed, 18 insertions, 2 deletions
diff --git a/otafault/ota_io.cpp b/otafault/ota_io.cpp
index 2efd3004a..874cb1d5c 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 = "";
@@ -74,11 +76,19 @@ int ota_close(int fd) {
return close(fd);
}
+int ota_close(unique_fd& fd) {
+ return ota_close(fd.release());
+}
+
int ota_fclose(FILE* fh) {
filename_cache.erase((intptr_t)fh);
return fclose(fh);
}
+int ota_fclose(std::unique_ptr<FILE, int (*)(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);
diff --git a/otafault/ota_io.h b/otafault/ota_io.h
index e119eef08..45d17b1bb 100644
--- a/otafault/ota_io.h
+++ b/otafault/ota_io.h
@@ -26,6 +26,8 @@
#include <stdio.h>
#include <sys/stat.h>
+#include <memory>
+
#include <android-base/unique_fd.h>
#define OTAIO_CACHE_FNAME "/cache/saved.file"
@@ -60,4 +62,8 @@ struct OtaCloser {
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);
+
#endif