Skip to content

Commit 93e9f5e

Browse files
committed
Document Linux kernel handoff in std::io::copy and std::fs::copy
1 parent 37b55c8 commit 93e9f5e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

library/std/src/fs.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1729,10 +1729,16 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
17291729
/// This function currently corresponds to the `open` function in Unix
17301730
/// with `O_RDONLY` for `from` and `O_WRONLY`, `O_CREAT`, and `O_TRUNC` for `to`.
17311731
/// `O_CLOEXEC` is set for returned file descriptors.
1732+
///
1733+
/// On Linux (including Android), this function attempts to use `copy_file_range(2)`,
1734+
/// and falls back to reading and writing if that is not possible.
1735+
///
17321736
/// On Windows, this function currently corresponds to `CopyFileEx`. Alternate
17331737
/// NTFS streams are copied but only the size of the main stream is returned by
1734-
/// this function. On MacOS, this function corresponds to `fclonefileat` and
1735-
/// `fcopyfile`.
1738+
/// this function.
1739+
///
1740+
/// On MacOS, this function corresponds to `fclonefileat` and `fcopyfile`.
1741+
///
17361742
/// Note that, this [may change in the future][changes].
17371743
///
17381744
/// [changes]: io#platform-specific-behavior

library/std/src/io/copy.rs

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ use crate::mem::MaybeUninit;
3939
/// Ok(())
4040
/// }
4141
/// ```
42+
///
43+
/// # Platform-specific behavior
44+
///
45+
/// On Linux (including Android), this function uses `copy_file_range(2)`,
46+
/// `sendfile(2)` or `splice(2)` syscalls to move data directly between file
47+
/// descriptors if possible.
4248
#[stable(feature = "rust1", since = "1.0.0")]
4349
pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> Result<u64>
4450
where

0 commit comments

Comments
 (0)