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_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 struct stat st; | 152 struct stat st; |
153 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { | 153 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
154 // Only accept regular files and character devices. | 154 // Only accept regular files and character devices. |
155 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) { | 155 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) { |
156 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; | 156 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
157 return NULL; | 157 return NULL; |
158 } | 158 } |
159 } | 159 } |
160 int flags = O_RDONLY; | 160 int flags = O_RDONLY; |
161 if ((mode & kWrite) != 0) { | 161 if ((mode & kWrite) != 0) { |
| 162 ASSERT((mode & kWriteOnly) == 0); |
162 flags = (O_RDWR | O_CREAT); | 163 flags = (O_RDWR | O_CREAT); |
163 } | 164 } |
| 165 if ((mode & kWriteOnly) != 0) { |
| 166 ASSERT((mode & kWrite) == 0); |
| 167 flags = (O_WRONLY | O_CREAT); |
| 168 } |
164 if ((mode & kTruncate) != 0) { | 169 if ((mode & kTruncate) != 0) { |
165 flags = flags | O_TRUNC; | 170 flags = flags | O_TRUNC; |
166 } | 171 } |
167 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666)); | 172 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666)); |
168 if (fd < 0) { | 173 if (fd < 0) { |
169 return NULL; | 174 return NULL; |
170 } | 175 } |
171 FDUtils::SetCloseOnExec(fd); | 176 FDUtils::SetCloseOnExec(fd); |
172 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { | 177 if ((((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) || |
| 178 (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { |
173 int64_t position = lseek(fd, 0, SEEK_END); | 179 int64_t position = lseek(fd, 0, SEEK_END); |
174 if (position < 0) { | 180 if (position < 0) { |
175 return NULL; | 181 return NULL; |
176 } | 182 } |
177 } | 183 } |
178 return new File(new FileHandle(fd)); | 184 return new File(new FileHandle(fd)); |
179 } | 185 } |
180 | 186 |
181 | 187 |
182 File* File::OpenStdio(int fd) { | 188 File* File::OpenStdio(int fd) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 return (file_1_info.st_ino == file_2_info.st_ino && | 431 return (file_1_info.st_ino == file_2_info.st_ino && |
426 file_1_info.st_dev == file_2_info.st_dev) ? | 432 file_1_info.st_dev == file_2_info.st_dev) ? |
427 File::kIdentical : | 433 File::kIdentical : |
428 File::kDifferent; | 434 File::kDifferent; |
429 } | 435 } |
430 | 436 |
431 } // namespace bin | 437 } // namespace bin |
432 } // namespace dart | 438 } // namespace dart |
433 | 439 |
434 #endif // defined(TARGET_OS_MACOS) | 440 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |