Skip to content

Commit a5e2942

Browse files
committed
Fix large file copies on 32 bit platforms
1 parent f4c2825 commit a5e2942

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/libstd/sys/unix/fs.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,15 +815,19 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
815815

816816
let mut written = 0u64;
817817
while written < len {
818-
let bytes_to_copy = len - written;
818+
let bytes_to_copy = if len - written > usize::max_value() as u64 {
819+
usize::max_value()
820+
} else {
821+
(len - written) as usize
822+
};
819823
let copy_result = unsafe {
820824
// We actually don't have to adjust the offsets,
821825
// because copy_file_range adjusts the file offset automatically
822826
cvt(copy_file_range(reader.as_raw_fd(),
823827
ptr::null_mut(),
824828
writer.as_raw_fd(),
825829
ptr::null_mut(),
826-
bytes_to_copy as usize,
830+
bytes_to_copy,
827831
0)
828832
)
829833
};

0 commit comments

Comments
 (0)