tilo_process/descriptor.rs
1//! Whether a raw descriptor number names a descriptor this process still has open.
2
3/// `raw`, when the descriptor it names is open and usable: a spoofed number pointing at nothing
4/// is no descriptor.
5#[must_use]
6pub fn open(raw: i32) -> Option<i32> {
7 if raw < 0 {
8 return None;
9 }
10 // SAFETY: `F_GETFD` only reads the descriptor's flags and never mutates or closes it.
11 let rc = unsafe { libc::fcntl(raw, libc::F_GETFD) };
12 (rc != -1).then_some(raw)
13}