about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorNicolas Koch <nioko1337@gmail.com>2018-05-16 10:35:19 +0200
committerNicolas Koch <nioko1337@gmail.com>2018-05-16 10:35:19 +0200
commita5e2942861324493c2cc5a32cb1473e656857b98 (patch)
tree3a4888d3c1c33bd2bf77b3398db59581af5b2a0d /src/libstd/sys
parentf4c2825c8f80eae6ef18eb3fa30464a18a588e0f (diff)
downloadrust-a5e2942861324493c2cc5a32cb1473e656857b98.tar.gz
rust-a5e2942861324493c2cc5a32cb1473e656857b98.zip
Fix large file copies on 32 bit platforms
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/fs.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs
index c9d187f2ff2..d8739d65326 100644
--- a/src/libstd/sys/unix/fs.rs
+++ b/src/libstd/sys/unix/fs.rs
@@ -815,7 +815,11 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
 
     let mut written = 0u64;
     while written < len {
-        let bytes_to_copy = len - written;
+        let bytes_to_copy = if len - written > usize::max_value() as u64 {
+            usize::max_value()
+        } else {
+            (len - written) as usize
+        };
         let copy_result = unsafe {
             // We actually don't have to adjust the offsets,
             // because copy_file_range adjusts the file offset automatically
@@ -823,7 +827,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
                                 ptr::null_mut(),
                                 writer.as_raw_fd(),
                                 ptr::null_mut(),
-                                bytes_to_copy as usize,
+                                bytes_to_copy,
                                 0)
                 )
         };