| 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 22 matching lines...) Expand all Loading... |
| 33 void set_fd(int fd) { fd_ = fd; } | 33 void set_fd(int fd) { fd_ = fd; } |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 int fd_; | 36 int fd_; |
| 37 | 37 |
| 38 DISALLOW_COPY_AND_ASSIGN(FileHandle); | 38 DISALLOW_COPY_AND_ASSIGN(FileHandle); |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 | 41 |
| 42 File::~File() { | 42 File::~File() { |
| 43 Close(); | 43 if (!IsClosed()) { |
| 44 Close(); |
| 45 } |
| 44 delete handle_; | 46 delete handle_; |
| 45 } | 47 } |
| 46 | 48 |
| 47 | 49 |
| 48 void File::Close() { | 50 void File::Close() { |
| 49 ASSERT(handle_->fd() >= 0); | 51 ASSERT(handle_->fd() >= 0); |
| 50 if (handle_->fd() == STDOUT_FILENO) { | 52 if (handle_->fd() == STDOUT_FILENO) { |
| 51 // If stdout, redirect fd to /dev/null. | 53 // If stdout, redirect fd to /dev/null. |
| 52 intptr_t null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); | 54 intptr_t null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); |
| 53 ASSERT(null_fd >= 0); | 55 ASSERT(null_fd >= 0); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 194 } |
| 193 | 195 |
| 194 | 196 |
| 195 File* File::Open(const char* path, FileOpenMode mode) { | 197 File* File::Open(const char* path, FileOpenMode mode) { |
| 196 // ScopedOpen doesn't actually need a scope. | 198 // ScopedOpen doesn't actually need a scope. |
| 197 return ScopedOpen(path, mode); | 199 return ScopedOpen(path, mode); |
| 198 } | 200 } |
| 199 | 201 |
| 200 | 202 |
| 201 File* File::OpenStdio(int fd) { | 203 File* File::OpenStdio(int fd) { |
| 202 if ((fd < 0) || (2 < fd)) { | 204 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); |
| 203 return NULL; | |
| 204 } | |
| 205 return new File(new FileHandle(fd)); | |
| 206 } | 205 } |
| 207 | 206 |
| 208 | 207 |
| 209 bool File::Exists(const char* name) { | 208 bool File::Exists(const char* name) { |
| 210 struct stat st; | 209 struct stat st; |
| 211 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { | 210 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
| 212 return S_ISREG(st.st_mode); | 211 return S_ISREG(st.st_mode); |
| 213 } else { | 212 } else { |
| 214 return false; | 213 return false; |
| 215 } | 214 } |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 return ((file_1_info.st_ino == file_2_info.st_ino) && | 461 return ((file_1_info.st_ino == file_2_info.st_ino) && |
| 463 (file_1_info.st_dev == file_2_info.st_dev)) ? | 462 (file_1_info.st_dev == file_2_info.st_dev)) ? |
| 464 File::kIdentical : | 463 File::kIdentical : |
| 465 File::kDifferent; | 464 File::kDifferent; |
| 466 } | 465 } |
| 467 | 466 |
| 468 } // namespace bin | 467 } // namespace bin |
| 469 } // namespace dart | 468 } // namespace dart |
| 470 | 469 |
| 471 #endif // defined(TARGET_OS_MACOS) | 470 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |