| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 VOID_TEMP_FAILURE_RETRY(close(old_fd)); | 238 VOID_TEMP_FAILURE_RETRY(close(old_fd)); |
| 239 return false; | 239 return false; |
| 240 } | 240 } |
| 241 off64_t offset = 0; | 241 off64_t offset = 0; |
| 242 int result = 1; | 242 int result = 1; |
| 243 while (result > 0) { | 243 while (result > 0) { |
| 244 // Loop to ensure we copy everything, and not only up to 2GB. | 244 // Loop to ensure we copy everything, and not only up to 2GB. |
| 245 result = TEMP_FAILURE_RETRY( | 245 result = TEMP_FAILURE_RETRY( |
| 246 sendfile64(new_fd, old_fd, &offset, kMaxUint32)); | 246 sendfile64(new_fd, old_fd, &offset, kMaxUint32)); |
| 247 } | 247 } |
| 248 // From sendfile man pages: |
| 249 // Applications may wish to fall back to read(2)/write(2) in the case |
| 250 // where sendfile() fails with EINVAL or ENOSYS. |
| 248 if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { | 251 if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { |
| 249 const intptr_t kBufferSize = 8 * 1024; | 252 const intptr_t kBufferSize = 8 * 1024; |
| 250 uint8_t buffer[kBufferSize]; | 253 uint8_t buffer[kBufferSize]; |
| 251 while ((result = TEMP_FAILURE_RETRY( | 254 while ((result = TEMP_FAILURE_RETRY( |
| 252 read(old_fd, buffer, kBufferSize))) > 0) { | 255 read(old_fd, buffer, kBufferSize))) > 0) { |
| 253 int wrote = TEMP_FAILURE_RETRY(write(new_fd, buffer, result)); | 256 int wrote = TEMP_FAILURE_RETRY(write(new_fd, buffer, result)); |
| 254 if (wrote != result) { | 257 if (wrote != result) { |
| 255 result = -1; | 258 result = -1; |
| 256 break; | 259 break; |
| 257 } | 260 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 return (file_1_info.st_ino == file_2_info.st_ino && | 409 return (file_1_info.st_ino == file_2_info.st_ino && |
| 407 file_1_info.st_dev == file_2_info.st_dev) ? | 410 file_1_info.st_dev == file_2_info.st_dev) ? |
| 408 File::kIdentical : | 411 File::kIdentical : |
| 409 File::kDifferent; | 412 File::kDifferent; |
| 410 } | 413 } |
| 411 | 414 |
| 412 } // namespace bin | 415 } // namespace bin |
| 413 } // namespace dart | 416 } // namespace dart |
| 414 | 417 |
| 415 #endif // defined(TARGET_OS_LINUX) | 418 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |