| 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 off64_t File::Position() { | 75 int64_t File::Position() { |
| 76 ASSERT(handle_->fd() >= 0); | 76 ASSERT(handle_->fd() >= 0); |
| 77 return _lseeki64(handle_->fd(), 0, SEEK_CUR); | 77 return _lseeki64(handle_->fd(), 0, SEEK_CUR); |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 bool File::SetPosition(off64_t position) { | 81 bool File::SetPosition(int64_t position) { |
| 82 ASSERT(handle_->fd() >= 0); | 82 ASSERT(handle_->fd() >= 0); |
| 83 return _lseeki64(handle_->fd(), position, SEEK_SET) >= 0; | 83 return _lseeki64(handle_->fd(), position, SEEK_SET) >= 0; |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 bool File::Truncate(off64_t length) { | 87 bool File::Truncate(int64_t length) { |
| 88 ASSERT(handle_->fd() >= 0); | 88 ASSERT(handle_->fd() >= 0); |
| 89 return _chsize_s(handle_->fd(), length) == 0; | 89 return _chsize_s(handle_->fd(), length) == 0; |
| 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 off64_t File::Length() { | 99 int64_t File::Length() { |
| 100 ASSERT(handle_->fd() >= 0); | 100 ASSERT(handle_->fd() >= 0); |
| 101 struct __stat64 st; | 101 struct __stat64 st; |
| 102 if (_fstat64(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 off64_t position = _lseeki64(fd, 0, SEEK_END); | 124 int64_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(); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 free(const_cast<wchar_t*>(system_old_path)); | 336 free(const_cast<wchar_t*>(system_old_path)); |
| 337 free(const_cast<wchar_t*>(system_new_path)); | 337 free(const_cast<wchar_t*>(system_new_path)); |
| 338 return success; | 338 return success; |
| 339 } else { | 339 } else { |
| 340 SetLastError(ERROR_FILE_NOT_FOUND); | 340 SetLastError(ERROR_FILE_NOT_FOUND); |
| 341 } | 341 } |
| 342 return false; | 342 return false; |
| 343 } | 343 } |
| 344 | 344 |
| 345 | 345 |
| 346 off64_t File::LengthFromPath(const char* name) { | 346 int64_t File::LengthFromPath(const char* name) { |
| 347 struct __stat64 st; | 347 struct __stat64 st; |
| 348 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 348 const wchar_t* system_name = StringUtils::Utf8ToWide(name); |
| 349 int stat_status = _wstat64(system_name, &st); | 349 int stat_status = _wstat64(system_name, &st); |
| 350 free(const_cast<wchar_t*>(system_name)); | 350 free(const_cast<wchar_t*>(system_name)); |
| 351 if (stat_status == 0) { | 351 if (stat_status == 0) { |
| 352 return st.st_size; | 352 return st.st_size; |
| 353 } | 353 } |
| 354 return -1; | 354 return -1; |
| 355 } | 355 } |
| 356 | 356 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 return kIdentical; | 627 return kIdentical; |
| 628 } else { | 628 } else { |
| 629 return kDifferent; | 629 return kDifferent; |
| 630 } | 630 } |
| 631 } | 631 } |
| 632 | 632 |
| 633 } // namespace bin | 633 } // namespace bin |
| 634 } // namespace dart | 634 } // namespace dart |
| 635 | 635 |
| 636 #endif // defined(TARGET_OS_WINDOWS) | 636 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |