diff options
Diffstat (limited to 'vendor/rustix/src/backend/libc/termios/syscalls.rs')
-rw-r--r-- | vendor/rustix/src/backend/libc/termios/syscalls.rs | 70 |
1 files changed, 26 insertions, 44 deletions
diff --git a/vendor/rustix/src/backend/libc/termios/syscalls.rs b/vendor/rustix/src/backend/libc/termios/syscalls.rs index ea284927f..df96595cd 100644 --- a/vendor/rustix/src/backend/libc/termios/syscalls.rs +++ b/vendor/rustix/src/backend/libc/termios/syscalls.rs @@ -9,7 +9,7 @@ use crate::backend::c; use crate::backend::conv::ret_pid_t; use crate::backend::conv::{borrowed_fd, ret}; use crate::fd::BorrowedFd; -#[cfg(feature = "procfs")] +#[cfg(all(feature = "alloc", feature = "procfs"))] #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] use crate::ffi::CStr; #[cfg(any( @@ -33,19 +33,21 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> { // If we have `TCGETS2`, use it, so that we fill in the `c_ispeed` and // `c_ospeed` fields. #[cfg(linux_kernel)] - unsafe { + { use crate::termios::{ControlModes, InputModes, LocalModes, OutputModes, SpecialCodes}; - use core::mem::zeroed; + use crate::utils::default_array; - let mut termios2 = MaybeUninit::<c::termios2>::uninit(); + let termios2 = unsafe { + let mut termios2 = MaybeUninit::<c::termios2>::uninit(); - ret(c::ioctl( - borrowed_fd(fd), - c::TCGETS2 as _, - termios2.as_mut_ptr(), - ))?; + ret(c::ioctl( + borrowed_fd(fd), + c::TCGETS2 as _, + termios2.as_mut_ptr(), + ))?; - let termios2 = termios2.assume_init(); + termios2.assume_init() + }; // Convert from the Linux `termios2` to our `Termios`. let mut result = Termios { @@ -54,7 +56,7 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> { control_modes: ControlModes::from_bits_retain(termios2.c_cflag), local_modes: LocalModes::from_bits_retain(termios2.c_lflag), line_discipline: termios2.c_line, - special_codes: SpecialCodes(zeroed()), + special_codes: SpecialCodes(default_array()), input_speed: termios2.c_ispeed, output_speed: termios2.c_ospeed, }; @@ -90,16 +92,16 @@ pub(crate) fn tcsetpgrp(fd: BorrowedFd<'_>, pid: Pid) -> io::Result<()> { #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) fn tcsetattr( - fd: BorrowedFd, + fd: BorrowedFd<'_>, optional_actions: OptionalActions, termios: &Termios, ) -> io::Result<()> { // If we have `TCSETS2`, use it, so that we use the `c_ispeed` and // `c_ospeed` fields. #[cfg(linux_kernel)] - unsafe { + { use crate::termios::speed; - use core::mem::zeroed; + use crate::utils::default_array; use linux_raw_sys::general::{termios2, BOTHER, CBAUD, IBSHIFT}; #[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))] @@ -134,7 +136,7 @@ pub(crate) fn tcsetattr( c_cflag: termios.control_modes.bits(), c_lflag: termios.local_modes.bits(), c_line: termios.line_discipline, - c_cc: zeroed(), + c_cc: default_array(), c_ispeed: input_speed, c_ospeed: output_speed, }; @@ -149,7 +151,7 @@ pub(crate) fn tcsetattr( .c_cc .copy_from_slice(&termios.special_codes.0[..nccs]); - ret(c::ioctl(borrowed_fd(fd), request as _, &termios2)) + unsafe { ret(c::ioctl(borrowed_fd(fd), request as _, &termios2)) } } #[cfg(not(linux_kernel))] @@ -163,27 +165,27 @@ pub(crate) fn tcsetattr( } #[cfg(not(target_os = "wasi"))] -pub(crate) fn tcsendbreak(fd: BorrowedFd) -> io::Result<()> { +pub(crate) fn tcsendbreak(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::tcsendbreak(borrowed_fd(fd), 0)) } } #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub(crate) fn tcdrain(fd: BorrowedFd) -> io::Result<()> { +pub(crate) fn tcdrain(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::tcdrain(borrowed_fd(fd))) } } #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub(crate) fn tcflush(fd: BorrowedFd, queue_selector: QueueSelector) -> io::Result<()> { +pub(crate) fn tcflush(fd: BorrowedFd<'_>, queue_selector: QueueSelector) -> io::Result<()> { unsafe { ret(c::tcflush(borrowed_fd(fd), queue_selector as _)) } } #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub(crate) fn tcflow(fd: BorrowedFd, action: Action) -> io::Result<()> { +pub(crate) fn tcflow(fd: BorrowedFd<'_>, action: Action) -> io::Result<()> { unsafe { ret(c::tcflow(borrowed_fd(fd), action as _)) } } #[cfg(not(target_os = "wasi"))] -pub(crate) fn tcgetsid(fd: BorrowedFd) -> io::Result<Pid> { +pub(crate) fn tcgetsid(fd: BorrowedFd<'_>) -> io::Result<Pid> { unsafe { let pid = ret_pid_t(c::tcgetsid(borrowed_fd(fd)))?; Ok(Pid::from_raw_unchecked(pid)) @@ -191,12 +193,12 @@ pub(crate) fn tcgetsid(fd: BorrowedFd) -> io::Result<Pid> { } #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub(crate) fn tcsetwinsize(fd: BorrowedFd, winsize: Winsize) -> io::Result<()> { +pub(crate) fn tcsetwinsize(fd: BorrowedFd<'_>, winsize: Winsize) -> io::Result<()> { unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCSWINSZ, &winsize)) } } #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub(crate) fn tcgetwinsize(fd: BorrowedFd) -> io::Result<Winsize> { +pub(crate) fn tcgetwinsize(fd: BorrowedFd<'_>) -> io::Result<Winsize> { unsafe { let mut buf = MaybeUninit::<Winsize>::uninit(); ret(c::ioctl( @@ -208,26 +210,6 @@ pub(crate) fn tcgetwinsize(fd: BorrowedFd) -> io::Result<Winsize> { } } -#[cfg(not(any( - target_os = "espidf", - target_os = "haiku", - target_os = "redox", - target_os = "wasi" -)))] -pub(crate) fn ioctl_tiocexcl(fd: BorrowedFd) -> io::Result<()> { - unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCEXCL as _)) } -} - -#[cfg(not(any( - target_os = "espidf", - target_os = "haiku", - target_os = "redox", - target_os = "wasi" -)))] -pub(crate) fn ioctl_tiocnxcl(fd: BorrowedFd) -> io::Result<()> { - unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCNXCL as _)) } -} - #[cfg(not(any(target_os = "espidf", target_os = "nto", target_os = "wasi")))] #[inline] pub(crate) fn set_speed(termios: &mut Termios, arbitrary_speed: u32) -> io::Result<()> { @@ -365,7 +347,7 @@ pub(crate) fn isatty(fd: BorrowedFd<'_>) -> bool { unsafe { c::isatty(borrowed_fd(fd)) != 0 } } -#[cfg(feature = "procfs")] +#[cfg(all(feature = "alloc", feature = "procfs"))] #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] pub(crate) fn ttyname(dirfd: BorrowedFd<'_>, buf: &mut [MaybeUninit<u8>]) -> io::Result<usize> { unsafe { |