| 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> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 return TEMP_FAILURE_RETRY(lseek(handle_->fd(), position, SEEK_SET) != -1); | 79 return TEMP_FAILURE_RETRY(lseek(handle_->fd(), position, SEEK_SET) != -1); |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 bool File::Truncate(int64_t length) { | 83 bool File::Truncate(int64_t length) { |
| 84 ASSERT(handle_->fd() >= 0); | 84 ASSERT(handle_->fd() >= 0); |
| 85 return TEMP_FAILURE_RETRY(ftruncate(handle_->fd(), length) != -1); | 85 return TEMP_FAILURE_RETRY(ftruncate(handle_->fd(), length) != -1); |
| 86 } | 86 } |
| 87 | 87 |
| 88 | 88 |
| 89 void File::Flush() { | 89 bool File::Flush() { |
| 90 ASSERT(handle_->fd() >= 0); | 90 ASSERT(handle_->fd() >= 0); |
| 91 TEMP_FAILURE_RETRY(fsync(handle_->fd())); | 91 return TEMP_FAILURE_RETRY(fsync(handle_->fd()) != -1); |
| 92 } | 92 } |
| 93 | 93 |
| 94 | 94 |
| 95 off_t File::Length() { | 95 off_t File::Length() { |
| 96 ASSERT(handle_->fd() >= 0); | 96 ASSERT(handle_->fd() >= 0); |
| 97 off_t position = TEMP_FAILURE_RETRY(lseek(handle_->fd(), 0, SEEK_CUR)); | 97 off_t position = TEMP_FAILURE_RETRY(lseek(handle_->fd(), 0, SEEK_CUR)); |
| 98 if (position < 0) { | 98 if (position < 0) { |
| 99 // The file is not capable of seeking. Return an error. | 99 // The file is not capable of seeking. Return an error. |
| 100 return -1; | 100 return -1; |
| 101 } | 101 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 int result = fstat(fd, &buf); | 227 int result = fstat(fd, &buf); |
| 228 if (result == -1) { | 228 if (result == -1) { |
| 229 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); | 229 FATAL2("Failed stat on file descriptor %d: %s", fd, strerror(errno)); |
| 230 } | 230 } |
| 231 if (S_ISCHR(buf.st_mode)) return kTerminal; | 231 if (S_ISCHR(buf.st_mode)) return kTerminal; |
| 232 if (S_ISFIFO(buf.st_mode)) return kPipe; | 232 if (S_ISFIFO(buf.st_mode)) return kPipe; |
| 233 if (S_ISSOCK(buf.st_mode)) return kSocket; | 233 if (S_ISSOCK(buf.st_mode)) return kSocket; |
| 234 if (S_ISREG(buf.st_mode)) return kFile; | 234 if (S_ISREG(buf.st_mode)) return kFile; |
| 235 return kOther; | 235 return kOther; |
| 236 } | 236 } |
| OLD | NEW |