diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-03-30 09:10:04 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-30 09:10:04 +0200 |
| commit | e332f3b45eb1df4ee322e0ce4d53b90d6eaa520a (patch) | |
| tree | 8257b0f44e7e39e5186beaf5af6d66d85b8140ea | |
| parent | 1446d17b8f4bd3ff8dbfb129a7674165e06f9f4c (diff) | |
| parent | cfee2ed8cb1c77e5bf841d52771e95e99f4fcac3 (diff) | |
| download | rust-e332f3b45eb1df4ee322e0ce4d53b90d6eaa520a.tar.gz rust-e332f3b45eb1df4ee322e0ce4d53b90d6eaa520a.zip | |
Rollup merge of #95294 - sourcefrog:doc-copy, r=dtolnay
Document Linux kernel handoff in std::io::copy and std::fs::copy
| -rw-r--r-- | library/std/src/fs.rs | 12 | ||||
| -rw-r--r-- | library/std/src/io/copy.rs | 10 |
2 files changed, 19 insertions, 3 deletions
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index d4e103ab525..46acd0ee4c5 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -1729,11 +1729,17 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> /// This function currently corresponds to the `open` function in Unix /// with `O_RDONLY` for `from` and `O_WRONLY`, `O_CREAT`, and `O_TRUNC` for `to`. /// `O_CLOEXEC` is set for returned file descriptors. +/// +/// On Linux (including Android), this function attempts to use `copy_file_range(2)`, +/// and falls back to reading and writing if that is not possible. +/// /// On Windows, this function currently corresponds to `CopyFileEx`. Alternate /// NTFS streams are copied but only the size of the main stream is returned by -/// this function. On MacOS, this function corresponds to `fclonefileat` and -/// `fcopyfile`. -/// Note that, this [may change in the future][changes]. +/// this function. +/// +/// On MacOS, this function corresponds to `fclonefileat` and `fcopyfile`. +/// +/// Note that platform-specific behavior [may change in the future][changes]. /// /// [changes]: io#platform-specific-behavior /// diff --git a/library/std/src/io/copy.rs b/library/std/src/io/copy.rs index 6ab96662305..1a10245e4a5 100644 --- a/library/std/src/io/copy.rs +++ b/library/std/src/io/copy.rs @@ -39,6 +39,16 @@ use crate::mem::MaybeUninit; /// Ok(()) /// } /// ``` +/// +/// # Platform-specific behavior +/// +/// On Linux (including Android), this function uses `copy_file_range(2)`, +/// `sendfile(2)` or `splice(2)` syscalls to move data directly between file +/// descriptors if possible. +/// +/// Note that platform-specific behavior [may change in the future][changes]. +/// +/// [changes]: crate::io#platform-specific-behavior #[stable(feature = "rust1", since = "1.0.0")] pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> Result<u64> where |
