relibc: pty/redox: deduplicate grantpt/unlockpt/ptsname (keep openpty)

Remove grantpt, unlockpt, and ptsname from pty/redox.rs; stdlib/mod.rs
already provides cross-platform versions. Keep the Redox-specific openpty
helper.
This commit is contained in:
Red Bear OS
2026-07-08 22:15:14 +03:00
parent 9a0ad82a7f
commit 78d02e3f19
-38
View File
@@ -7,44 +7,6 @@ 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: [u8; 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() as *const c_char }
}
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 {