| 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 #include <libgen.h> | 11 #include <libgen.h> |
| 12 | 12 |
| 13 #include "bin/builtin.h" | 13 #include "bin/builtin.h" |
| 14 | 14 |
| 15 class FileHandle { | 15 class FileHandle { |
| 16 public: | 16 public: |
| 17 explicit FileHandle(int fd) : fd_(fd) { } | 17 explicit FileHandle(int fd) : fd_(fd) { } |
| 18 ~FileHandle() { } | 18 ~FileHandle() { } |
| 19 int fd() const { return fd_; } | 19 int fd() const { return fd_; } |
| 20 void set_fd(int fd) { fd_ = fd; } | 20 void set_fd(int fd) { fd_ = fd; } |
| 21 | 21 |
| 22 private: | 22 private: |
| 23 int fd_; | 23 int fd_; |
| 24 | 24 |
| 25 // DISALLOW_COPY_AND_ASSIGN(FileHandle). | 25 DISALLOW_COPY_AND_ASSIGN(FileHandle); |
| 26 FileHandle(const FileHandle&); | |
| 27 void operator=(const FileHandle&); | |
| 28 }; | 26 }; |
| 29 | 27 |
| 30 | 28 |
| 31 File::~File() { | 29 File::~File() { |
| 32 // Close the file (unless it's a standard stream). | 30 // Close the file (unless it's a standard stream). |
| 33 if (handle_->fd() > STDERR_FILENO) { | 31 if (handle_->fd() > STDERR_FILENO) { |
| 34 Close(); | 32 Close(); |
| 35 } | 33 } |
| 36 delete handle_; | 34 delete handle_; |
| 37 } | 35 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 int result = fstat(fd, &buf); | 233 int result = fstat(fd, &buf); |
| 236 if (result == -1) { | 234 if (result == -1) { |
| 237 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); | 235 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); |
| 238 } | 236 } |
| 239 if (S_ISCHR(buf.st_mode)) return kTerminal; | 237 if (S_ISCHR(buf.st_mode)) return kTerminal; |
| 240 if (S_ISFIFO(buf.st_mode)) return kPipe; | 238 if (S_ISFIFO(buf.st_mode)) return kPipe; |
| 241 if (S_ISSOCK(buf.st_mode)) return kSocket; | 239 if (S_ISSOCK(buf.st_mode)) return kSocket; |
| 242 if (S_ISREG(buf.st_mode)) return kFile; | 240 if (S_ISREG(buf.st_mode)) return kFile; |
| 243 return kOther; | 241 return kOther; |
| 244 } | 242 } |
| OLD | NEW |