cap-primitives 0.16.1

Capability-based primitives
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::fs::file_path_by_searching;
#[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))]
use posish::io::ttyname;
#[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))]
use std::ffi::OsString;
use std::{fs, path::PathBuf};

pub(crate) fn file_path_by_ttyname_or_seaching(file: &fs::File) -> Option<PathBuf> {
    // If it happens to be a tty, we can look up its name.
    #[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))]
    if let Ok(name) = ttyname(file, OsString::new()) {
        return Some(name.into());
    }

    file_path_by_searching(file)
}