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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); | 113 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 int64_t File::Write(const void* buffer, int64_t num_bytes) { | 117 int64_t File::Write(const void* buffer, int64_t num_bytes) { |
118 ASSERT(handle_->fd() >= 0); | 118 ASSERT(handle_->fd() >= 0); |
119 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); | 119 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); |
120 } | 120 } |
121 | 121 |
122 | 122 |
| 123 bool File::VPrint(const char* format, va_list args) { |
| 124 // Measure. |
| 125 va_list measure_args; |
| 126 va_copy(measure_args, args); |
| 127 intptr_t len = vsnprintf(NULL, 0, format, measure_args); |
| 128 va_end(measure_args); |
| 129 |
| 130 char* buffer = reinterpret_cast<char*>(malloc(len + 1)); |
| 131 |
| 132 // Print. |
| 133 va_list print_args; |
| 134 va_copy(print_args, args); |
| 135 vsnprintf(buffer, len + 1, format, print_args); |
| 136 va_end(print_args); |
| 137 |
| 138 bool result = WriteFully(buffer, len); |
| 139 free(buffer); |
| 140 return result; |
| 141 } |
| 142 |
123 int64_t File::Position() { | 143 int64_t File::Position() { |
124 ASSERT(handle_->fd() >= 0); | 144 ASSERT(handle_->fd() >= 0); |
125 return NO_RETRY_EXPECTED(lseek64(handle_->fd(), 0, SEEK_CUR)); | 145 return NO_RETRY_EXPECTED(lseek64(handle_->fd(), 0, SEEK_CUR)); |
126 } | 146 } |
127 | 147 |
128 | 148 |
129 bool File::SetPosition(int64_t position) { | 149 bool File::SetPosition(int64_t position) { |
130 ASSERT(handle_->fd() >= 0); | 150 ASSERT(handle_->fd() >= 0); |
131 return NO_RETRY_EXPECTED(lseek64(handle_->fd(), position, SEEK_SET)) >= 0; | 151 return NO_RETRY_EXPECTED(lseek64(handle_->fd(), position, SEEK_SET)) >= 0; |
132 } | 152 } |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 return ((file_1_info.st_ino == file_2_info.st_ino) && | 614 return ((file_1_info.st_ino == file_2_info.st_ino) && |
595 (file_1_info.st_dev == file_2_info.st_dev)) | 615 (file_1_info.st_dev == file_2_info.st_dev)) |
596 ? File::kIdentical | 616 ? File::kIdentical |
597 : File::kDifferent; | 617 : File::kDifferent; |
598 } | 618 } |
599 | 619 |
600 } // namespace bin | 620 } // namespace bin |
601 } // namespace dart | 621 } // namespace dart |
602 | 622 |
603 #endif // defined(TARGET_OS_LINUX) | 623 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |