Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: runtime/bin/file_android.cc

Issue 1193653002: Add file modes for opening a file write only (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Addressed review comments + fixed analyzer reported issues Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/file.cc ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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)
OLDNEW
« no previous file with comments | « runtime/bin/file.cc ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698