summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/mod.rs3
-rw-r--r--src/sys/sendfile.rs12
2 files changed, 15 insertions, 0 deletions
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index c7fdc4dc..de449b76 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -16,6 +16,9 @@ pub mod memfd;
#[cfg(not(any(target_os = "ios", target_os = "freebsd", target_os = "dragonfly")))]
pub mod ioctl;
+#[cfg(any(target_os = "linux", target_os = "android"))]
+pub mod sendfile;
+
pub mod signal;
#[cfg(any(target_os = "linux", target_os = "android"))]
diff --git a/src/sys/sendfile.rs b/src/sys/sendfile.rs
new file mode 100644
index 00000000..2c39ea90
--- /dev/null
+++ b/src/sys/sendfile.rs
@@ -0,0 +1,12 @@
+use std::os::unix::io::RawFd;
+use std::ptr;
+
+use libc::{self, off_t};
+
+use {Errno, Result};
+
+pub fn sendfile(out_fd: RawFd, in_fd: RawFd, offset: Option<&mut off_t>, count: usize) -> Result<usize> {
+ let offset = offset.map(|offset| offset as *mut _).unwrap_or(ptr::null_mut());
+ let ret = unsafe { libc::sendfile(out_fd, in_fd, offset, count) };
+ Errno::result(ret).map(|r| r as usize)
+}