| 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 "bin/file.h" | 5 #include "bin/file.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <sys/stat.h> | 11 #include <sys/stat.h> |
| 12 | 12 |
| 13 #include "bin/builtin.h" | 13 #include "bin/builtin.h" |
| 14 #include "bin/log.h" |
| 14 | 15 |
| 15 class FileHandle { | 16 class FileHandle { |
| 16 public: | 17 public: |
| 17 explicit FileHandle(int fd) : fd_(fd) { } | 18 explicit FileHandle(int fd) : fd_(fd) { } |
| 18 ~FileHandle() { } | 19 ~FileHandle() { } |
| 19 int fd() const { return fd_; } | 20 int fd() const { return fd_; } |
| 20 void set_fd(int fd) { fd_ = fd; } | 21 void set_fd(int fd) { fd_ = fd; } |
| 21 | 22 |
| 22 private: | 23 private: |
| 23 int fd_; | 24 int fd_; |
| 24 | 25 |
| 25 DISALLOW_COPY_AND_ASSIGN(FileHandle); | 26 DISALLOW_COPY_AND_ASSIGN(FileHandle); |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 | 29 |
| 29 File::~File() { | 30 File::~File() { |
| 30 // Close the file (unless it's a standard stream). | 31 // Close the file (unless it's a standard stream). |
| 31 if (handle_->fd() > 2) { | 32 if (handle_->fd() > 2) { |
| 32 Close(); | 33 Close(); |
| 33 } | 34 } |
| 34 delete handle_; | 35 delete handle_; |
| 35 } | 36 } |
| 36 | 37 |
| 37 | 38 |
| 38 void File::Close() { | 39 void File::Close() { |
| 39 ASSERT(handle_->fd() >= 0); | 40 ASSERT(handle_->fd() >= 0); |
| 40 int err = close(handle_->fd()); | 41 int err = close(handle_->fd()); |
| 41 if (err != 0) { | 42 if (err != 0) { |
| 42 fprintf(stderr, "%s\n", strerror(errno)); | 43 Log::PrintErr("%s\n", strerror(errno)); |
| 43 } | 44 } |
| 44 handle_->set_fd(kClosedFd); | 45 handle_->set_fd(kClosedFd); |
| 45 } | 46 } |
| 46 | 47 |
| 47 | 48 |
| 48 bool File::IsClosed() { | 49 bool File::IsClosed() { |
| 49 return handle_->fd() == kClosedFd; | 50 return handle_->fd() == kClosedFd; |
| 50 } | 51 } |
| 51 | 52 |
| 52 | 53 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 const char* File::StringEscapedPathSeparator() { | 255 const char* File::StringEscapedPathSeparator() { |
| 255 return "\\\\"; | 256 return "\\\\"; |
| 256 } | 257 } |
| 257 | 258 |
| 258 | 259 |
| 259 File::StdioHandleType File::GetStdioHandleType(int fd) { | 260 File::StdioHandleType File::GetStdioHandleType(int fd) { |
| 260 // Treat all stdio handles as pipes. The Windows event handler and | 261 // Treat all stdio handles as pipes. The Windows event handler and |
| 261 // socket code will handle the different handle types. | 262 // socket code will handle the different handle types. |
| 262 return kPipe; | 263 return kPipe; |
| 263 } | 264 } |
| OLD | NEW |