| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 if (_fstat64(handle_->fd(), &st) == 0) { | 150 if (_fstat64(handle_->fd(), &st) == 0) { |
| 151 return st.st_size; | 151 return st.st_size; |
| 152 } | 152 } |
| 153 return -1; | 153 return -1; |
| 154 } | 154 } |
| 155 | 155 |
| 156 | 156 |
| 157 File* File::Open(const char* name, FileOpenMode mode) { | 157 File* File::Open(const char* name, FileOpenMode mode) { |
| 158 int flags = O_RDONLY | O_BINARY | O_NOINHERIT; | 158 int flags = O_RDONLY | O_BINARY | O_NOINHERIT; |
| 159 if ((mode & kWrite) != 0) { | 159 if ((mode & kWrite) != 0) { |
| 160 ASSERT((mode & kWriteOnly) == 0); |
| 160 flags = (O_RDWR | O_CREAT | O_BINARY | O_NOINHERIT); | 161 flags = (O_RDWR | O_CREAT | O_BINARY | O_NOINHERIT); |
| 161 } | 162 } |
| 163 if ((mode & kWriteOnly) != 0) { |
| 164 ASSERT((mode & kWrite) == 0); |
| 165 flags = (O_WRONLY | O_CREAT | O_BINARY | O_NOINHERIT); |
| 166 } |
| 162 if ((mode & kTruncate) != 0) { | 167 if ((mode & kTruncate) != 0) { |
| 163 flags = flags | O_TRUNC; | 168 flags = flags | O_TRUNC; |
| 164 } | 169 } |
| 165 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 170 const wchar_t* system_name = StringUtils::Utf8ToWide(name); |
| 166 int fd = _wopen(system_name, flags, 0666); | 171 int fd = _wopen(system_name, flags, 0666); |
| 167 free(const_cast<wchar_t*>(system_name)); | 172 free(const_cast<wchar_t*>(system_name)); |
| 168 if (fd < 0) { | 173 if (fd < 0) { |
| 169 return NULL; | 174 return NULL; |
| 170 } | 175 } |
| 171 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { | 176 if ((((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) || |
| 177 (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { |
| 172 int64_t position = _lseeki64(fd, 0, SEEK_END); | 178 int64_t position = _lseeki64(fd, 0, SEEK_END); |
| 173 if (position < 0) { | 179 if (position < 0) { |
| 174 return NULL; | 180 return NULL; |
| 175 } | 181 } |
| 176 } | 182 } |
| 177 return new File(new FileHandle(fd)); | 183 return new File(new FileHandle(fd)); |
| 178 } | 184 } |
| 179 | 185 |
| 180 | 186 |
| 181 File* File::OpenStdio(int fd) { | 187 File* File::OpenStdio(int fd) { |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 return kIdentical; | 690 return kIdentical; |
| 685 } else { | 691 } else { |
| 686 return kDifferent; | 692 return kDifferent; |
| 687 } | 693 } |
| 688 } | 694 } |
| 689 | 695 |
| 690 } // namespace bin | 696 } // namespace bin |
| 691 } // namespace dart | 697 } // namespace dart |
| 692 | 698 |
| 693 #endif // defined(TARGET_OS_WINDOWS) | 699 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |