| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 return -1; | 176 return -1; |
| 177 } | 177 } |
| 178 | 178 |
| 179 | 179 |
| 180 File* File::FileOpenW(const wchar_t* system_name, FileOpenMode mode) { | 180 File* File::FileOpenW(const wchar_t* system_name, FileOpenMode mode) { |
| 181 UNREACHABLE(); | 181 UNREACHABLE(); |
| 182 return NULL; | 182 return NULL; |
| 183 } | 183 } |
| 184 | 184 |
| 185 | 185 |
| 186 File* File::ScopedOpen(const char* name, FileOpenMode mode) { | 186 File* File::Open(const char* name, FileOpenMode mode) { |
| 187 // Report errors for non-regular files. | 187 // Report errors for non-regular files. |
| 188 struct stat st; | 188 struct stat st; |
| 189 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { | 189 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
| 190 if (!S_ISREG(st.st_mode)) { | 190 if (!S_ISREG(st.st_mode)) { |
| 191 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; | 191 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
| 192 return NULL; | 192 return NULL; |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 int flags = O_RDONLY; | 195 int flags = O_RDONLY; |
| 196 if ((mode & kWrite) != 0) { | 196 if ((mode & kWrite) != 0) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 213 (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { | 213 (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { |
| 214 int64_t position = lseek64(fd, 0, SEEK_END); | 214 int64_t position = lseek64(fd, 0, SEEK_END); |
| 215 if (position < 0) { | 215 if (position < 0) { |
| 216 return NULL; | 216 return NULL; |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 return new File(new FileHandle(fd)); | 219 return new File(new FileHandle(fd)); |
| 220 } | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 File* File::Open(const char* path, FileOpenMode mode) { | |
| 224 // ScopedOpen doesn't actually need a scope. | |
| 225 return ScopedOpen(path, mode); | |
| 226 } | |
| 227 | |
| 228 | |
| 229 File* File::OpenStdio(int fd) { | 223 File* File::OpenStdio(int fd) { |
| 230 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); | 224 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); |
| 231 } | 225 } |
| 232 | 226 |
| 233 | 227 |
| 234 bool File::Exists(const char* name) { | 228 bool File::Exists(const char* name) { |
| 235 struct stat st; | 229 struct stat st; |
| 236 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { | 230 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
| 237 return S_ISREG(st.st_mode); | 231 return S_ISREG(st.st_mode); |
| 238 } else { | 232 } else { |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 return ((file_1_info.st_ino == file_2_info.st_ino) && | 508 return ((file_1_info.st_ino == file_2_info.st_ino) && |
| 515 (file_1_info.st_dev == file_2_info.st_dev)) ? | 509 (file_1_info.st_dev == file_2_info.st_dev)) ? |
| 516 File::kIdentical : | 510 File::kIdentical : |
| 517 File::kDifferent; | 511 File::kDifferent; |
| 518 } | 512 } |
| 519 | 513 |
| 520 } // namespace bin | 514 } // namespace bin |
| 521 } // namespace dart | 515 } // namespace dart |
| 522 | 516 |
| 523 #endif // defined(TARGET_OS_ANDROID) | 517 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |