| 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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 20 matching lines...) Expand all Loading... |
| 31 void set_fd(int fd) { fd_ = fd; } | 31 void set_fd(int fd) { fd_ = fd; } |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 int fd_; | 34 int fd_; |
| 35 | 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(FileHandle); | 36 DISALLOW_COPY_AND_ASSIGN(FileHandle); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 | 39 |
| 40 File::~File() { | 40 File::~File() { |
| 41 Close(); | 41 if (!IsClosed()) { |
| 42 Close(); |
| 43 } |
| 42 delete handle_; | 44 delete handle_; |
| 43 } | 45 } |
| 44 | 46 |
| 45 | 47 |
| 46 void File::Close() { | 48 void File::Close() { |
| 47 ASSERT(handle_->fd() >= 0); | 49 ASSERT(handle_->fd() >= 0); |
| 48 if (handle_->fd() == STDOUT_FILENO) { | 50 if (handle_->fd() == STDOUT_FILENO) { |
| 49 // If stdout, redirect fd to /dev/null. | 51 // If stdout, redirect fd to /dev/null. |
| 50 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); | 52 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); |
| 51 ASSERT(null_fd >= 0); | 53 ASSERT(null_fd >= 0); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } | 191 } |
| 190 | 192 |
| 191 | 193 |
| 192 File* File::Open(const char* path, FileOpenMode mode) { | 194 File* File::Open(const char* path, FileOpenMode mode) { |
| 193 // ScopedOpen doesn't actually need a scope. | 195 // ScopedOpen doesn't actually need a scope. |
| 194 return ScopedOpen(path, mode); | 196 return ScopedOpen(path, mode); |
| 195 } | 197 } |
| 196 | 198 |
| 197 | 199 |
| 198 File* File::OpenStdio(int fd) { | 200 File* File::OpenStdio(int fd) { |
| 199 if ((fd < 0) || (2 < fd)) { | 201 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); |
| 200 return NULL; | |
| 201 } | |
| 202 return new File(new FileHandle(fd)); | |
| 203 } | 202 } |
| 204 | 203 |
| 205 | 204 |
| 206 bool File::Exists(const char* name) { | 205 bool File::Exists(const char* name) { |
| 207 struct stat64 st; | 206 struct stat64 st; |
| 208 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { | 207 if (TEMP_FAILURE_RETRY(stat64(name, &st)) == 0) { |
| 209 return S_ISREG(st.st_mode); | 208 return S_ISREG(st.st_mode); |
| 210 } else { | 209 } else { |
| 211 return false; | 210 return false; |
| 212 } | 211 } |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 return ((file_1_info.st_ino == file_2_info.st_ino) && | 497 return ((file_1_info.st_ino == file_2_info.st_ino) && |
| 499 (file_1_info.st_dev == file_2_info.st_dev)) ? | 498 (file_1_info.st_dev == file_2_info.st_dev)) ? |
| 500 File::kIdentical : | 499 File::kIdentical : |
| 501 File::kDifferent; | 500 File::kDifferent; |
| 502 } | 501 } |
| 503 | 502 |
| 504 } // namespace bin | 503 } // namespace bin |
| 505 } // namespace dart | 504 } // namespace dart |
| 506 | 505 |
| 507 #endif // defined(TARGET_OS_LINUX) | 506 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |