//! Libc call arguments and return values are often things like `c_int`, //! `c_uint`, or libc-specific pointer types. This module provides functions //! for converting between rustix's types and libc types.
/// Convert a `c_int` returned from a libc function to an `OwnedFd`, if valid. /// /// # Safety /// /// The caller must ensure that this is the return value of a libc function /// which returns an owned file descriptor. #[inline] pub(super) unsafefn ret_owned_fd(raw: LibcFd) -> io::Result<OwnedFd> { if raw == !0 {
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(any(windows, target_os = "redox", target_os = "wasi")))] #[inline] pub(super) fn send_recv_len(len: usize) -> usize {
len
}
/// Convert the buffer-length argument value of a `send` or `recv` call. #[cfg(windows)] #[inline] pub(super) fn send_recv_len(len: usize) -> i32 { // On Windows, the length argument has type `i32`; saturate the length, // since `send` and `recv` are allowed to send and recv less data than // requested.
len.try_into().unwrap_or(i32::MAX)
}
/// Convert the return value of a `send` or `recv` call. #[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] #[inline] pub(super) fn ret_send_recv(len: isize) -> io::Result<usize> {
ret_usize(len)
}
/// Convert the return value of a `send` or `recv` call. #[cfg(windows)] #[inline] 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 = "espidf", target_os = "redox", target_os = "wasi")),
any(
target_os = "android",
all(
target_os = "linux",
not(target_env = "musl"),
not(all(target_env = "uclibc", any(target_arch = "arm", target_arch = "mips")))
)
)
))] #[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 = "espidf",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)),
not(any(
target_os = "android",
all(
target_os = "linux",
not(target_env = "musl"),
not(all(target_env = "uclibc", any(target_arch = "arm", target_arch = "mips")))
)
))
))] #[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 = "aix",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "haiku",
target_os = "nto",
))] #[inline] pub(crate) fn msg_control_len(len: usize) -> c::socklen_t {
len.try_into().unwrap_or(c::socklen_t::MAX)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.