From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/rustix/src/pty.rs | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'vendor/rustix/src/pty.rs') diff --git a/vendor/rustix/src/pty.rs b/vendor/rustix/src/pty.rs index 5040ca2c1..a63fbfeef 100644 --- a/vendor/rustix/src/pty.rs +++ b/vendor/rustix/src/pty.rs @@ -5,13 +5,21 @@ //! //! [rustix-openpty crate]: https://crates.io/crates/rustix-openpty +#![allow(unsafe_code)] + use crate::backend::c; use crate::fd::{AsFd, OwnedFd}; use crate::fs::OFlags; use crate::{backend, io}; -#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))] +#[cfg(all( + feature = "alloc", + any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia") +))] use {crate::ffi::CString, alloc::vec::Vec}; +#[cfg(target_os = "linux")] +use crate::{fd::FromRawFd, ioctl}; + bitflags::bitflags! { /// `O_*` flags for use with [`openpt`] and [`ioctl_tiocgptpeer`]. /// @@ -32,6 +40,9 @@ bitflags::bitflags! { /// rustix supports it on Linux, and FreeBSD and NetBSD support it. #[cfg(any(linux_kernel, target_os = "freebsd", target_os = "netbsd"))] const CLOEXEC = c::O_CLOEXEC as c::c_uint; + + /// + const _ = !0; } } @@ -102,9 +113,12 @@ pub fn openpt(flags: OpenptFlags) -> io::Result { /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/ptsname.html /// [Linux]: https://man7.org/linux/man-pages/man3/ptsname.3.html /// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Allocation.html#index-ptsname +#[cfg(all( + feature = "alloc", + any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia") +))] #[inline] #[doc(alias = "ptsname_r")] -#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))] pub fn ptsname>>(fd: Fd, reuse: B) -> io::Result { backend::pty::syscalls::ptsname(fd.as_fd(), reuse.into()) } @@ -166,5 +180,27 @@ pub fn grantpt(fd: Fd) -> io::Result<()> { #[cfg(target_os = "linux")] #[inline] pub fn ioctl_tiocgptpeer(fd: Fd, flags: OpenptFlags) -> io::Result { - backend::pty::syscalls::ioctl_tiocgptpeer(fd.as_fd(), flags) + unsafe { ioctl::ioctl(fd, Tiocgptpeer(flags)) } +} + +#[cfg(target_os = "linux")] +struct Tiocgptpeer(OpenptFlags); + +#[cfg(target_os = "linux")] +unsafe impl ioctl::Ioctl for Tiocgptpeer { + type Output = OwnedFd; + + const IS_MUTATING: bool = false; + const OPCODE: ioctl::Opcode = ioctl::Opcode::old(c::TIOCGPTPEER as ioctl::RawOpcode); + + fn as_ptr(&mut self) -> *mut c::c_void { + self.0.bits() as *mut c::c_void + } + + unsafe fn output_from_ptr( + ret: ioctl::IoctlOutput, + _arg: *mut c::c_void, + ) -> io::Result { + Ok(OwnedFd::from_raw_fd(ret)) + } } -- cgit v1.2.3