Index: runtime/bin/file_win.cc |
diff --git a/runtime/bin/file_win.cc b/runtime/bin/file_win.cc |
index 87734a9e20321420081b64ab2767154d3fd203d7..766cbd176f903f32396e2794448daf555907a28b 100644 |
--- a/runtime/bin/file_win.cc |
+++ b/runtime/bin/file_win.cc |
@@ -7,13 +7,13 @@ |
#include "bin/file.h" |
+#include <WinIoCtl.h> // NOLINT |
#include <fcntl.h> // NOLINT |
#include <io.h> // NOLINT |
#include <stdio.h> // NOLINT |
#include <string.h> // NOLINT |
#include <sys/stat.h> // NOLINT |
#include <sys/utime.h> // NOLINT |
-#include <WinIoCtl.h> // NOLINT |
#include "bin/builtin.h" |
#include "bin/log.h" |
@@ -37,7 +37,6 @@ class FileHandle { |
DISALLOW_COPY_AND_ASSIGN(FileHandle); |
}; |
- |
File::~File() { |
if (!IsClosed() && handle_->fd() != _fileno(stdout) && |
handle_->fd() != _fileno(stderr)) { |
@@ -46,7 +45,6 @@ File::~File() { |
delete handle_; |
} |
- |
void File::Close() { |
ASSERT(handle_->fd() >= 0); |
int closing_fd = handle_->fd(); |
@@ -64,17 +62,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(File::MapType type, int64_t position, int64_t length) { |
DWORD prot_alloc; |
DWORD prot_final; |
@@ -114,7 +109,6 @@ MappedMemory* File::Map(File::MapType type, int64_t position, int64_t length) { |
return new MappedMemory(addr, length); |
} |
- |
void MappedMemory::Unmap() { |
BOOL result = VirtualFree(address_, 0, MEM_RELEASE); |
ASSERT(result); |
@@ -122,13 +116,11 @@ void MappedMemory::Unmap() { |
size_ = 0; |
} |
- |
int64_t File::Read(void* buffer, int64_t num_bytes) { |
ASSERT(handle_->fd() >= 0); |
return read(handle_->fd(), buffer, num_bytes); |
} |
- |
int64_t File::Write(const void* buffer, int64_t num_bytes) { |
int fd = handle_->fd(); |
ASSERT(fd >= 0); |
@@ -161,7 +153,6 @@ int64_t File::Write(const void* buffer, int64_t num_bytes) { |
return bytes_written; |
} |
- |
bool File::VPrint(const char* format, va_list args) { |
// Measure. |
va_list measure_args; |
@@ -182,31 +173,26 @@ bool File::VPrint(const char* format, va_list args) { |
return result; |
} |
- |
int64_t File::Position() { |
ASSERT(handle_->fd() >= 0); |
return _lseeki64(handle_->fd(), 0, SEEK_CUR); |
} |
- |
bool File::SetPosition(int64_t position) { |
ASSERT(handle_->fd() >= 0); |
return _lseeki64(handle_->fd(), position, SEEK_SET) >= 0; |
} |
- |
bool File::Truncate(int64_t length) { |
ASSERT(handle_->fd() >= 0); |
return _chsize_s(handle_->fd(), length) == 0; |
} |
- |
bool File::Flush() { |
ASSERT(handle_->fd()); |
return _commit(handle_->fd()) != -1; |
} |
- |
bool File::Lock(File::LockType lock, int64_t start, int64_t end) { |
ASSERT(handle_->fd() >= 0); |
ASSERT((end == -1) || (end > start)); |
@@ -250,7 +236,6 @@ bool File::Lock(File::LockType lock, int64_t start, int64_t end) { |
return rc; |
} |
- |
int64_t File::Length() { |
ASSERT(handle_->fd() >= 0); |
struct __stat64 st; |
@@ -260,7 +245,6 @@ int64_t File::Length() { |
return -1; |
} |
- |
File* File::FileOpenW(const wchar_t* system_name, FileOpenMode mode) { |
int flags = O_RDONLY | O_BINARY | O_NOINHERIT; |
if ((mode & kWrite) != 0) { |
@@ -288,14 +272,12 @@ File* File::FileOpenW(const wchar_t* system_name, FileOpenMode mode) { |
return new File(new FileHandle(fd)); |
} |
- |
File* File::Open(const char* path, FileOpenMode mode) { |
Utf8ToWideScope system_name(path); |
File* file = FileOpenW(system_name.wide(), mode); |
return file; |
} |
- |
File* File::OpenStdio(int fd) { |
int stdio_fd = -1; |
switch (fd) { |
@@ -312,7 +294,6 @@ File* File::OpenStdio(int fd) { |
return new File(new FileHandle(stdio_fd)); |
} |
- |
static bool StatHelper(wchar_t* path, struct __stat64* st) { |
int stat_status = _wstat64(path, st); |
if (stat_status != 0) { |
@@ -325,14 +306,12 @@ static bool StatHelper(wchar_t* path, struct __stat64* st) { |
return true; |
} |
- |
bool File::Exists(const char* name) { |
struct __stat64 st; |
Utf8ToWideScope system_name(name); |
return StatHelper(system_name.wide(), &st); |
} |
- |
bool File::Create(const char* name) { |
Utf8ToWideScope system_name(name); |
int fd = _wopen(system_name.wide(), O_RDONLY | O_CREAT, 0666); |
@@ -342,7 +321,6 @@ bool File::Create(const char* name) { |
return (close(fd) == 0); |
} |
- |
// This structure is needed for creating and reading Junctions. |
typedef struct _REPARSE_DATA_BUFFER { |
ULONG ReparseTag; |
@@ -373,11 +351,9 @@ typedef struct _REPARSE_DATA_BUFFER { |
}; |
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; |
- |
static const int kReparseDataHeaderSize = sizeof ULONG + 2 * sizeof USHORT; |
static const int kMountPointHeaderSize = 4 * sizeof USHORT; |
- |
bool File::CreateLink(const char* utf8_name, const char* utf8_target) { |
Utf8ToWideScope name(utf8_name); |
int create_status = CreateDirectoryW(name.wide(), NULL); |
@@ -435,14 +411,12 @@ bool File::CreateLink(const char* utf8_name, const char* utf8_target) { |
return (result != 0); |
} |
- |
bool File::Delete(const char* name) { |
Utf8ToWideScope system_name(name); |
int status = _wremove(system_name.wide()); |
return status != -1; |
} |
- |
bool File::DeleteLink(const char* name) { |
Utf8ToWideScope system_name(name); |
bool result = false; |
@@ -457,7 +431,6 @@ bool File::DeleteLink(const char* name) { |
return result; |
} |
- |
bool File::Rename(const char* old_path, const char* new_path) { |
File::Type type = GetType(old_path, false); |
if (type == kIsFile) { |
@@ -473,7 +446,6 @@ bool File::Rename(const char* old_path, const char* new_path) { |
return false; |
} |
- |
bool File::RenameLink(const char* old_path, const char* new_path) { |
File::Type type = GetType(old_path, false); |
if (type == kIsLink) { |
@@ -489,7 +461,6 @@ bool File::RenameLink(const char* old_path, const char* new_path) { |
return false; |
} |
- |
bool File::Copy(const char* old_path, const char* new_path) { |
File::Type type = GetType(old_path, false); |
if (type == kIsFile) { |
@@ -504,7 +475,6 @@ bool File::Copy(const char* old_path, const char* new_path) { |
return false; |
} |
- |
int64_t File::LengthFromPath(const char* name) { |
struct __stat64 st; |
Utf8ToWideScope system_name(name); |
@@ -514,7 +484,6 @@ int64_t File::LengthFromPath(const char* name) { |
return st.st_size; |
} |
- |
const char* File::LinkTarget(const char* pathname) { |
const wchar_t* name = StringUtilsWin::Utf8ToWide(pathname); |
HANDLE dir_handle = CreateFileW( |
@@ -578,7 +547,6 @@ const char* File::LinkTarget(const char* pathname) { |
return utf8_target; |
} |
- |
void File::Stat(const char* name, int64_t* data) { |
File::Type type = GetType(name, false); |
data[kType] = type; |
@@ -598,7 +566,6 @@ void File::Stat(const char* name, int64_t* data) { |
} |
} |
- |
time_t File::LastAccessed(const char* name) { |
struct __stat64 st; |
Utf8ToWideScope system_name(name); |
@@ -608,7 +575,6 @@ time_t File::LastAccessed(const char* name) { |
return st.st_atime; |
} |
- |
time_t File::LastModified(const char* name) { |
struct __stat64 st; |
Utf8ToWideScope system_name(name); |
@@ -618,7 +584,6 @@ time_t File::LastModified(const char* name) { |
return st.st_mtime; |
} |
- |
bool File::SetLastAccessed(const char* name, int64_t millis) { |
// First get the current times. |
struct __stat64 st; |
@@ -634,7 +599,6 @@ bool File::SetLastAccessed(const char* name, int64_t millis) { |
return _wutime64(system_name.wide(), ×) == 0; |
} |
- |
bool File::SetLastModified(const char* name, int64_t millis) { |
// First get the current times. |
struct __stat64 st; |
@@ -650,7 +614,6 @@ bool File::SetLastModified(const char* name, int64_t millis) { |
return _wutime64(system_name.wide(), ×) == 0; |
} |
- |
bool File::IsAbsolutePath(const char* pathname) { |
// Should we consider network paths? |
if (pathname == NULL) { |
@@ -660,7 +623,6 @@ bool File::IsAbsolutePath(const char* pathname) { |
((pathname[2] == '\\') || (pathname[2] == '/'))); |
} |
- |
const char* File::GetCanonicalPath(const char* pathname) { |
Utf8ToWideScope system_name(pathname); |
HANDLE file_handle = |
@@ -697,26 +659,22 @@ const char* File::GetCanonicalPath(const char* pathname) { |
return result; |
} |
- |
const char* File::PathSeparator() { |
// This is already UTF-8 encoded. |
return "\\"; |
} |
- |
const char* File::StringEscapedPathSeparator() { |
// This is already UTF-8 encoded. |
return "\\\\"; |
} |
- |
File::StdioHandleType File::GetStdioHandleType(int fd) { |
// Treat all stdio handles as pipes. The Windows event handler and |
// socket code will handle the different handle types. |
return kPipe; |
} |
- |
File::Type File::GetType(const char* pathname, bool follow_links) { |
// Convert to wchar_t string. |
Utf8ToWideScope name(pathname); |
@@ -745,7 +703,6 @@ File::Type File::GetType(const char* pathname, bool follow_links) { |
return result; |
} |
- |
File::Identical File::AreIdentical(const char* file_1, const char* file_2) { |
BY_HANDLE_FILE_INFORMATION file_info[2]; |
const char* file_names[2] = {file_1, file_2}; |