ART: Replace ScopedFd with FdFile
FdFile can now be used like ScopedFd. Remove ScopedFd.
Bug: 21192156
Test: m test-art-host
Test: m test-art-target (shamu)
Change-Id: I32115fa8b2b8bb5aa5d1886eae63522f80ce836b
diff --git a/runtime/base/file_magic.cc b/runtime/base/file_magic.cc
index 9756338..de6f423 100644
--- a/runtime/base/file_magic.cc
+++ b/runtime/base/file_magic.cc
@@ -21,27 +21,28 @@
#include <sys/types.h>
#include "base/logging.h"
+#include "base/unix_file/fd_file.h"
#include "dex_file.h"
#include "stringprintf.h"
namespace art {
-ScopedFd OpenAndReadMagic(const char* filename, uint32_t* magic, std::string* error_msg) {
+File OpenAndReadMagic(const char* filename, uint32_t* magic, std::string* error_msg) {
CHECK(magic != nullptr);
- ScopedFd fd(open(filename, O_RDONLY, 0));
- if (fd.get() == -1) {
+ File fd(filename, O_RDONLY, /* check_usage */ false);
+ if (fd.Fd() == -1) {
*error_msg = StringPrintf("Unable to open '%s' : %s", filename, strerror(errno));
- return ScopedFd();
+ return File();
}
- int n = TEMP_FAILURE_RETRY(read(fd.get(), magic, sizeof(*magic)));
+ int n = TEMP_FAILURE_RETRY(read(fd.Fd(), magic, sizeof(*magic)));
if (n != sizeof(*magic)) {
*error_msg = StringPrintf("Failed to find magic in '%s'", filename);
- return ScopedFd();
+ return File();
}
- if (lseek(fd.get(), 0, SEEK_SET) != 0) {
+ if (lseek(fd.Fd(), 0, SEEK_SET) != 0) {
*error_msg = StringPrintf("Failed to seek to beginning of file '%s' : %s", filename,
strerror(errno));
- return ScopedFd();
+ return File();
}
return fd;
}
diff --git a/runtime/base/file_magic.h b/runtime/base/file_magic.h
index f7e4bad..4b5d2f5 100644
--- a/runtime/base/file_magic.h
+++ b/runtime/base/file_magic.h
@@ -20,12 +20,12 @@
#include <stdint.h>
#include <string>
-#include "ScopedFd.h"
+#include "os.h"
namespace art {
// Open file and read magic number
-ScopedFd OpenAndReadMagic(const char* filename, uint32_t* magic, std::string* error_msg);
+File OpenAndReadMagic(const char* filename, uint32_t* magic, std::string* error_msg);
// Check whether the given magic matches a known file type.
bool IsZipMagic(uint32_t magic);