relibc/header/sys_uio/
mod.rs1use core::slice;
6
7use crate::{
8 header::{errno, limits::IOV_MAX, unistd},
9 platform::{
10 self,
11 types::{c_int, c_void, ssize_t},
12 },
13};
14
15pub use crate::header::bits_iovec::{gather, iovec, scatter};
16
17#[unsafe(no_mangle)]
25pub unsafe extern "C" fn readv(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t {
26 if !(0..=IOV_MAX).contains(&iovcnt) {
27 platform::ERRNO.set(errno::EINVAL);
28 return -1;
29 }
30
31 let iovs = unsafe { slice::from_raw_parts(iov, iovcnt as usize) };
32 let mut vec = unsafe { gather(iovs) };
33
34 let ret = unsafe { unistd::read(fd, vec.as_mut_ptr().cast::<c_void>(), vec.len()) };
35
36 unsafe { scatter(iovs, vec) };
37
38 ret
39}
40
41#[unsafe(no_mangle)]
50pub unsafe extern "C" fn writev(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t {
51 if !(0..=IOV_MAX).contains(&iovcnt) {
52 platform::ERRNO.set(errno::EINVAL);
53 return -1;
54 }
55
56 let iovs = unsafe { slice::from_raw_parts(iov, iovcnt as usize) };
57 let vec = unsafe { gather(iovs) };
58
59 unsafe { unistd::write(fd, vec.as_ptr().cast::<c_void>(), vec.len()) }
60}