Debian Codegraph @

debian/rust-vendor/rustix/src/termios/ioctl.rs

raw
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 /// In exclusive mode, subsequent unprivileged `open` calls on the terminal
12 /// device fail with [`io::Errno::BUSY`].
13 ///
14 /// # References
15 /// - [Linux]
16 /// - [FreeBSD]
17 /// - [NetBSD]
18 /// - [OpenBSD]
19 ///
20 /// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html
21 /// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=tty&sektion=4
22 /// [NetBSD]: https://man.netbsd.org/tty.4
23 /// [OpenBSD]: https://man.openbsd.org/tty.4
24 #[cfg(not(any(
25 windows,
26 target_os = "horizon",
27 target_os = "redox",
28 target_os = "wasi"
29 )))]
30 #[inline]
31 #[doc(alias = "TIOCEXCL")]
32 pub fn ioctl_tiocexcl<Fd: AsFd>(fd: Fd) -> io::Result<()> {
33 // SAFETY: `TIOCEXCL` is a no-argument setter opcode.
34 unsafe {
35 let ctl = ioctl::NoArg::<{ c::TIOCEXCL as _ }>::new();
36 ioctl::ioctl(fd, ctl)
37 }
38 }
39
40 /// `ioctl(fd, TIOCNXCL)`—Disables exclusive mode on a terminal.
41 ///
42 /// # References
43 /// - [Linux]
44 /// - [FreeBSD]
45 /// - [NetBSD]
46 /// - [OpenBSD]
47 ///
48 /// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html
49 /// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=tty&sektion=4
50 /// [NetBSD]: https://man.netbsd.org/tty.4
51 /// [OpenBSD]: https://man.openbsd.org/tty.4
52 #[cfg(not(any(
53 windows,
54 target_os = "horizon",
55 target_os = "redox",
56 target_os = "wasi"
57 )))]
58 #[inline]
59 #[doc(alias = "TIOCNXCL")]
60 pub fn ioctl_tiocnxcl<Fd: AsFd>(fd: Fd) -> io::Result<()> {
61 // SAFETY: `TIOCNXCL` is a no-argument setter opcode.
62 unsafe {
63 let ctl = ioctl::NoArg::<{ c::TIOCNXCL as _ }>::new();
64 ioctl::ioctl(fd, ctl)
65 }
66 }