diff options
Diffstat (limited to 'vendor/rustix/src/backend/libc/io/syscalls.rs')
-rw-r--r-- | vendor/rustix/src/backend/libc/io/syscalls.rs | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/vendor/rustix/src/backend/libc/io/syscalls.rs b/vendor/rustix/src/backend/libc/io/syscalls.rs index 362af11ee..19ecfa9b6 100644 --- a/vendor/rustix/src/backend/libc/io/syscalls.rs +++ b/vendor/rustix/src/backend/libc/io/syscalls.rs @@ -15,6 +15,7 @@ use crate::io::DupFlags; #[cfg(linux_kernel)] use crate::io::ReadWriteFlags; use crate::io::{self, FdFlags}; +use crate::ioctl::{IoctlOutput, RawOpcode}; use core::cmp::min; #[cfg(all(feature = "fs", feature = "net"))] use libc_errno::errno; @@ -78,7 +79,7 @@ pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], offset: u64) -> io::Result< } #[cfg(not(target_os = "espidf"))] -pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<usize> { +pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> { unsafe { ret_usize(c::readv( borrowed_fd(fd), @@ -89,7 +90,7 @@ pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<u } #[cfg(not(target_os = "espidf"))] -pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize> { +pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>]) -> io::Result<usize> { unsafe { ret_usize(c::writev( borrowed_fd(fd), @@ -108,7 +109,7 @@ pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize> )))] pub(crate) fn preadv( fd: BorrowedFd<'_>, - bufs: &mut [IoSliceMut], + bufs: &mut [IoSliceMut<'_>], offset: u64, ) -> io::Result<usize> { // Silently cast; we'll get `EINVAL` if the value is negative. @@ -130,7 +131,7 @@ pub(crate) fn preadv( target_os = "redox", target_os = "solaris" )))] -pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io::Result<usize> { +pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> { // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; unsafe { @@ -146,7 +147,7 @@ pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io:: #[cfg(linux_kernel)] pub(crate) fn preadv2( fd: BorrowedFd<'_>, - bufs: &mut [IoSliceMut], + bufs: &mut [IoSliceMut<'_>], offset: u64, flags: ReadWriteFlags, ) -> io::Result<usize> { @@ -166,7 +167,7 @@ pub(crate) fn preadv2( #[cfg(linux_kernel)] pub(crate) fn pwritev2( fd: BorrowedFd<'_>, - bufs: &[IoSlice], + bufs: &[IoSlice<'_>], offset: u64, flags: ReadWriteFlags, ) -> io::Result<usize> { @@ -203,25 +204,22 @@ pub(crate) unsafe fn close(raw_fd: RawFd) { let _ = c::close(raw_fd as c::c_int); } -#[cfg(not(target_os = "espidf"))] -pub(crate) fn ioctl_fionread(fd: BorrowedFd<'_>) -> io::Result<u64> { - use core::mem::MaybeUninit; - - let mut nread = MaybeUninit::<c::c_int>::uninit(); - unsafe { - ret(c::ioctl(borrowed_fd(fd), c::FIONREAD, nread.as_mut_ptr()))?; - // `FIONREAD` returns the number of bytes silently casted to a `c_int`, - // even when this is lossy. The best we can do is convert it back to a - // `u64` without sign-extending it back first. - Ok(u64::from(nread.assume_init() as c::c_uint)) - } +#[inline] +pub(crate) unsafe fn ioctl( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ret_c_int(c::ioctl(borrowed_fd(fd), request, arg)) } -pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { - unsafe { - let data = value as c::c_int; - ret(c::ioctl(borrowed_fd(fd), c::FIONBIO, &data)) - } +#[inline] +pub(crate) unsafe fn ioctl_readonly( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ioctl(fd, request, arg) } #[cfg(not(any(target_os = "redox", target_os = "wasi")))] @@ -302,11 +300,13 @@ pub(crate) fn dup(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(c::dup(borrowed_fd(fd))) } } +#[allow(clippy::needless_pass_by_ref_mut)] #[cfg(not(target_os = "wasi"))] pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> { unsafe { ret_discarded_fd(c::dup2(borrowed_fd(fd), borrowed_fd(new.as_fd()))) } } +#[allow(clippy::needless_pass_by_ref_mut)] #[cfg(not(any( apple, target_os = "aix", @@ -342,14 +342,3 @@ pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, _flags: DupFlags) -> i // have an `&mut OwnedFd` which means `fd` doesn't alias it. dup2(fd, new) } - -#[cfg(apple)] -pub(crate) fn ioctl_fioclex(fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { - ret(c::ioctl( - borrowed_fd(fd), - c::FIOCLEX, - core::ptr::null_mut::<u8>(), - )) - } -} |