| 1 |
//! Terminal-related `ioctl` functions. |
| 2 |
|
| 3 |
#![allow(unsafe_code)] |
| 4 |
|
| 5 |
use crate::fd::AsFd; |
| 6 |
use crate::{backend, io, ioctl}; |
| 7 |
use backend::c; |
| 8 |
|
| 9 |
/// `ioctl(fd, TIOCEXCL)`—Enables exclusive mode on a terminal. |
| 10 |
/// |
| 11 |
/// # References |
| 12 |
/// - [Linux] |
| 13 |
/// - [FreeBSD] |
| 14 |
/// - [NetBSD] |
| 15 |
/// - [OpenBSD] |
| 16 |
/// |
| 17 |
/// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html |
| 18 |
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=tty&sektion=4 |
| 19 |
/// [NetBSD]: https://man.netbsd.org/tty.4 |
| 20 |
/// [OpenBSD]: https://man.openbsd.org/tty.4 |
| 21 |
#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] |
| 22 |
#[inline] |
| 23 |
#[doc(alias = "TIOCEXCL")] |
| 24 |
pub fn ioctl_tiocexcl<Fd: AsFd>(fd: Fd) -> io::Result<()> { |
| 25 |
// SAFETY: TIOCEXCL is a no-argument setter opcode. |
| 26 |
unsafe { |
| 27 |
let ctl = ioctl::NoArg::<ioctl::BadOpcode<{ c::TIOCEXCL as _ }>>::new(); |
| 28 |
ioctl::ioctl(fd, ctl) |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
/// `ioctl(fd, TIOCNXCL)`—Disables exclusive mode on a terminal. |
| 33 |
/// |
| 34 |
/// # References |
| 35 |
/// - [Linux] |
| 36 |
/// - [FreeBSD] |
| 37 |
/// - [NetBSD] |
| 38 |
/// - [OpenBSD] |
| 39 |
/// |
| 40 |
/// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html |
| 41 |
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=tty&sektion=4 |
| 42 |
/// [NetBSD]: https://man.netbsd.org/tty.4 |
| 43 |
/// [OpenBSD]: https://man.openbsd.org/tty.4 |
| 44 |
#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] |
| 45 |
#[inline] |
| 46 |
#[doc(alias = "TIOCNXCL")] |
| 47 |
pub fn ioctl_tiocnxcl<Fd: AsFd>(fd: Fd) -> io::Result<()> { |
| 48 |
// SAFETY: TIOCNXCL is a no-argument setter opcode. |
| 49 |
unsafe { |
| 50 |
let ctl = ioctl::NoArg::<ioctl::BadOpcode<{ c::TIOCNXCL as _ }>>::new(); |
| 51 |
ioctl::ioctl(fd, ctl) |
| 52 |
} |
| 53 |
} |