Chromium Code Reviews| Index: runtime/bin/file_openbsd.cc |
| diff --git a/runtime/bin/file_android.cc b/runtime/bin/file_openbsd.cc |
| similarity index 89% |
| copy from runtime/bin/file_android.cc |
| copy to runtime/bin/file_openbsd.cc |
| index cc29740f094e524cddef3672a836566e37de425c..dfa3708b6139f88f371dd71bc68fa5ca8482cfd8 100644 |
| --- a/runtime/bin/file_android.cc |
| +++ b/runtime/bin/file_openbsd.cc |
| @@ -3,7 +3,7 @@ |
| // BSD-style license that can be found in the LICENSE file. |
| #include "platform/globals.h" |
| -#if defined(TARGET_OS_ANDROID) |
| +#if defined(TARGET_OS_OPENBSD) |
| #include "bin/file.h" |
| @@ -11,7 +11,6 @@ |
| #include <fcntl.h> // NOLINT |
| #include <sys/stat.h> // NOLINT |
| #include <sys/types.h> // NOLINT |
| -#include <sys/sendfile.h> // NOLINT |
| #include <unistd.h> // NOLINT |
| #include <libgen.h> // NOLINT |
| @@ -19,7 +18,6 @@ |
| #include "bin/log.h" |
| #include "platform/signal_blocker.h" |
| -#include "platform/utils.h" |
| namespace dart { |
| @@ -58,7 +56,7 @@ void File::Close() { |
| if (err != 0) { |
| const int kBufferSize = 1024; |
| char error_message[kBufferSize]; |
| - Utils::StrError(errno, error_message, kBufferSize); |
| + strerror_r(errno, error_message, kBufferSize); |
| Log::PrintErr("%s\n", error_message); |
| } |
| } |
| @@ -90,13 +88,13 @@ int64_t File::Write(const void* buffer, int64_t num_bytes) { |
| int64_t File::Position() { |
| ASSERT(handle_->fd() >= 0); |
| - return NO_RETRY_EXPECTED(lseek64(handle_->fd(), 0, SEEK_CUR)); |
| + return NO_RETRY_EXPECTED(lseek(handle_->fd(), 0, SEEK_CUR)); |
| } |
| bool File::SetPosition(int64_t position) { |
| ASSERT(handle_->fd() >= 0); |
| - return NO_RETRY_EXPECTED(lseek64(handle_->fd(), position, SEEK_SET)) >= 0; |
| + return NO_RETRY_EXPECTED(lseek(handle_->fd(), position, SEEK_SET)) >= 0; |
| } |
| @@ -176,7 +174,7 @@ File* File::Open(const char* name, FileOpenMode mode) { |
| } |
| if ((((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) || |
| (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { |
| - int64_t position = lseek64(fd, 0, SEEK_END); |
| + int64_t position = lseek(fd, 0, SEEK_END); |
| if (position < 0) { |
| return NULL; |
| } |
| @@ -282,28 +280,21 @@ bool File::Copy(const char* old_path, const char* new_path) { |
| VOID_TEMP_FAILURE_RETRY(close(old_fd)); |
| return false; |
| } |
| - off_t offset = 0; |
| + |
| int result = 1; |
| - while (result > 0) { |
| - // Loop to ensure we copy everything, and not only up to 2GB. |
| - result = NO_RETRY_EXPECTED( |
| - sendfile(new_fd, old_fd, &offset, kMaxUint32)); |
| - } |
| - // From sendfile man pages: |
| - // Applications may wish to fall back to read(2)/write(2) in the case |
| - // where sendfile() fails with EINVAL or ENOSYS. |
| - if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { |
| - const intptr_t kBufferSize = 8 * KB; |
| - uint8_t buffer[kBufferSize]; |
| - while ((result = TEMP_FAILURE_RETRY( |
| - read(old_fd, buffer, kBufferSize))) > 0) { |
| - int wrote = TEMP_FAILURE_RETRY(write(new_fd, buffer, result)); |
| - if (wrote != result) { |
| - result = -1; |
| - break; |
| - } |
| + // OpenBSD has no sendfile so use read(2)/write(2) to copy the file |
| + const intptr_t kBufferSize = 8 * KB; |
| + uint8_t buffer[kBufferSize]; |
| + while ((result = TEMP_FAILURE_RETRY(read(old_fd, |
| + buffer, |
| + kBufferSize))) > 0) { |
| + int wrote = TEMP_FAILURE_RETRY(write(new_fd, buffer, result)); |
|
Ivan Posva
2016/01/11 23:58:40
Please add a TODO to deal with short writes. We wi
mulander
2016/01/12 00:22:45
Acknowledged.
|
| + if (wrote != result) { |
| + result = -1; |
| + break; |
| } |
| } |
| + |
| int e = errno; |
| VOID_TEMP_FAILURE_RETRY(close(old_fd)); |
| VOID_TEMP_FAILURE_RETRY(close(new_fd)); |
| @@ -423,7 +414,7 @@ File::StdioHandleType File::GetStdioHandleType(int fd) { |
| if (result == -1) { |
| const int kBufferSize = 1024; |
| char error_message[kBufferSize]; |
| - Utils::StrError(errno, error_message, kBufferSize); |
| + strerror_r(errno, error_message, kBufferSize); |
| FATAL2("Failed stat on file descriptor %d: %s", fd, error_message); |
| } |
| if (S_ISCHR(buf.st_mode)) return kTerminal; |
| @@ -466,4 +457,4 @@ File::Identical File::AreIdentical(const char* file_1, const char* file_2) { |
| } // namespace bin |
| } // namespace dart |
| -#endif // defined(TARGET_OS_ANDROID) |
| +#endif // defined(TARGET_OS_OPENBSD) |