| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 <fcntl.h> | 5 #include <fcntl.h> |
| 6 #include <io.h> | 6 #include <io.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 File::~File() { | 30 File::~File() { |
| 31 // Close the file (unless it's a standard stream). | 31 // Close the file (unless it's a standard stream). |
| 32 if (handle_->fd() > 2) { | 32 if (handle_->fd() > 2) { |
| 33 Close(); | 33 Close(); |
| 34 } | 34 } |
| 35 delete handle_; | 35 delete handle_; |
| 36 } | 36 } |
| 37 | 37 |
| 38 | 38 |
| 39 void File::Close() { | 39 void File::Close() { |
| 40 assert(handle_->fd() >= 0); | 40 ASSERT(handle_->fd() >= 0); |
| 41 int err = close(handle_->fd()); | 41 int err = close(handle_->fd()); |
| 42 if (err != 0) { | 42 if (err != 0) { |
| 43 fprintf(stderr, "%s\n", strerror(errno)); | 43 fprintf(stderr, "%s\n", strerror(errno)); |
| 44 } | 44 } |
| 45 handle_->set_fd(kClosedFd); | 45 handle_->set_fd(kClosedFd); |
| 46 } | 46 } |
| 47 | 47 |
| 48 | 48 |
| 49 bool File::IsClosed() { | 49 bool File::IsClosed() { |
| 50 return handle_->fd() == kClosedFd; | 50 return handle_->fd() == kClosedFd; |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 int64_t File::Read(void* buffer, int64_t num_bytes) { | 54 int64_t File::Read(void* buffer, int64_t num_bytes) { |
| 55 assert(handle_->fd() >= 0); | 55 ASSERT(handle_->fd() >= 0); |
| 56 return read(handle_->fd(), buffer, num_bytes); | 56 return read(handle_->fd(), buffer, num_bytes); |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 int64_t File::Write(const void* buffer, int64_t num_bytes) { | 60 int64_t File::Write(const void* buffer, int64_t num_bytes) { |
| 61 assert(handle_->fd() >= 0); | 61 ASSERT(handle_->fd() >= 0); |
| 62 return write(handle_->fd(), buffer, num_bytes); | 62 return write(handle_->fd(), buffer, num_bytes); |
| 63 } | 63 } |
| 64 | 64 |
| 65 | 65 |
| 66 off_t File::Position() { | 66 off_t File::Position() { |
| 67 assert(handle_->fd() >= 0); | 67 ASSERT(handle_->fd() >= 0); |
| 68 return lseek(handle_->fd(), 0, SEEK_CUR); | 68 return lseek(handle_->fd(), 0, SEEK_CUR); |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 void File::Flush() { | 72 void File::Flush() { |
| 73 assert(handle_->fd()); | 73 ASSERT(handle_->fd()); |
| 74 _commit(handle_->fd()); | 74 _commit(handle_->fd()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 off_t File::Length() { | 78 off_t File::Length() { |
| 79 assert(handle_->fd() >= 0); | 79 ASSERT(handle_->fd() >= 0); |
| 80 off_t position = lseek(handle_->fd(), 0, SEEK_CUR); | 80 off_t position = lseek(handle_->fd(), 0, SEEK_CUR); |
| 81 if (position < 0) { | 81 if (position < 0) { |
| 82 // The file is not capable of seeking. Return an error. | 82 // The file is not capable of seeking. Return an error. |
| 83 return -1; | 83 return -1; |
| 84 } | 84 } |
| 85 off_t result = lseek(handle_->fd(), 0, SEEK_END); | 85 off_t result = lseek(handle_->fd(), 0, SEEK_END); |
| 86 lseek(handle_->fd(), position, SEEK_SET); | 86 lseek(handle_->fd(), position, SEEK_SET); |
| 87 return result; | 87 return result; |
| 88 } | 88 } |
| 89 | 89 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 121 |
| 122 | 122 |
| 123 const char* File::PathSeparator() { | 123 const char* File::PathSeparator() { |
| 124 return "\\"; | 124 return "\\"; |
| 125 } | 125 } |
| 126 | 126 |
| 127 | 127 |
| 128 const char* File::StringEscapedPathSeparator() { | 128 const char* File::StringEscapedPathSeparator() { |
| 129 return "\\\\"; | 129 return "\\\\"; |
| 130 } | 130 } |
| OLD | NEW |