summaryrefslogtreecommitdiff
path: root/src/sys/uio.rs
diff options
context:
space:
mode:
authorTrip Volpe <trip.volpe@gmail.com>2015-07-07 20:07:24 -0700
committerCarl Lerche <me@carllerche.com>2015-07-13 11:41:48 -0700
commita8182ce667947b33a91e3db03a3688e9f7f565a7 (patch)
tree0b204e59ddb4a79e0bdfeb867ffa21e4d842ac65 /src/sys/uio.rs
parenta5e9cc637b187d5c3446d1b90abea2c67031d9e9 (diff)
downloadnix-a8182ce667947b33a91e3db03a3688e9f7f565a7.zip
Add support for preadv and pwritev to sys/uio on Linux.
Diffstat (limited to 'src/sys/uio.rs')
-rw-r--r--src/sys/uio.rs38
1 files changed, 38 insertions, 0 deletions
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<usize> {
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<usize> {
+ 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<usize> {
+ 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<usize> {
let res = unsafe {
ffi::pwrite(fd, buf.as_ptr() as *const c_void, buf.len() as size_t,