summaryrefslogtreecommitdiff
path: root/src/sys/uio.rs
diff options
context:
space:
mode:
authorAlex Saveau <saveau.alexandre@gmail.com>2022-11-06 11:27:08 -0800
committerAlex Saveau <saveau.alexandre@gmail.com>2022-11-06 11:39:09 -0800
commit17833268cb3269d83766bcdb4d9cbe0e25ebd38e (patch)
treeb86885991e1d8b6f9c610747c2e8c3a3370960cd /src/sys/uio.rs
parent20df092bd067908fba23e49120eed7ad62f29108 (diff)
downloadnix-17833268cb3269d83766bcdb4d9cbe0e25ebd38e.zip
Reformat everything
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
Diffstat (limited to 'src/sys/uio.rs')
-rw-r--r--src/sys/uio.rs95
1 files changed, 58 insertions, 37 deletions
diff --git a/src/sys/uio.rs b/src/sys/uio.rs
index 7cddb372..b31c3068 100644
--- a/src/sys/uio.rs
+++ b/src/sys/uio.rs
@@ -1,8 +1,8 @@
//! Vectored I/O
-use crate::Result;
use crate::errno::Errno;
-use libc::{self, c_int, c_void, size_t, off_t};
+use crate::Result;
+use libc::{self, c_int, c_void, off_t, size_t};
use std::io::{IoSlice, IoSliceMut};
use std::marker::PhantomData;
use std::os::unix::io::RawFd;
@@ -12,13 +12,15 @@ use std::os::unix::io::RawFd;
/// See also [writev(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/writev.html)
pub fn writev(fd: RawFd, iov: &[IoSlice<'_>]) -> Result<usize> {
// SAFETY: to quote the documentation for `IoSlice`:
- //
- // [IoSlice] is semantically a wrapper around a &[u8], but is
+ //
+ // [IoSlice] is semantically a wrapper around a &[u8], but is
// guaranteed to be ABI compatible with the iovec type on Unix
// platforms.
//
// Because it is ABI compatible, a pointer cast here is valid
- let res = unsafe { libc::writev(fd, iov.as_ptr() as *const libc::iovec, 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)
}
@@ -28,7 +30,9 @@ pub fn writev(fd: RawFd, iov: &[IoSlice<'_>]) -> Result<usize> {
/// See also [readv(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/readv.html)
pub fn readv(fd: RawFd, iov: &mut [IoSliceMut<'_>]) -> Result<usize> {
// SAFETY: same as in writev(), IoSliceMut is ABI-compatible with iovec
- let res = unsafe { libc::readv(fd, iov.as_ptr() as *const libc::iovec, 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)
}
@@ -41,15 +45,18 @@ pub fn readv(fd: RawFd, iov: &mut [IoSliceMut<'_>]) -> Result<usize> {
/// See also: [`writev`](fn.writev.html) and [`pwrite`](fn.pwrite.html)
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
#[cfg_attr(docsrs, doc(cfg(all())))]
-pub fn pwritev(fd: RawFd, iov: &[IoSlice<'_>],
- offset: off_t) -> Result<usize> {
-
+pub fn pwritev(fd: RawFd, iov: &[IoSlice<'_>], offset: off_t) -> Result<usize> {
#[cfg(target_env = "uclibc")]
let offset = offset as libc::off64_t; // uclibc doesn't use off_t
// SAFETY: same as in writev()
let res = unsafe {
- libc::pwritev(fd, iov.as_ptr() as *const libc::iovec, 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)
@@ -64,14 +71,22 @@ pub fn pwritev(fd: RawFd, iov: &[IoSlice<'_>],
/// See also: [`readv`](fn.readv.html) and [`pread`](fn.pread.html)
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
#[cfg_attr(docsrs, doc(cfg(all())))]
-pub fn preadv(fd: RawFd, iov: &mut [IoSliceMut<'_>],
- offset: off_t) -> Result<usize> {
+pub fn preadv(
+ fd: RawFd,
+ iov: &mut [IoSliceMut<'_>],
+ offset: off_t,
+) -> Result<usize> {
#[cfg(target_env = "uclibc")]
let offset = offset as libc::off64_t; // uclibc doesn't use off_t
// SAFETY: same as in readv()
let res = unsafe {
- libc::preadv(fd, iov.as_ptr() as *const libc::iovec, 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)
@@ -83,8 +98,12 @@ pub fn preadv(fd: RawFd, iov: &mut [IoSliceMut<'_>],
// TODO: move to unistd
pub fn pwrite(fd: RawFd, buf: &[u8], offset: off_t) -> Result<usize> {
let res = unsafe {
- libc::pwrite(fd, buf.as_ptr() as *const c_void, buf.len() as size_t,
- offset)
+ libc::pwrite(
+ fd,
+ buf.as_ptr() as *const c_void,
+ buf.len() as size_t,
+ offset,
+ )
};
Errno::result(res).map(|r| r as usize)
@@ -94,10 +113,14 @@ pub fn pwrite(fd: RawFd, buf: &[u8], offset: off_t) -> Result<usize> {
///
/// See also [pread(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html)
// TODO: move to unistd
-pub fn pread(fd: RawFd, buf: &mut [u8], offset: off_t) -> Result<usize>{
+pub fn pread(fd: RawFd, buf: &mut [u8], offset: off_t) -> Result<usize> {
let res = unsafe {
- libc::pread(fd, buf.as_mut_ptr() as *mut c_void, buf.len() as size_t,
- offset)
+ libc::pread(
+ fd,
+ buf.as_mut_ptr() as *mut c_void,
+ buf.len() as size_t,
+ offset,
+ )
};
Errno::result(res).map(|r| r as usize)
@@ -151,9 +174,7 @@ impl<T> IoVec<T> {
use std::slice;
unsafe {
- slice::from_raw_parts(
- self.0.iov_base as *const u8,
- self.0.iov_len)
+ slice::from_raw_parts(self.0.iov_base as *const u8, self.0.iov_len)
}
}
}
@@ -161,30 +182,30 @@ impl<T> IoVec<T> {
#[allow(deprecated)]
impl<'a> IoVec<&'a [u8]> {
/// Create an `IoVec` from a Rust slice.
- #[deprecated(
- since = "0.24.0",
- note = "Use `IoSlice::new` instead"
- )]
+ #[deprecated(since = "0.24.0", note = "Use `IoSlice::new` instead")]
pub fn from_slice(buf: &'a [u8]) -> IoVec<&'a [u8]> {
- IoVec(libc::iovec {
- iov_base: buf.as_ptr() as *mut c_void,
- iov_len: buf.len() as size_t,
- }, PhantomData)
+ IoVec(
+ libc::iovec {
+ iov_base: buf.as_ptr() as *mut c_void,
+ iov_len: buf.len() as size_t,
+ },
+ PhantomData,
+ )
}
}
#[allow(deprecated)]
impl<'a> IoVec<&'a mut [u8]> {
/// Create an `IoVec` from a mutable Rust slice.
- #[deprecated(
- since = "0.24.0",
- note = "Use `IoSliceMut::new` instead"
- )]
+ #[deprecated(since = "0.24.0", note = "Use `IoSliceMut::new` instead")]
pub fn from_mut_slice(buf: &'a mut [u8]) -> IoVec<&'a mut [u8]> {
- IoVec(libc::iovec {
- iov_base: buf.as_ptr() as *mut c_void,
- iov_len: buf.len() as size_t,
- }, PhantomData)
+ IoVec(
+ libc::iovec {
+ iov_base: buf.as_ptr() as *mut c_void,
+ iov_len: buf.len() as size_t,
+ },
+ PhantomData,
+ )
}
}