rustix/process/
ioctl.rs

1//! Process-oriented `ioctl`s.
2//!
3//! # Safety
4//!
5//! This module invokes `ioctl`s.
6
7#![allow(unsafe_code)]
8
9use crate::{backend, io, ioctl};
10use backend::c;
11use backend::fd::AsFd;
12
13/// `ioctl(fd, TIOCSCTTY, 0)`—Sets the controlling terminal for the process.
14///
15/// # References
16///  - [Linux]
17///  - [FreeBSD]
18///  - [NetBSD]
19///  - [OpenBSD]
20///
21/// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html
22/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=tty&sektion=4
23/// [NetBSD]: https://man.netbsd.org/tty.4
24/// [OpenBSD]: https://man.openbsd.org/tty.4
25#[cfg(not(any(
26    windows,
27    target_os = "aix",
28    target_os = "horizon",
29    target_os = "redox",
30    target_os = "wasi"
31)))]
32#[inline]
33#[doc(alias = "TIOCSCTTY")]
34pub fn ioctl_tiocsctty<Fd: AsFd>(fd: Fd) -> io::Result<()> {
35    unsafe { ioctl::ioctl(fd, Tiocsctty) }
36}
37
38#[cfg(not(any(
39    windows,
40    target_os = "aix",
41    target_os = "horizon",
42    target_os = "redox",
43    target_os = "wasi"
44)))]
45struct Tiocsctty;
46
47#[cfg(not(any(
48    windows,
49    target_os = "aix",
50    target_os = "horizon",
51    target_os = "redox",
52    target_os = "wasi"
53)))]
54unsafe impl ioctl::Ioctl for Tiocsctty {
55    type Output = ();
56
57    const IS_MUTATING: bool = false;
58
59    fn opcode(&self) -> ioctl::Opcode {
60        c::TIOCSCTTY as ioctl::Opcode
61    }
62
63    fn as_ptr(&mut self) -> *mut c::c_void {
64        crate::utils::as_ptr(&0_u32) as *mut c::c_void
65    }
66
67    unsafe fn output_from_ptr(
68        _: ioctl::IoctlOutput,
69        _: *mut c::c_void,
70    ) -> io::Result<Self::Output> {
71        Ok(())
72    }
73}