diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/rustix/src/termios | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/termios')
-rw-r--r-- | vendor/rustix/src/termios/cf.rs | 40 | ||||
-rw-r--r-- | vendor/rustix/src/termios/constants.rs | 719 | ||||
-rw-r--r-- | vendor/rustix/src/termios/mod.rs | 610 | ||||
-rw-r--r-- | vendor/rustix/src/termios/tc.rs | 196 | ||||
-rw-r--r-- | vendor/rustix/src/termios/tty.rs | 72 |
5 files changed, 1637 insertions, 0 deletions
diff --git a/vendor/rustix/src/termios/cf.rs b/vendor/rustix/src/termios/cf.rs new file mode 100644 index 000000000..d28b65e03 --- /dev/null +++ b/vendor/rustix/src/termios/cf.rs @@ -0,0 +1,40 @@ +use crate::termios::{Speed, Termios}; +use crate::{imp, io}; + +/// `cfgetospeed(termios)` +#[inline] +#[must_use] +pub fn cfgetospeed(termios: &Termios) -> Speed { + imp::termios::syscalls::cfgetospeed(termios) +} + +/// `cfgetispeed(termios)` +#[inline] +#[must_use] +pub fn cfgetispeed(termios: &Termios) -> Speed { + imp::termios::syscalls::cfgetispeed(termios) +} + +/// `cfmakeraw(termios)` +#[inline] +pub fn cfmakeraw(termios: &mut Termios) { + imp::termios::syscalls::cfmakeraw(termios) +} + +/// `cfsetospeed(termios, speed)` +#[inline] +pub fn cfsetospeed(termios: &mut Termios, speed: Speed) -> io::Result<()> { + imp::termios::syscalls::cfsetospeed(termios, speed) +} + +/// `cfsetispeed(termios, speed)` +#[inline] +pub fn cfsetispeed(termios: &mut Termios, speed: Speed) -> io::Result<()> { + imp::termios::syscalls::cfsetispeed(termios, speed) +} + +/// `cfsetspeed(termios, speed)` +#[inline] +pub fn cfsetspeed(termios: &mut Termios, speed: Speed) -> io::Result<()> { + imp::termios::syscalls::cfsetspeed(termios, speed) +} diff --git a/vendor/rustix/src/termios/constants.rs b/vendor/rustix/src/termios/constants.rs new file mode 100644 index 000000000..5c10c12ed --- /dev/null +++ b/vendor/rustix/src/termios/constants.rs @@ -0,0 +1,719 @@ +use crate::imp; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::B1000000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::B1152000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::B1500000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::B2000000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::B2500000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::B3000000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::B3500000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::B4000000; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] +pub use imp::termios::types::B460800; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::B500000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::B576000; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] +pub use imp::termios::types::B921600; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::BRKINT; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::BS0; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::BS1; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::BSDLY; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::CBAUD; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::CBAUDEX; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::CIBAUD; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::CLOCAL; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::CMSPAR; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::CR0; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::CR1; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::CR2; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::CR3; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::CRDLY; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::CREAD; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use imp::termios::types::CRTSCTS; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::CS5; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::CS6; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::CS7; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::CS8; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::CSIZE; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::CSTOPB; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::ECHO; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use imp::termios::types::ECHOCTL; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::ECHOE; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::ECHOK; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use imp::termios::types::ECHOKE; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::ECHONL; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use imp::termios::types::ECHOPRT; +#[cfg(not(any( + target_os = "emscripten", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "redox", +)))] +pub use imp::termios::types::EXTA; +#[cfg(not(any( + target_os = "emscripten", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "redox", +)))] +pub use imp::termios::types::EXTB; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use imp::termios::types::EXTPROC; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::FF0; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::FF1; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::FFDLY; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use imp::termios::types::FLUSHO; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::HUPCL; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::ICRNL; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::IEXTEN; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::IGNBRK; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::IGNCR; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::IGNPAR; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use imp::termios::types::IMAXBEL; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::INLCR; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::INPCK; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::ISIG; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::ISTRIP; +#[cfg(any( + linux_raw, + all( + libc, + any(target_os = "haiku", target_os = "illumos", target_os = "solaris"), + ) +))] +pub use imp::termios::types::IUCLC; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::IUTF8; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use imp::termios::types::IXANY; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::IXOFF; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::IXON; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::NL0; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::NL1; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::NLDLY; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::NOFLSH; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::OCRNL; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::OFDEL; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::OFILL; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "redox", +)))] +pub use imp::termios::types::OLCUC; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::ONLCR; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::ONLRET; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::ONOCR; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::OPOST; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::PARENB; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::PARMRK; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::PARODD; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use imp::termios::types::PENDIN; +#[cfg(not(any( + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::TAB0; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::TAB1; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::TAB2; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "emscripten", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::TAB3; +#[cfg(not(any( + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "illumos", + target_os = "redox", +)))] +pub use imp::termios::types::TABDLY; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use imp::termios::types::TOSTOP; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use imp::termios::types::VSWTC; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::VT0; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::VT1; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::VTDLY; +#[cfg(any(linux_raw, all(libc, any(target_arch = "s390x", target_os = "haiku"))))] +pub use imp::termios::types::XCASE; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::termios::types::XTABS; +pub use imp::termios::types::{ + B0, B110, B115200, B1200, B134, B150, B1800, B19200, B200, B230400, B2400, B300, B38400, B4800, + B50, B57600, B600, B75, B9600, ICANON, VDISCARD, VEOF, VEOL, VEOL2, VERASE, VINTR, VKILL, + VLNEXT, VMIN, VQUIT, VREPRINT, VSTART, VSTOP, VSUSP, VTIME, VWERASE, +}; + +/// Translate from a `Speed` code to a speed value `u32`. +/// +/// ```rust +/// let speed = rustix::termios::speed_value(rustix::termios::B57600); +/// assert_eq!(speed, Some(57600)); +/// ``` +pub fn speed_value(speed: imp::termios::types::Speed) -> Option<u32> { + match speed { + imp::termios::types::B0 => Some(0), + imp::termios::types::B50 => Some(50), + imp::termios::types::B75 => Some(75), + imp::termios::types::B110 => Some(110), + imp::termios::types::B134 => Some(134), + imp::termios::types::B150 => Some(150), + imp::termios::types::B200 => Some(200), + imp::termios::types::B300 => Some(300), + imp::termios::types::B600 => Some(600), + imp::termios::types::B1200 => Some(1200), + imp::termios::types::B1800 => Some(1800), + imp::termios::types::B2400 => Some(2400), + imp::termios::types::B4800 => Some(4800), + imp::termios::types::B9600 => Some(9600), + imp::termios::types::B19200 => Some(19200), + imp::termios::types::B38400 => Some(38400), + imp::termios::types::B57600 => Some(57600), + imp::termios::types::B115200 => Some(115_200), + imp::termios::types::B230400 => Some(230_400), + #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] + imp::termios::types::B460800 => Some(460_800), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + )))] + imp::termios::types::B500000 => Some(500_000), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + )))] + imp::termios::types::B576000 => Some(576_000), + #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] + imp::termios::types::B921600 => Some(921_600), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + )))] + imp::termios::types::B1000000 => Some(1_000_000), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + )))] + imp::termios::types::B1152000 => Some(1_152_000), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + )))] + imp::termios::types::B1500000 => Some(1_500_000), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + )))] + imp::termios::types::B2000000 => Some(2_000_000), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + )))] + imp::termios::types::B2500000 => Some(2_500_000), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + )))] + imp::termios::types::B3000000 => Some(3_000_000), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + )))] + imp::termios::types::B3500000 => Some(3_500_000), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + )))] + imp::termios::types::B4000000 => Some(4_000_000), + _ => None, + } +} diff --git a/vendor/rustix/src/termios/mod.rs b/vendor/rustix/src/termios/mod.rs new file mode 100644 index 000000000..79f2f6b38 --- /dev/null +++ b/vendor/rustix/src/termios/mod.rs @@ -0,0 +1,610 @@ +//! Terminal I/O stream operations. + +mod cf; +mod constants; +mod tc; +#[cfg(not(windows))] +mod tty; + +pub use cf::{cfgetispeed, cfgetospeed, cfmakeraw, cfsetispeed, cfsetospeed, cfsetspeed}; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::B1000000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::B1152000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::B1500000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::B2000000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::B2500000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::B3000000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::B3500000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::B4000000; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] +pub use constants::B460800; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::B500000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::B576000; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] +pub use constants::B921600; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::BRKINT; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::BS0; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::BS1; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::BSDLY; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::CBAUD; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::CBAUDEX; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::CIBAUD; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::CLOCAL; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::CMSPAR; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::CR0; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::CR1; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::CR2; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::CR3; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::CRDLY; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::CREAD; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use constants::CRTSCTS; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::CS5; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::CS6; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::CS7; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::CS8; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::CSIZE; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::CSTOPB; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::ECHO; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use constants::ECHOCTL; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::ECHOE; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::ECHOK; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use constants::ECHOKE; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::ECHONL; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use constants::ECHOPRT; +#[cfg(not(any( + target_os = "emscripten", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "redox", +)))] +pub use constants::EXTA; +#[cfg(not(any( + target_os = "emscripten", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "redox", +)))] +pub use constants::EXTB; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use constants::EXTPROC; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::FF0; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::FF1; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::FFDLY; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use constants::FLUSHO; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::HUPCL; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::ICRNL; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::IEXTEN; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::IGNBRK; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::IGNCR; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::IGNPAR; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use constants::IMAXBEL; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::INLCR; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::INPCK; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::ISIG; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::ISTRIP; +#[cfg(any( + linux_raw, + all( + libc, + any(target_os = "haiku", target_os = "illumos", target_os = "solaris"), + ) +))] +pub use constants::IUCLC; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::IUTF8; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use constants::IXANY; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::IXOFF; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::IXON; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::NL0; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::NL1; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::NLDLY; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::NOFLSH; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::OCRNL; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::OFDEL; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::OFILL; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "redox", +)))] +pub use constants::OLCUC; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::ONLCR; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::ONLRET; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::ONOCR; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::OPOST; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::PARENB; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::PARMRK; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::PARODD; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub use constants::PENDIN; +#[cfg(not(any( + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::TAB0; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::TAB1; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::TAB2; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "emscripten", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::TAB3; +#[cfg(not(any( + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "illumos", + target_os = "redox", +)))] +pub use constants::TABDLY; +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +pub use constants::TOSTOP; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", +)))] +pub use constants::VSWTC; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::VT0; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::VT1; +#[cfg(not(any( + all(libc, target_env = "musl"), + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::VTDLY; +#[cfg(any(linux_raw, all(libc, any(target_arch = "s390x", target_os = "haiku"))))] +pub use constants::XCASE; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use constants::XTABS; +pub use constants::{ + speed_value, B0, B110, B115200, B1200, B134, B150, B1800, B19200, B200, B230400, B2400, B300, + B38400, B4800, B50, B57600, B600, B75, B9600, ICANON, VDISCARD, VEOF, VEOL, VEOL2, VERASE, + VINTR, VKILL, VLNEXT, VMIN, VQUIT, VREPRINT, VSTART, VSTOP, VSUSP, VTIME, VWERASE, +}; +pub use tc::{ + tcdrain, tcflow, tcflush, tcgetattr, tcgetpgrp, tcgetsid, tcgetwinsize, tcsendbreak, tcsetattr, + tcsetpgrp, tcsetwinsize, Action, OptionalActions, QueueSelector, Speed, Tcflag, Termios, + Winsize, +}; +#[cfg(not(windows))] +pub use tty::isatty; +#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +#[cfg(feature = "procfs")] +pub use tty::ttyname; diff --git a/vendor/rustix/src/termios/tc.rs b/vendor/rustix/src/termios/tc.rs new file mode 100644 index 000000000..b44eafde3 --- /dev/null +++ b/vendor/rustix/src/termios/tc.rs @@ -0,0 +1,196 @@ +use crate::fd::AsFd; +use crate::process::Pid; +use crate::{imp, io}; + +pub use imp::termios::types::{ + Action, OptionalActions, QueueSelector, Speed, Tcflag, Termios, Winsize, +}; + +/// `tcgetattr(fd)`—Get terminal attributes. +/// +/// Also known as the `TCGETS` operation with `ioctl`. +/// +/// # References +/// - [POSIX `tcgetattr`] +/// - [Linux `ioctl_tty`] +/// - [Linux `termios`] +/// +/// [POSIX `tcgetattr`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetattr.html +/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html +/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html +#[cfg(not(any(windows, target_os = "wasi")))] +#[inline] +#[doc(alias = "TCGETS")] +pub fn tcgetattr<Fd: AsFd>(fd: Fd) -> io::Result<Termios> { + imp::termios::syscalls::tcgetattr(fd.as_fd()) +} + +/// `tcgetwinsize(fd)`—Get the current terminal window size. +/// +/// Also known as the `TIOCGWINSZ` operation with `ioctl`. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html +#[cfg(not(any(windows, target_os = "wasi")))] +#[inline] +#[doc(alias = "TIOCGWINSZ")] +pub fn tcgetwinsize<Fd: AsFd>(fd: Fd) -> io::Result<Winsize> { + imp::termios::syscalls::tcgetwinsize(fd.as_fd()) +} + +/// `tcgetpgrp(fd)`—Get the terminal foreground process group. +/// +/// Also known as the `TIOCGPGRP` operation with `ioctl`. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetpgrp.html +/// [Linux]: https://man7.org/linux/man-pages/man3/tcgetpgrp.3.html +#[cfg(not(any(windows, target_os = "wasi")))] +#[inline] +#[doc(alias = "TIOCGPGRP")] +pub fn tcgetpgrp<Fd: AsFd>(fd: Fd) -> io::Result<Pid> { + imp::termios::syscalls::tcgetpgrp(fd.as_fd()) +} + +/// `tcsetpgrp(fd, pid)`—Set the terminal foreground process group. +/// +/// Also known as the `TIOCSPGRP` operation with `ioctl`. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsetpgrp.html +/// [Linux]: https://man7.org/linux/man-pages/man3/tcsetpgrp.3.html +#[cfg(not(any(windows, target_os = "wasi")))] +#[inline] +#[doc(alias = "TIOCSPGRP")] +pub fn tcsetpgrp<Fd: AsFd>(fd: Fd, pid: Pid) -> io::Result<()> { + imp::termios::syscalls::tcsetpgrp(fd.as_fd(), pid) +} + +/// `tcsetattr(fd)`—Set terminal attributes. +/// +/// Also known as the `TCSETS` operation with `ioctl`. +/// +/// # References +/// - [POSIX `tcsetattr`] +/// - [Linux `ioctl_tty`] +/// - [Linux `termios`] +/// +/// [POSIX `tcsetattr`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsetattr.html +/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html +/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html +#[inline] +#[doc(alias = "TCSETS")] +pub fn tcsetattr<Fd: AsFd>( + fd: Fd, + optional_actions: OptionalActions, + termios: &Termios, +) -> io::Result<()> { + imp::termios::syscalls::tcsetattr(fd.as_fd(), optional_actions, termios) +} + +/// `tcsendbreak(fd, 0)`—Transmit zero-valued bits. +/// +/// Also known as the `TCSBRK` operation with `ioctl`, with a duration of 0. +/// +/// This function always uses an effective duration parameter of zero. For the +/// equivalent of a `tcsendbreak` with a non-zero duration parameter, use +/// `tcdrain`. +/// +/// # References +/// - [POSIX `tcsendbreak`] +/// - [Linux `ioctl_tty`] +/// - [Linux `termios`] +/// +/// [POSIX `tcsendbreak`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsendbreak.html +/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html +/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html +#[inline] +#[doc(alias = "TCSBRK")] +pub fn tcsendbreak<Fd: AsFd>(fd: Fd) -> io::Result<()> { + imp::termios::syscalls::tcsendbreak(fd.as_fd()) +} + +/// `tcdrain(fd, duration)`—Wait until all pending output has been written. +/// +/// # References +/// - [POSIX `tcdrain`] +/// - [Linux `ioctl_tty`] +/// - [Linux `termios`] +/// +/// [POSIX `tcsetattr`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcdrain.html +/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html +/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html +#[inline] +pub fn tcdrain<Fd: AsFd>(fd: Fd) -> io::Result<()> { + imp::termios::syscalls::tcdrain(fd.as_fd()) +} + +/// `tcflush(fd, queue_selector)`—Wait until all pending output has been +/// written. +/// +/// # References +/// - [POSIX `tcflush`] +/// - [Linux `ioctl_tty`] +/// - [Linux `termios`] +/// +/// [POSIX `tcflush`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcflush.html +/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html +/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html +#[inline] +#[doc(alias = "TCFLSH")] +pub fn tcflush<Fd: AsFd>(fd: Fd, queue_selector: QueueSelector) -> io::Result<()> { + imp::termios::syscalls::tcflush(fd.as_fd(), queue_selector) +} + +/// `tcflow(fd, action)`—Suspend or resume transmission or reception. +/// +/// # References +/// - [POSIX `tcflow`] +/// - [Linux `ioctl_tty`] +/// - [Linux `termios`] +/// +/// [POSIX `tcflow`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcflow.html +/// [Linux `ioctl_tty`]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html +/// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html +#[inline] +#[doc(alias = "TCXONC")] +pub fn tcflow<Fd: AsFd>(fd: Fd, action: Action) -> io::Result<()> { + imp::termios::syscalls::tcflow(fd.as_fd(), action) +} + +/// `tcgetsid(fd)`—Return the session ID of the current session with `fd` as +/// its controlling terminal. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetsid.html +/// [Linux]: https://man7.org/linux/man-pages/man3/tcgetsid.3.html +#[inline] +#[doc(alias = "TIOCGSID")] +pub fn tcgetsid<Fd: AsFd>(fd: Fd) -> io::Result<Pid> { + imp::termios::syscalls::tcgetsid(fd.as_fd()) +} + +/// `tcsetwinsize(fd)`—Set the current terminal window size. +/// +/// Also known as the `TIOCSWINSZ` operation with `ioctl`. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html +#[inline] +#[doc(alias = "TIOCSWINSZ")] +pub fn tcsetwinsize<Fd: AsFd>(fd: Fd, winsize: Winsize) -> io::Result<()> { + imp::termios::syscalls::tcsetwinsize(fd.as_fd(), winsize) +} diff --git a/vendor/rustix/src/termios/tty.rs b/vendor/rustix/src/termios/tty.rs new file mode 100644 index 000000000..1651a3c3b --- /dev/null +++ b/vendor/rustix/src/termios/tty.rs @@ -0,0 +1,72 @@ +//! Functions which operate on file descriptors which might be terminals. + +use crate::imp; +#[cfg(any( + all(linux_raw, feature = "procfs"), + all(libc, not(any(target_os = "fuchsia", target_os = "wasi"))), +))] +#[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))] +use crate::io; +use imp::fd::AsFd; +#[cfg(any( + all(linux_raw, feature = "procfs"), + all(libc, not(any(target_os = "fuchsia", target_os = "wasi"))), +))] +use { + crate::ffi::CString, crate::path::SMALL_PATH_BUFFER_SIZE, alloc::vec::Vec, imp::fd::BorrowedFd, +}; + +/// `isatty(fd)`—Tests whether a file descriptor refers to a terminal. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/isatty.html +/// [Linux]: https://man7.org/linux/man-pages/man3/isatty.3.html +#[inline] +pub fn isatty<Fd: AsFd>(fd: Fd) -> bool { + imp::termios::syscalls::isatty(fd.as_fd()) +} + +/// `ttyname_r(fd)` +/// +/// If `reuse` is non-empty, reuse its buffer to store the result if possible. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/ttyname.html +/// [Linux]: https://man7.org/linux/man-pages/man3/ttyname.3.html +#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +#[cfg(feature = "procfs")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))] +#[inline] +pub fn ttyname<Fd: AsFd, B: Into<Vec<u8>>>(dirfd: Fd, reuse: B) -> io::Result<CString> { + _ttyname(dirfd.as_fd(), reuse.into()) +} + +#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +#[cfg(feature = "procfs")] +fn _ttyname(dirfd: BorrowedFd<'_>, mut buffer: Vec<u8>) -> io::Result<CString> { + // This code would benefit from having a better way to read into + // uninitialized memory, but that requires `unsafe`. + buffer.clear(); + buffer.reserve(SMALL_PATH_BUFFER_SIZE); + buffer.resize(buffer.capacity(), 0_u8); + + loop { + match imp::termios::syscalls::ttyname(dirfd, &mut buffer) { + Err(io::Errno::RANGE) => { + buffer.reserve(1); // use `Vec` reallocation strategy to grow capacity exponentially + buffer.resize(buffer.capacity(), 0_u8); + } + Ok(len) => { + buffer.resize(len, 0_u8); + return Ok(CString::new(buffer).unwrap()); + } + Err(errno) => return Err(errno), + } + } +} |