Index: runtime/bin/file_macos.cc |
diff --git a/runtime/bin/file_macos.cc b/runtime/bin/file_macos.cc |
index c2015126e22036beb6760c9f862421c59d6dfc7f..1b53cb2c1cfe5280ba64a4fd11000476fae8fecc 100644 |
--- a/runtime/bin/file_macos.cc |
+++ b/runtime/bin/file_macos.cc |
@@ -40,7 +40,6 @@ class FileHandle { |
DISALLOW_COPY_AND_ASSIGN(FileHandle); |
}; |
- |
File::~File() { |
if (!IsClosed() && handle_->fd() != STDOUT_FILENO && |
handle_->fd() != STDERR_FILENO) { |
@@ -49,7 +48,6 @@ File::~File() { |
delete handle_; |
} |
- |
void File::Close() { |
ASSERT(handle_->fd() >= 0); |
if (handle_->fd() == STDOUT_FILENO) { |
@@ -70,17 +68,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); |
@@ -102,7 +97,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); |
@@ -110,19 +104,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; |
@@ -148,25 +139,21 @@ int64_t File::Position() { |
return lseek(handle_->fd(), 0, SEEK_CUR); |
} |
- |
bool File::SetPosition(int64_t position) { |
ASSERT(handle_->fd() >= 0); |
return lseek(handle_->fd(), position, SEEK_SET) >= 0; |
} |
- |
bool File::Truncate(int64_t length) { |
ASSERT(handle_->fd() >= 0); |
return TEMP_FAILURE_RETRY(ftruncate(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)); |
@@ -197,7 +184,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 stat st; |
@@ -207,13 +193,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 stat st; |
@@ -251,12 +235,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 stat st; |
if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
@@ -267,7 +249,6 @@ bool File::Exists(const char* name) { |
} |
} |
- |
bool File::Create(const char* name) { |
int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CREAT, 0666)); |
if (fd < 0) { |
@@ -291,13 +272,11 @@ bool File::Create(const char* name) { |
return is_file; |
} |
- |
bool File::CreateLink(const char* name, const char* target) { |
int status = NO_RETRY_EXPECTED(symlink(target, name)); |
return (status == 0); |
} |
- |
File::Type File::GetType(const char* pathname, bool follow_links) { |
struct stat entry_info; |
int stat_success; |
@@ -321,7 +300,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) { |
@@ -343,37 +321,31 @@ 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) { |
return CheckTypeAndSetErrno(old_path, kIsFile, true) && |
(copyfile(old_path, new_path, NULL, COPYFILE_ALL) == 0); |
} |
- |
static bool StatHelper(const char* name, struct stat* st) { |
if (NO_RETRY_EXPECTED(stat(name, st)) != 0) { |
return false; |
@@ -387,7 +359,6 @@ static bool StatHelper(const char* name, struct stat* st) { |
return true; |
} |
- |
int64_t File::LengthFromPath(const char* name) { |
struct stat st; |
if (!StatHelper(name, &st)) { |
@@ -396,13 +367,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 stat st; |
if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
@@ -428,7 +397,6 @@ void File::Stat(const char* name, int64_t* data) { |
} |
} |
- |
time_t File::LastModified(const char* name) { |
struct stat st; |
if (!StatHelper(name, &st)) { |
@@ -437,7 +405,6 @@ time_t File::LastModified(const char* name) { |
return st.st_mtime; |
} |
- |
time_t File::LastAccessed(const char* name) { |
struct stat st; |
if (!StatHelper(name, &st)) { |
@@ -446,7 +413,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 stat st; |
@@ -461,7 +427,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 stat st; |
@@ -476,7 +441,6 @@ bool File::SetLastModified(const char* name, int64_t millis) { |
return utime(name, ×) == 0; |
} |
- |
const char* File::LinkTarget(const char* pathname) { |
struct stat link_stats; |
if (lstat(pathname, &link_stats) != 0) { |
@@ -502,12 +466,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) { |
@@ -525,17 +487,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 stat buf; |
@@ -558,7 +517,6 @@ File::StdioHandleType File::GetStdioHandleType(int fd) { |
return kOther; |
} |
- |
File::Identical File::AreIdentical(const char* file_1, const char* file_2) { |
struct stat file_1_info; |
struct stat file_2_info; |