| 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 <copyfile.h> // NOLINT | 10 #include <copyfile.h> // NOLINT |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 return -1; | 178 return -1; |
| 179 } | 179 } |
| 180 | 180 |
| 181 | 181 |
| 182 File* File::FileOpenW(const wchar_t* system_name, FileOpenMode mode) { | 182 File* File::FileOpenW(const wchar_t* system_name, FileOpenMode mode) { |
| 183 UNREACHABLE(); | 183 UNREACHABLE(); |
| 184 return NULL; | 184 return NULL; |
| 185 } | 185 } |
| 186 | 186 |
| 187 | 187 |
| 188 File* File::ScopedOpen(const char* name, FileOpenMode mode) { | 188 File* File::Open(const char* name, FileOpenMode mode) { |
| 189 // Report errors for non-regular files. | 189 // Report errors for non-regular files. |
| 190 struct stat st; | 190 struct stat st; |
| 191 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { | 191 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
| 192 // Only accept regular files, character devices, and pipes. | 192 // Only accept regular files, character devices, and pipes. |
| 193 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode) && !S_ISFIFO(st.st_mode)) { | 193 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode) && !S_ISFIFO(st.st_mode)) { |
| 194 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; | 194 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
| 195 return NULL; | 195 return NULL; |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 int flags = O_RDONLY; | 198 int flags = O_RDONLY; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 216 (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { | 216 (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { |
| 217 int64_t position = lseek(fd, 0, SEEK_END); | 217 int64_t position = lseek(fd, 0, SEEK_END); |
| 218 if (position < 0) { | 218 if (position < 0) { |
| 219 return NULL; | 219 return NULL; |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 return new File(new FileHandle(fd)); | 222 return new File(new FileHandle(fd)); |
| 223 } | 223 } |
| 224 | 224 |
| 225 | 225 |
| 226 File* File::Open(const char* path, FileOpenMode mode) { | |
| 227 // ScopedOpen doesn't actually need a scope. | |
| 228 return ScopedOpen(path, mode); | |
| 229 } | |
| 230 | |
| 231 | |
| 232 File* File::OpenStdio(int fd) { | 226 File* File::OpenStdio(int fd) { |
| 233 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); | 227 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); |
| 234 } | 228 } |
| 235 | 229 |
| 236 | 230 |
| 237 bool File::Exists(const char* name) { | 231 bool File::Exists(const char* name) { |
| 238 struct stat st; | 232 struct stat st; |
| 239 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { | 233 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
| 240 return S_ISREG(st.st_mode); | 234 return S_ISREG(st.st_mode); |
| 241 } else { | 235 } else { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 return ((file_1_info.st_ino == file_2_info.st_ino) && | 484 return ((file_1_info.st_ino == file_2_info.st_ino) && |
| 491 (file_1_info.st_dev == file_2_info.st_dev)) ? | 485 (file_1_info.st_dev == file_2_info.st_dev)) ? |
| 492 File::kIdentical : | 486 File::kIdentical : |
| 493 File::kDifferent; | 487 File::kDifferent; |
| 494 } | 488 } |
| 495 | 489 |
| 496 } // namespace bin | 490 } // namespace bin |
| 497 } // namespace dart | 491 } // namespace dart |
| 498 | 492 |
| 499 #endif // defined(TARGET_OS_MACOS) | 493 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |