Index: runtime/bin/file_linux.cc |
diff --git a/runtime/bin/file_linux.cc b/runtime/bin/file_linux.cc |
index ee6765731105db61bc6d2a5c954bc6e719295d2e..7e966ce2640587e9dc620e1ba797df0cbccb8f92 100644 |
--- a/runtime/bin/file_linux.cc |
+++ b/runtime/bin/file_linux.cc |
@@ -39,7 +39,6 @@ class FileHandle { |
DISALLOW_COPY_AND_ASSIGN(FileHandle); |
}; |
- |
File::~File() { |
if (!IsClosed() && handle_->fd() != STDOUT_FILENO && |
handle_->fd() != STDERR_FILENO) { |
@@ -48,7 +47,6 @@ File::~File() { |
delete handle_; |
} |
- |
void File::Close() { |
ASSERT(handle_->fd() >= 0); |
if (handle_->fd() == STDOUT_FILENO) { |
@@ -68,17 +66,14 @@ void File::Close() { |
handle_->set_fd(kClosedFd); |
} |
- |
intptr_t File::GetFD() { |
return handle_->fd(); |
} |
- |
bool File::IsClosed() { |
return handle_->fd() == kClosedFd; |
} |
- |
MappedMemory* File::Map(MapType type, int64_t position, int64_t length) { |
ASSERT(handle_->fd() >= 0); |
ASSERT(length > 0); |
@@ -100,7 +95,6 @@ MappedMemory* File::Map(MapType type, int64_t position, int64_t length) { |
return new MappedMemory(addr, length); |
} |
- |
void MappedMemory::Unmap() { |
int result = munmap(address_, size_); |
ASSERT(result == 0); |
@@ -108,19 +102,16 @@ void MappedMemory::Unmap() { |
size_ = 0; |
} |
- |
int64_t File::Read(void* buffer, int64_t num_bytes) { |
ASSERT(handle_->fd() >= 0); |
return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
} |
- |
int64_t File::Write(const void* buffer, int64_t num_bytes) { |
ASSERT(handle_->fd() >= 0); |
return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); |
} |
- |
bool File::VPrint(const char* format, va_list args) { |
// Measure. |
va_list measure_args; |
@@ -146,25 +137,21 @@ int64_t File::Position() { |
return NO_RETRY_EXPECTED(lseek64(handle_->fd(), 0, SEEK_CUR)); |
} |
- |
bool File::SetPosition(int64_t position) { |
ASSERT(handle_->fd() >= 0); |
return NO_RETRY_EXPECTED(lseek64(handle_->fd(), position, SEEK_SET)) >= 0; |
} |
- |
bool File::Truncate(int64_t length) { |
ASSERT(handle_->fd() >= 0); |
return TEMP_FAILURE_RETRY(ftruncate64(handle_->fd(), length) != -1); |
} |
- |
bool File::Flush() { |
ASSERT(handle_->fd() >= 0); |
return NO_RETRY_EXPECTED(fsync(handle_->fd())) != -1; |
} |
- |
bool File::Lock(File::LockType lock, int64_t start, int64_t end) { |
ASSERT(handle_->fd() >= 0); |
ASSERT((end == -1) || (end > start)); |
@@ -195,7 +182,6 @@ bool File::Lock(File::LockType lock, int64_t start, int64_t end) { |
return TEMP_FAILURE_RETRY(fcntl(handle_->fd(), cmd, &fl)) != -1; |
} |
- |
int64_t File::Length() { |
ASSERT(handle_->fd() >= 0); |
struct stat64 st; |
@@ -205,13 +191,11 @@ int64_t File::Length() { |
return -1; |
} |
- |
File* File::FileOpenW(const wchar_t* system_name, FileOpenMode mode) { |
UNREACHABLE(); |
return NULL; |
} |
- |
File* File::Open(const char* name, FileOpenMode mode) { |
// Report errors for non-regular files. |
struct stat64 st; |
@@ -249,12 +233,10 @@ File* File::Open(const char* name, FileOpenMode mode) { |
return new File(new FileHandle(fd)); |
} |
- |
File* File::OpenStdio(int fd) { |
return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); |
} |
- |
bool File::Exists(const char* name) { |
struct stat64 st; |
if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { |
@@ -265,7 +247,6 @@ bool File::Exists(const char* name) { |
} |
} |
- |
bool File::Create(const char* name) { |
int fd = |
TEMP_FAILURE_RETRY(open64(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666)); |
@@ -290,12 +271,10 @@ bool File::Create(const char* name) { |
return is_file; |
} |
- |
bool File::CreateLink(const char* name, const char* target) { |
return NO_RETRY_EXPECTED(symlink(target, name)) == 0; |
} |
- |
File::Type File::GetType(const char* pathname, bool follow_links) { |
struct stat64 entry_info; |
int stat_success; |
@@ -319,7 +298,6 @@ File::Type File::GetType(const char* pathname, bool follow_links) { |
return File::kDoesNotExist; |
} |
- |
static bool CheckTypeAndSetErrno(const char* name, |
File::Type expected, |
bool follow_links) { |
@@ -341,31 +319,26 @@ static bool CheckTypeAndSetErrno(const char* name, |
return false; |
} |
- |
bool File::Delete(const char* name) { |
return CheckTypeAndSetErrno(name, kIsFile, true) && |
(NO_RETRY_EXPECTED(unlink(name)) == 0); |
} |
- |
bool File::DeleteLink(const char* name) { |
return CheckTypeAndSetErrno(name, kIsLink, false) && |
(NO_RETRY_EXPECTED(unlink(name)) == 0); |
} |
- |
bool File::Rename(const char* old_path, const char* new_path) { |
return CheckTypeAndSetErrno(old_path, kIsFile, true) && |
(NO_RETRY_EXPECTED(rename(old_path, new_path)) == 0); |
} |
- |
bool File::RenameLink(const char* old_path, const char* new_path) { |
return CheckTypeAndSetErrno(old_path, kIsLink, false) && |
(NO_RETRY_EXPECTED(rename(old_path, new_path)) == 0); |
} |
- |
bool File::Copy(const char* old_path, const char* new_path) { |
if (!CheckTypeAndSetErrno(old_path, kIsFile, true)) { |
return false; |
@@ -416,7 +389,6 @@ bool File::Copy(const char* old_path, const char* new_path) { |
return true; |
} |
- |
static bool StatHelper(const char* name, struct stat64* st) { |
if (TEMP_FAILURE_RETRY(stat64(name, st)) != 0) { |
return false; |
@@ -430,7 +402,6 @@ static bool StatHelper(const char* name, struct stat64* st) { |
return true; |
} |
- |
int64_t File::LengthFromPath(const char* name) { |
struct stat64 st; |
if (!StatHelper(name, &st)) { |
@@ -439,13 +410,11 @@ int64_t File::LengthFromPath(const char* name) { |
return st.st_size; |
} |
- |
static int64_t TimespecToMilliseconds(const struct timespec& t) { |
return static_cast<int64_t>(t.tv_sec) * 1000L + |
static_cast<int64_t>(t.tv_nsec) / 1000000L; |
} |
- |
void File::Stat(const char* name, int64_t* data) { |
struct stat64 st; |
if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { |
@@ -468,7 +437,6 @@ void File::Stat(const char* name, int64_t* data) { |
} |
} |
- |
time_t File::LastModified(const char* name) { |
struct stat64 st; |
if (!StatHelper(name, &st)) { |
@@ -477,7 +445,6 @@ time_t File::LastModified(const char* name) { |
return st.st_mtime; |
} |
- |
time_t File::LastAccessed(const char* name) { |
struct stat64 st; |
if (!StatHelper(name, &st)) { |
@@ -486,7 +453,6 @@ time_t File::LastAccessed(const char* name) { |
return st.st_atime; |
} |
- |
bool File::SetLastAccessed(const char* name, int64_t millis) { |
// First get the current times. |
struct stat64 st; |
@@ -501,7 +467,6 @@ bool File::SetLastAccessed(const char* name, int64_t millis) { |
return utime(name, ×) == 0; |
} |
- |
bool File::SetLastModified(const char* name, int64_t millis) { |
// First get the current times. |
struct stat64 st; |
@@ -516,7 +481,6 @@ bool File::SetLastModified(const char* name, int64_t millis) { |
return utime(name, ×) == 0; |
} |
- |
const char* File::LinkTarget(const char* pathname) { |
struct stat64 link_stats; |
if (TEMP_FAILURE_RETRY(lstat64(pathname, &link_stats)) != 0) { |
@@ -543,12 +507,10 @@ const char* File::LinkTarget(const char* pathname) { |
return target_name; |
} |
- |
bool File::IsAbsolutePath(const char* pathname) { |
return (pathname != NULL && pathname[0] == '/'); |
} |
- |
const char* File::GetCanonicalPath(const char* pathname) { |
char* abs_path = NULL; |
if (pathname != NULL) { |
@@ -563,17 +525,14 @@ const char* File::GetCanonicalPath(const char* pathname) { |
return abs_path; |
} |
- |
const char* File::PathSeparator() { |
return "/"; |
} |
- |
const char* File::StringEscapedPathSeparator() { |
return "/"; |
} |
- |
File::StdioHandleType File::GetStdioHandleType(int fd) { |
ASSERT((0 <= fd) && (fd <= 2)); |
struct stat64 buf; |
@@ -596,7 +555,6 @@ File::StdioHandleType File::GetStdioHandleType(int fd) { |
return kOther; |
} |
- |
File::Identical File::AreIdentical(const char* file_1, const char* file_2) { |
struct stat64 file_1_info; |
struct stat64 file_2_info; |