Skip to content

Commit a552dd9

Browse files
committed
std::unix::fs::get_path: using fcntl codepath for netbsd instead.
on netbsd, procfs is not as central as on linux/solaris thus can be perfectly not mounted. Thus using fcntl with F_GETPATH, the kernel deals with MAXPATHLEN internally too.
1 parent 8768db9 commit a552dd9

File tree

1 file changed

+3
-8
lines changed
  • library/std/src/sys/pal/unix

1 file changed

+3
-8
lines changed

library/std/src/sys/pal/unix/fs.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1481,22 +1481,17 @@ impl FromRawFd for File {
14811481

14821482
impl fmt::Debug for File {
14831483
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1484-
#[cfg(any(
1485-
target_os = "linux",
1486-
target_os = "netbsd",
1487-
target_os = "illumos",
1488-
target_os = "solaris"
1489-
))]
1484+
#[cfg(any(target_os = "linux", target_os = "illumos", target_os = "solaris"))]
14901485
fn get_path(fd: c_int) -> Option<PathBuf> {
14911486
let mut p = PathBuf::from("/proc/self/fd");
14921487
p.push(&fd.to_string());
14931488
readlink(&p).ok()
14941489
}
14951490

1496-
#[cfg(target_vendor = "apple")]
1491+
#[cfg(any(target_vendor = "apple", target_os = "netbsd"))]
14971492
fn get_path(fd: c_int) -> Option<PathBuf> {
14981493
// FIXME: The use of PATH_MAX is generally not encouraged, but it
1499-
// is inevitable in this case because Apple targets define `fcntl`
1494+
// is inevitable in this case because Apple targets and NetBSD define `fcntl`
15001495
// with `F_GETPATH` in terms of `MAXPATHLEN`, and there are no
15011496
// alternatives. If a better method is invented, it should be used
15021497
// instead.

0 commit comments

Comments
 (0)