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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // Report errors for non-regular files. | 151 // Report errors for non-regular files. |
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 if (!S_ISREG(st.st_mode)) { | 154 if (!S_ISREG(st.st_mode)) { |
155 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; | 155 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
156 return NULL; | 156 return NULL; |
157 } | 157 } |
158 } | 158 } |
159 int flags = O_RDONLY; | 159 int flags = O_RDONLY; |
160 if ((mode & kWrite) != 0) { | 160 if ((mode & kWrite) != 0) { |
| 161 ASSERT((mode & kWriteOnly) == 0); |
161 flags = (O_RDWR | O_CREAT); | 162 flags = (O_RDWR | O_CREAT); |
162 } | 163 } |
| 164 if ((mode & kWriteOnly) != 0) { |
| 165 ASSERT((mode & kWrite) == 0); |
| 166 flags = (O_WRONLY | O_CREAT); |
| 167 } |
163 if ((mode & kTruncate) != 0) { | 168 if ((mode & kTruncate) != 0) { |
164 flags = flags | O_TRUNC; | 169 flags = flags | O_TRUNC; |
165 } | 170 } |
166 flags |= O_CLOEXEC; | 171 flags |= O_CLOEXEC; |
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 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 = lseek64(fd, 0, SEEK_END); | 178 int64_t position = lseek64(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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 return (file_1_info.st_ino == file_2_info.st_ino && | 459 return (file_1_info.st_ino == file_2_info.st_ino && |
454 file_1_info.st_dev == file_2_info.st_dev) ? | 460 file_1_info.st_dev == file_2_info.st_dev) ? |
455 File::kIdentical : | 461 File::kIdentical : |
456 File::kDifferent; | 462 File::kDifferent; |
457 } | 463 } |
458 | 464 |
459 } // namespace bin | 465 } // namespace bin |
460 } // namespace dart | 466 } // namespace dart |
461 | 467 |
462 #endif // defined(TARGET_OS_ANDROID) | 468 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |