summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-30 16:26:41 +0000
committerGitHub <noreply@github.com>2021-05-30 16:26:41 +0000
commitdf9ed9314d61cc0598de60a401800a24f9c68850 (patch)
treea0e4ba3b0d76096df355f2f4490022d9638f2602 /src
parent33df3e7cb638eb3c088f0def18a2d649562c4499 (diff)
parentfb5d942c3cf35b842e913a4cd1ec9a5528a38664 (diff)
downloadnix-df9ed9314d61cc0598de60a401800a24f9c68850.zip
Merge #1439
1439: Add sendfile64 r=asomers a=tdryer `sendfile64` is a Linux-specific call with a wider type for the `offset` argument than `sendfile`. This is largely a copy of the existing `sendfile` function and associated test. Co-authored-by: Tom Dryer <tomdryer.com@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/sys/sendfile.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/sys/sendfile.rs b/src/sys/sendfile.rs
index d44672c7..a12c0411 100644
--- a/src/sys/sendfile.rs
+++ b/src/sys/sendfile.rs
@@ -33,6 +33,32 @@ pub fn sendfile(
Errno::result(ret).map(|r| r as usize)
}
+/// Copy up to `count` bytes to `out_fd` from `in_fd` starting at `offset`.
+///
+/// Returns a `Result` with the number of bytes written.
+///
+/// If `offset` is `None`, `sendfile` will begin reading at the current offset of `in_fd`and will
+/// update the offset of `in_fd`. If `offset` is `Some`, `sendfile` will begin at the specified
+/// offset and will not update the offset of `in_fd`. Instead, it will mutate `offset` to point to
+/// the byte after the last byte copied.
+///
+/// `in_fd` must support `mmap`-like operations and therefore cannot be a socket.
+///
+/// For more information, see [the sendfile(2) man page.](https://man7.org/linux/man-pages/man2/sendfile.2.html)
+#[cfg(target_os = "linux")]
+pub fn sendfile64(
+ out_fd: RawFd,
+ in_fd: RawFd,
+ offset: Option<&mut libc::off64_t>,
+ count: usize,
+) -> Result<usize> {
+ let offset = offset
+ .map(|offset| offset as *mut _)
+ .unwrap_or(ptr::null_mut());
+ let ret = unsafe { libc::sendfile64(out_fd, in_fd, offset, count) };
+ Errno::result(ret).map(|r| r as usize)
+}
+
cfg_if! {
if #[cfg(any(target_os = "freebsd",
target_os = "ios",