diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/rustix/src/pty.rs | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/pty.rs')
-rw-r--r-- | vendor/rustix/src/pty.rs | 42 |
1 files changed, 39 insertions, 3 deletions
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; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -102,9 +113,12 @@ pub fn openpt(flags: OpenptFlags) -> io::Result<OwnedFd> { /// [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: AsFd, B: Into<Vec<u8>>>(fd: Fd, reuse: B) -> io::Result<CString> { backend::pty::syscalls::ptsname(fd.as_fd(), reuse.into()) } @@ -166,5 +180,27 @@ pub fn grantpt<Fd: AsFd>(fd: Fd) -> io::Result<()> { #[cfg(target_os = "linux")] #[inline] pub fn ioctl_tiocgptpeer<Fd: AsFd>(fd: Fd, flags: OpenptFlags) -> io::Result<OwnedFd> { - 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<Self::Output> { + Ok(OwnedFd::from_raw_fd(ret)) + } } |