| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
| 7 | 7 |
| 8 #include "bin/file.h" | 8 #include "bin/file.h" |
| 9 | 9 |
| 10 #include <fcntl.h> // NOLINT | 10 #include <fcntl.h> // NOLINT |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 return read(handle_->fd(), buffer, num_bytes); | 65 return read(handle_->fd(), buffer, num_bytes); |
| 66 } | 66 } |
| 67 | 67 |
| 68 | 68 |
| 69 int64_t File::Write(const void* buffer, int64_t num_bytes) { | 69 int64_t File::Write(const void* buffer, int64_t num_bytes) { |
| 70 ASSERT(handle_->fd() >= 0); | 70 ASSERT(handle_->fd() >= 0); |
| 71 return write(handle_->fd(), buffer, num_bytes); | 71 return write(handle_->fd(), buffer, num_bytes); |
| 72 } | 72 } |
| 73 | 73 |
| 74 | 74 |
| 75 off_t File::Position() { | 75 off64_t File::Position() { |
| 76 ASSERT(handle_->fd() >= 0); | 76 ASSERT(handle_->fd() >= 0); |
| 77 return lseek(handle_->fd(), 0, SEEK_CUR); | 77 return _lseeki64(handle_->fd(), 0, SEEK_CUR); |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 bool File::SetPosition(int64_t position) { | 81 bool File::SetPosition(off64_t position) { |
| 82 ASSERT(handle_->fd() >= 0); | 82 ASSERT(handle_->fd() >= 0); |
| 83 return (lseek(handle_->fd(), position, SEEK_SET) != -1); | 83 return _lseeki64(handle_->fd(), position, SEEK_SET) >= 0; |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 bool File::Truncate(int64_t length) { | 87 bool File::Truncate(off64_t length) { |
| 88 ASSERT(handle_->fd() >= 0); | 88 ASSERT(handle_->fd() >= 0); |
| 89 return (chsize(handle_->fd(), length) != -1); | 89 return (_chsize_s(handle_->fd(), length) != -1); |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 bool File::Flush() { | 93 bool File::Flush() { |
| 94 ASSERT(handle_->fd()); | 94 ASSERT(handle_->fd()); |
| 95 return _commit(handle_->fd()) != -1; | 95 return _commit(handle_->fd()) != -1; |
| 96 } | 96 } |
| 97 | 97 |
| 98 | 98 |
| 99 off_t File::Length() { | 99 off64_t File::Length() { |
| 100 ASSERT(handle_->fd() >= 0); | 100 ASSERT(handle_->fd() >= 0); |
| 101 struct stat st; | 101 struct __stat64 st; |
| 102 if (fstat(handle_->fd(), &st) == 0) { | 102 if (_fstat64(handle_->fd(), &st) == 0) { |
| 103 return st.st_size; | 103 return st.st_size; |
| 104 } | 104 } |
| 105 return -1; | 105 return -1; |
| 106 } | 106 } |
| 107 | 107 |
| 108 | 108 |
| 109 File* File::Open(const char* name, FileOpenMode mode) { | 109 File* File::Open(const char* name, FileOpenMode mode) { |
| 110 int flags = O_RDONLY | O_BINARY | O_NOINHERIT; | 110 int flags = O_RDONLY | O_BINARY | O_NOINHERIT; |
| 111 if ((mode & kWrite) != 0) { | 111 if ((mode & kWrite) != 0) { |
| 112 flags = (O_RDWR | O_CREAT | O_BINARY | O_NOINHERIT); | 112 flags = (O_RDWR | O_CREAT | O_BINARY | O_NOINHERIT); |
| 113 } | 113 } |
| 114 if ((mode & kTruncate) != 0) { | 114 if ((mode & kTruncate) != 0) { |
| 115 flags = flags | O_TRUNC; | 115 flags = flags | O_TRUNC; |
| 116 } | 116 } |
| 117 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 117 const wchar_t* system_name = StringUtils::Utf8ToWide(name); |
| 118 int fd = _wopen(system_name, flags, 0666); | 118 int fd = _wopen(system_name, flags, 0666); |
| 119 free(const_cast<wchar_t*>(system_name)); | 119 free(const_cast<wchar_t*>(system_name)); |
| 120 if (fd < 0) { | 120 if (fd < 0) { |
| 121 return NULL; | 121 return NULL; |
| 122 } | 122 } |
| 123 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { | 123 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { |
| 124 int position = lseek(fd, 0, SEEK_END); | 124 off64_t position = _lseeki64(fd, 0, SEEK_END); |
| 125 if (position < 0) { | 125 if (position < 0) { |
| 126 return NULL; | 126 return NULL; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 return new File(new FileHandle(fd)); | 129 return new File(new FileHandle(fd)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 | 132 |
| 133 File* File::OpenStdio(int fd) { | 133 File* File::OpenStdio(int fd) { |
| 134 UNREACHABLE(); | 134 UNREACHABLE(); |
| 135 return NULL; | 135 return NULL; |
| 136 } | 136 } |
| 137 | 137 |
| 138 | 138 |
| 139 bool File::Exists(const char* name) { | 139 bool File::Exists(const char* name) { |
| 140 struct _stat st; | 140 struct __stat64 st; |
| 141 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 141 const wchar_t* system_name = StringUtils::Utf8ToWide(name); |
| 142 bool stat_status = _wstat(system_name, &st); | 142 bool stat_status = _wstat64(system_name, &st); |
| 143 free(const_cast<wchar_t*>(system_name)); | 143 free(const_cast<wchar_t*>(system_name)); |
| 144 if (stat_status == 0) { | 144 if (stat_status == 0) { |
| 145 return ((st.st_mode & S_IFMT) == S_IFREG); | 145 return ((st.st_mode & S_IFMT) == S_IFREG); |
| 146 } else { | 146 } else { |
| 147 return false; | 147 return false; |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 | 151 |
| 152 bool File::Create(const char* name) { | 152 bool File::Create(const char* name) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 free(const_cast<wchar_t*>(system_old_path)); | 315 free(const_cast<wchar_t*>(system_old_path)); |
| 316 free(const_cast<wchar_t*>(system_new_path)); | 316 free(const_cast<wchar_t*>(system_new_path)); |
| 317 return (move_status != 0); | 317 return (move_status != 0); |
| 318 } else { | 318 } else { |
| 319 SetLastError(ERROR_FILE_NOT_FOUND); | 319 SetLastError(ERROR_FILE_NOT_FOUND); |
| 320 } | 320 } |
| 321 return false; | 321 return false; |
| 322 } | 322 } |
| 323 | 323 |
| 324 | 324 |
| 325 off_t File::LengthFromPath(const char* name) { | 325 off64_t File::LengthFromPath(const char* name) { |
| 326 struct _stat st; | 326 struct __stat64 st; |
| 327 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 327 const wchar_t* system_name = StringUtils::Utf8ToWide(name); |
| 328 int stat_status = _wstat(system_name, &st); | 328 int stat_status = _wstat64(system_name, &st); |
| 329 free(const_cast<wchar_t*>(system_name)); | 329 free(const_cast<wchar_t*>(system_name)); |
| 330 if (stat_status == 0) { | 330 if (stat_status == 0) { |
| 331 return st.st_size; | 331 return st.st_size; |
| 332 } | 332 } |
| 333 return -1; | 333 return -1; |
| 334 } | 334 } |
| 335 | 335 |
| 336 | 336 |
| 337 char* File::LinkTarget(const char* pathname) { | 337 char* File::LinkTarget(const char* pathname) { |
| 338 const wchar_t* name = StringUtils::Utf8ToWide(pathname); | 338 const wchar_t* name = StringUtils::Utf8ToWide(pathname); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 data[kMode] = st.st_mode; | 441 data[kMode] = st.st_mode; |
| 442 data[kSize] = st.st_size; | 442 data[kSize] = st.st_size; |
| 443 } else { | 443 } else { |
| 444 data[kType] = File::kDoesNotExist; | 444 data[kType] = File::kDoesNotExist; |
| 445 } | 445 } |
| 446 } | 446 } |
| 447 } | 447 } |
| 448 | 448 |
| 449 | 449 |
| 450 time_t File::LastModified(const char* name) { | 450 time_t File::LastModified(const char* name) { |
| 451 struct _stat st; | 451 struct __stat64 st; |
| 452 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 452 const wchar_t* system_name = StringUtils::Utf8ToWide(name); |
| 453 int stat_status = _wstat(system_name, &st); | 453 int stat_status = _wstat64(system_name, &st); |
| 454 free(const_cast<wchar_t*>(system_name)); | 454 free(const_cast<wchar_t*>(system_name)); |
| 455 if (stat_status == 0) { | 455 if (stat_status == 0) { |
| 456 return st.st_mtime; | 456 return st.st_mtime; |
| 457 } | 457 } |
| 458 return -1; | 458 return -1; |
| 459 } | 459 } |
| 460 | 460 |
| 461 | 461 |
| 462 bool File::IsAbsolutePath(const char* pathname) { | 462 bool File::IsAbsolutePath(const char* pathname) { |
| 463 // Should we consider network paths? | 463 // Should we consider network paths? |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 return kIdentical; | 606 return kIdentical; |
| 607 } else { | 607 } else { |
| 608 return kDifferent; | 608 return kDifferent; |
| 609 } | 609 } |
| 610 } | 610 } |
| 611 | 611 |
| 612 } // namespace bin | 612 } // namespace bin |
| 613 } // namespace dart | 613 } // namespace dart |
| 614 | 614 |
| 615 #endif // defined(TARGET_OS_WINDOWS) | 615 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |