From a8182ce667947b33a91e3db03a3688e9f7f565a7 Mon Sep 17 00:00:00 2001 From: Trip Volpe Date: Tue, 7 Jul 2015 20:07:24 -0700 Subject: Add support for preadv and pwritev to sys/uio on Linux. --- src/sys/uio.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/sys/uio.rs') diff --git a/src/sys/uio.rs b/src/sys/uio.rs index 43f0a23a..605ced4c 100644 --- a/src/sys/uio.rs +++ b/src/sys/uio.rs @@ -21,6 +21,18 @@ mod ffi { // doc: http://man7.org/linux/man-pages/man2/readv.2.html pub fn readv(fd: RawFd, iov: *const IoVec<&mut [u8]>, iovcnt: c_int) -> ssize_t; + // vectorized write at a specified offset + // doc: http://man7.org/linux/man-pages/man2/pwritev.2.html + #[cfg(any(target_os = "linux", target_os = "android"))] + pub fn pwritev(fd: RawFd, iov: *const IoVec<&[u8]>, iovcnt: c_int, + offset: off_t) -> ssize_t; + + // vectorized read at a specified offset + // doc: http://man7.org/linux/man-pages/man2/preadv.2.html + #[cfg(any(target_os = "linux", target_os = "android"))] + pub fn preadv(fd: RawFd, iov: *const IoVec<&mut [u8]>, iovcnt: c_int, + offset: off_t) -> ssize_t; + // write to a file at a specified offset // doc: http://man7.org/linux/man-pages/man2/pwrite.2.html pub fn pwrite(fd: RawFd, buf: *const c_void, nbyte: size_t, @@ -52,6 +64,32 @@ pub fn readv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>]) -> Result { return Ok(res as usize) } +#[cfg(any(target_os = "linux", target_os = "android"))] +pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>], + offset: off_t) -> Result { + let res = unsafe { + ffi::pwritev(fd, iov.as_ptr(), iov.len() as c_int, offset) + }; + if res < 0 { + Err(Error::Sys(Errno::last())) + } else { + Ok(res as usize) + } +} + +#[cfg(any(target_os = "linux", target_os = "android"))] +pub fn preadv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>], + offset: off_t) -> Result { + let res = unsafe { + ffi::preadv(fd, iov.as_ptr(), iov.len() as c_int, offset) + }; + if res < 0 { + Err(Error::Sys(Errno::last())) + } else { + Ok(res as usize) + } +} + pub fn pwrite(fd: RawFd, buf: &[u8], offset: off_t) -> Result { let res = unsafe { ffi::pwrite(fd, buf.as_ptr() as *const c_void, buf.len() as size_t, -- cgit v1.2.3