summaryrefslogtreecommitdiff
path: root/src/sys/uio.rs
diff options
context:
space:
mode:
authorKamal Marhubi <kamal@marhubi.com>2016-03-10 01:09:12 -0500
committerKamal Marhubi <kamal@marhubi.com>2016-03-10 01:09:12 -0500
commit5089e0f8be4d826b490adec55f5ed60be68b4f3b (patch)
tree58a3fc2e51761120e192b617698200761716402b /src/sys/uio.rs
parentf848e2ce467878004946979fa174a1c0f85c3bad (diff)
downloadnix-5089e0f8be4d826b490adec55f5ed60be68b4f3b.zip
uio: Use bindings from libc instead of our own
Refs https://github.com/nix-rust/nix/issues/264
Diffstat (limited to 'src/sys/uio.rs')
-rw-r--r--src/sys/uio.rs72
1 files changed, 14 insertions, 58 deletions
diff --git a/src/sys/uio.rs b/src/sys/uio.rs
index 03f2a3a8..5af10930 100644
--- a/src/sys/uio.rs
+++ b/src/sys/uio.rs
@@ -2,56 +2,18 @@
#![allow(improper_ctypes)]
use {Errno, Result};
-use libc::{c_int, c_void, size_t, off_t};
+use libc::{self, c_int, c_void, size_t, off_t};
use std::marker::PhantomData;
use std::os::unix::io::RawFd;
-mod ffi {
- use super::IoVec;
- use libc::{ssize_t, c_int, size_t, off_t, c_void};
- use std::os::unix::io::RawFd;
-
- extern {
- // vectorized version of write
- // doc: http://man7.org/linux/man-pages/man2/writev.2.html
- pub fn writev(fd: RawFd, iov: *const IoVec<&[u8]>, iovcnt: c_int) -> ssize_t;
-
- // vectorized version of read
- // 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(feature = "preadv_pwritev")]
- 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(feature = "preadv_pwritev")]
- 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,
- offset: off_t) -> ssize_t;
-
- // read from a file at a specified offset
- // doc: http://man7.org/linux/man-pages/man2/pread.2.html
- pub fn pread(fd: RawFd, buf: *mut c_void, nbyte: size_t, offset: off_t)
- -> ssize_t;
- }
-}
-
pub fn writev(fd: RawFd, iov: &[IoVec<&[u8]>]) -> Result<usize> {
- let res = unsafe { ffi::writev(fd, iov.as_ptr(), iov.len() as c_int) };
+ let res = unsafe { libc::writev(fd, iov.as_ptr() as *const libc::iovec, iov.len() as c_int) };
Errno::result(res).map(|r| r as usize)
}
pub fn readv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>]) -> Result<usize> {
- let res = unsafe { ffi::readv(fd, iov.as_ptr(), iov.len() as c_int) };
+ let res = unsafe { libc::readv(fd, iov.as_ptr() as *const libc::iovec, iov.len() as c_int) };
Errno::result(res).map(|r| r as usize)
}
@@ -60,7 +22,7 @@ pub fn readv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>]) -> Result<usize> {
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)
+ libc::pwritev(fd, iov.as_ptr() as *const libc::iovec, iov.len() as c_int, offset)
};
Errno::result(res).map(|r| r as usize)
@@ -70,7 +32,7 @@ pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>],
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)
+ libc::preadv(fd, iov.as_ptr() as *const libc::iovec, iov.len() as c_int, offset)
};
Errno::result(res).map(|r| r as usize)
@@ -78,7 +40,7 @@ pub fn preadv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>],
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,
+ libc::pwrite(fd, buf.as_ptr() as *const c_void, buf.len() as size_t,
offset)
};
@@ -87,7 +49,7 @@ pub fn pwrite(fd: RawFd, buf: &[u8], offset: off_t) -> Result<usize> {
pub fn pread(fd: RawFd, buf: &mut [u8], offset: off_t) -> Result<usize>{
let res = unsafe {
- ffi::pread(fd, buf.as_mut_ptr() as *mut c_void, buf.len() as size_t,
+ libc::pread(fd, buf.as_mut_ptr() as *mut c_void, buf.len() as size_t,
offset)
};
@@ -95,11 +57,7 @@ pub fn pread(fd: RawFd, buf: &mut [u8], offset: off_t) -> Result<usize>{
}
#[repr(C)]
-pub struct IoVec<T> {
- iov_base: *mut c_void,
- iov_len: size_t,
- phantom: PhantomData<T>
-}
+pub struct IoVec<T>(libc::iovec, PhantomData<T>);
impl<T> IoVec<T> {
#[inline]
@@ -108,29 +66,27 @@ impl<T> IoVec<T> {
unsafe {
slice::from_raw_parts(
- self.iov_base as *const u8,
- self.iov_len as usize)
+ self.0.iov_base as *const u8,
+ self.0.iov_len as usize)
}
}
}
impl<'a> IoVec<&'a [u8]> {
pub fn from_slice(buf: &'a [u8]) -> IoVec<&'a [u8]> {
- IoVec {
+ IoVec(libc::iovec {
iov_base: buf.as_ptr() as *mut c_void,
iov_len: buf.len() as size_t,
- phantom: PhantomData
- }
+ }, PhantomData)
}
}
impl<'a> IoVec<&'a mut [u8]> {
pub fn from_mut_slice(buf: &'a mut [u8]) -> IoVec<&'a mut [u8]> {
- IoVec {
+ IoVec(libc::iovec {
iov_base: buf.as_ptr() as *mut c_void,
iov_len: buf.len() as size_t,
- phantom: PhantomData
- }
+ }, PhantomData)
}
}