diff options
Diffstat (limited to 'vendor/rustix/src/backend/libc/conv.rs')
-rw-r--r-- | vendor/rustix/src/backend/libc/conv.rs | 113 |
1 files changed, 57 insertions, 56 deletions
diff --git a/vendor/rustix/src/backend/libc/conv.rs b/vendor/rustix/src/backend/libc/conv.rs index b827d0bbc..d6bcc16ee 100644 --- a/vendor/rustix/src/backend/libc/conv.rs +++ b/vendor/rustix/src/backend/libc/conv.rs @@ -7,13 +7,8 @@ use super::c; use super::fd::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, LibcFd, OwnedFd, RawFd}; #[cfg(not(windows))] -#[cfg(feature = "fs")] -use super::offset::libc_off_t; -#[cfg(not(windows))] use crate::ffi::CStr; use crate::io; -#[cfg(windows)] -use core::convert::TryInto; #[cfg(not(windows))] #[inline] @@ -47,15 +42,6 @@ pub(super) fn ret(raw: c::c_int) -> io::Result<()> { } #[inline] -pub(super) fn syscall_ret(raw: c::c_long) -> io::Result<()> { - if raw == 0 { - Ok(()) - } else { - Err(io::Errno::last_os_error()) - } -} - -#[inline] pub(super) fn nonnegative_ret(raw: c::c_int) -> io::Result<()> { if raw >= 0 { Ok(()) @@ -97,35 +83,10 @@ pub(super) fn ret_usize(raw: c::ssize_t) -> io::Result<usize> { } } -#[inline] -pub(super) fn syscall_ret_usize(raw: c::c_long) -> io::Result<usize> { - if raw == -1 { - Err(io::Errno::last_os_error()) - } else { - debug_assert!(raw >= 0); - Ok(raw as c::ssize_t as usize) - } -} - -#[cfg(any(target_os = "android", target_os = "linux"))] -#[inline] -pub(super) fn syscall_ret_u32(raw: c::c_long) -> io::Result<u32> { - if raw == -1 { - Err(io::Errno::last_os_error()) - } else { - let r32 = raw as u32; - - // Converting `raw` to `u32` should be lossless. - debug_assert_eq!(r32 as c::c_long, raw); - - Ok(r32) - } -} - #[cfg(not(windows))] #[cfg(feature = "fs")] #[inline] -pub(super) fn ret_off_t(raw: libc_off_t) -> io::Result<libc_off_t> { +pub(super) fn ret_off_t(raw: c::off_t) -> io::Result<c::off_t> { if raw == -1 { Err(io::Errno::last_os_error()) } else { @@ -176,22 +137,6 @@ pub(super) fn ret_discarded_char_ptr(raw: *mut c::c_char) -> io::Result<()> { } } -/// Convert a `c_long` returned from `syscall` to an `OwnedFd`, if valid. -/// -/// # Safety -/// -/// The caller must ensure that this is the return value of a `syscall` call -/// which returns an owned file descriptor. -#[cfg(not(windows))] -#[inline] -pub(super) unsafe fn syscall_ret_owned_fd(raw: c::c_long) -> io::Result<OwnedFd> { - if raw == -1 { - Err(io::Errno::last_os_error()) - } else { - Ok(OwnedFd::from_raw_fd(raw as RawFd)) - } -} - /// Convert the buffer-length argument value of a `send` or `recv` call. #[cfg(not(windows))] #[inline] @@ -222,3 +167,59 @@ pub(super) fn ret_send_recv(len: isize) -> io::Result<usize> { pub(super) fn ret_send_recv(len: i32) -> io::Result<usize> { ret_usize(len as isize) } + +/// Convert the value to the `msg_iovlen` field of a `msghdr` struct. +#[cfg(all( + not(any(windows, target_os = "wasi")), + any( + target_os = "android", + all(target_os = "linux", not(target_env = "musl")) + ) +))] +#[inline] +pub(super) fn msg_iov_len(len: usize) -> c::size_t { + len +} + +/// Convert the value to the `msg_iovlen` field of a `msghdr` struct. +#[cfg(all( + not(any(windows, target_os = "wasi")), + not(any( + target_os = "android", + all(target_os = "linux", not(target_env = "musl")) + )) +))] +#[inline] +pub(crate) fn msg_iov_len(len: usize) -> c::c_int { + len.try_into().unwrap_or(c::c_int::MAX) +} + +/// Convert the value to a `socklen_t`. +#[cfg(any( + bsd, + solarish, + target_env = "musl", + target_os = "emscripten", + target_os = "haiku", + target_os = "fuchsia" +))] +#[inline] +pub(crate) fn msg_control_len(len: usize) -> c::socklen_t { + len.try_into().unwrap_or(c::socklen_t::MAX) +} + +/// Convert the value to a `size_t`. +#[cfg(not(any( + bsd, + solarish, + target_env = "musl", + target_os = "emscripten", + target_os = "haiku", + target_os = "fuchsia", + windows, + target_os = "wasi" +)))] +#[inline] +pub(crate) fn msg_control_len(len: usize) -> c::size_t { + len +} |