Skip to content

Commit

Permalink
fallback to procfs
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Jun 3, 2024
1 parent a552dd9 commit e41e233
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions library/std/src/sys/pal/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,16 @@ impl fmt::Debug for File {
let mut buf = vec![0; libc::PATH_MAX as usize];
let n = unsafe { libc::fcntl(fd, libc::F_GETPATH, buf.as_ptr()) };
if n == -1 {
cfg_if::cfg_if! {
if #[cfg(target_os = "netbsd")] {
// fallback to procfs as last resort
let mut p = PathBuf::from("/proc/self/fd");
p.push(&fd.to_string());
if p.exists() {
return readlink(&p).ok();
}
}
}
return None;
}
let l = buf.iter().position(|&c| c == 0).unwrap();
Expand Down

0 comments on commit e41e233

Please sign in to comment.