diff --git a/src/header/pty/redox.rs b/src/header/pty/redox.rs index a4fad5c608..53d123c34f 100644 --- a/src/header/pty/redox.rs +++ b/src/header/pty/redox.rs @@ -7,6 +7,44 @@ use crate::{ }, }; +/// POSIX `grantpt(fd)` — change the mode and owner of the slave +/// pseudoterminal device. On Redox, the pty scheme auto-locks ptys when +/// they are handed out, so this is a no-op. Reference: Linux 7.x +/// `man-pages/man3/grantpt.3.html` and `drivers/tty/pty.c`. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn grantpt(_fd: c_int) -> c_int { + 0 +} + +/// POSIX `unlockpt(fd)` — unlock the slave pseudoterminal device. +/// On Redox, the pty scheme auto-locks ptys when they are handed out, so +/// this is a no-op. Reference: Linux 7.x `man-pages/man3/unlockpt.3.html` +/// and `drivers/tty/pty.c`. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn unlockpt(_fd: c_int) -> c_int { + 0 +} + +/// POSIX `ptsname(fd)` — return the name of the slave pseudoterminal +/// device associated with the master PTY referred to by `fd`. On Redox +/// we use `Sys::fpath` to retrieve the slave path from the pty scheme. +/// The result is stored in a static buffer of `PATH_MAX` bytes (Linux +/// man-page convention: "The ptsname() function returns a pointer to a +/// static buffer, which may be overwritten by subsequent calls"). Reference: +/// Linux 7.x `man-pages/man3/ptsname.3.html` and `drivers/tty/pty.c`. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn ptsname(fd: c_int) -> *const c_char { + use crate::header::limits::PATH_MAX; + static mut NAME_BUF: [c_char; PATH_MAX] = [0; PATH_MAX]; + let count = unsafe { Sys::fpath(fd, &mut NAME_BUF) } + .map(|u| u as ssize_t) + .or_minus_one_errno(); + if count < 0 { + return core::ptr::null(); + } + unsafe { NAME_BUF.as_mut_ptr() } +} + pub(super) unsafe fn openpty(name: &mut [u8]) -> Result<(c_int, c_int), ()> { let master = unsafe { fcntl::open(c"/scheme/pty".as_ptr(), fcntl::O_RDWR, 0) }; if master < 0 {