use crate::posish::fs::file_path_by_ttyname_or_seaching;
use posish::fs::getpath;
use std::{fs, os::unix::ffi::OsStringExt, path::PathBuf};
pub(crate) fn file_path(file: &fs::File) -> Option<PathBuf> {
let mut buf = vec![0; libc::PATH_MAX as usize];
if let Ok(()) = getpath(file, &mut buf) {
let l = buf.iter().position(|&c| c == 0).unwrap();
buf.truncate(l as usize);
buf.shrink_to_fit();
return Some(PathBuf::from(std::ffi::OsString::from_vec(buf)));
}
file_path_by_ttyname_or_seaching(file)
}