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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 struct stat64 st; | 150 struct stat64 st; |
151 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { | 151 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { |
152 // Only accept regular files and character devices. | 152 // Only accept regular files and character devices. |
153 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) { | 153 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) { |
154 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; | 154 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
155 return NULL; | 155 return NULL; |
156 } | 156 } |
157 } | 157 } |
158 int flags = O_RDONLY; | 158 int flags = O_RDONLY; |
159 if ((mode & kWrite) != 0) { | 159 if ((mode & kWrite) != 0) { |
| 160 ASSERT((mode & kWriteOnly) == 0); |
160 flags = (O_RDWR | O_CREAT); | 161 flags = (O_RDWR | O_CREAT); |
161 } | 162 } |
| 163 if ((mode & kWriteOnly) != 0) { |
| 164 ASSERT((mode & kWrite) == 0); |
| 165 flags = (O_WRONLY | O_CREAT); |
| 166 } |
162 if ((mode & kTruncate) != 0) { | 167 if ((mode & kTruncate) != 0) { |
163 flags = flags | O_TRUNC; | 168 flags = flags | O_TRUNC; |
164 } | 169 } |
165 flags |= O_CLOEXEC; | 170 flags |= O_CLOEXEC; |
166 int fd = TEMP_FAILURE_RETRY(open64(name, flags, 0666)); | 171 int fd = TEMP_FAILURE_RETRY(open64(name, flags, 0666)); |
167 if (fd < 0) { | 172 if (fd < 0) { |
168 return NULL; | 173 return NULL; |
169 } | 174 } |
170 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { | 175 if ((((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) || |
| 176 (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { |
171 int64_t position = NO_RETRY_EXPECTED(lseek64(fd, 0, SEEK_END)); | 177 int64_t position = NO_RETRY_EXPECTED(lseek64(fd, 0, SEEK_END)); |
172 if (position < 0) { | 178 if (position < 0) { |
173 return NULL; | 179 return NULL; |
174 } | 180 } |
175 } | 181 } |
176 return new File(new FileHandle(fd)); | 182 return new File(new FileHandle(fd)); |
177 } | 183 } |
178 | 184 |
179 | 185 |
180 File* File::OpenStdio(int fd) { | 186 File* File::OpenStdio(int fd) { |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 return (file_1_info.st_ino == file_2_info.st_ino && | 465 return (file_1_info.st_ino == file_2_info.st_ino && |
460 file_1_info.st_dev == file_2_info.st_dev) ? | 466 file_1_info.st_dev == file_2_info.st_dev) ? |
461 File::kIdentical : | 467 File::kIdentical : |
462 File::kDifferent; | 468 File::kDifferent; |
463 } | 469 } |
464 | 470 |
465 } // namespace bin | 471 } // namespace bin |
466 } // namespace dart | 472 } // namespace dart |
467 | 473 |
468 #endif // defined(TARGET_OS_LINUX) | 474 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |