Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions library/std/src/sys/fs/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ cfg_select! {

#[cfg(all(target_os = "linux", target_env = "gnu"))]
use libc::c_char;
#[cfg(any(
all(target_os = "linux", not(target_env = "musl")),
target_os = "android",
target_os = "fuchsia",
target_os = "hurd",
target_os = "illumos",
target_vendor = "apple",
))]
use libc::dirfd;
use libc::{c_int, mode_t};

use crate::ffi::{CStr, OsStr, OsString};
Expand Down Expand Up @@ -990,12 +981,10 @@ impl Drop for DirStream {
target_os = "nto",
target_os = "qnx",
target_os = "vita",
target_os = "hurd",

@RalfJung RalfJung Oct 2, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hurd has dirfd according to libc, and we've been using it for DirEntry::metadata, so it should be fine to use here as well.

View changes since the review

target_os = "espidf",
target_os = "horizon",
target_os = "vxworks",
target_os = "rtems",
target_os = "nuttx",
)))]
{
let fd = unsafe { libc::dirfd(self.0) };
Expand Down Expand Up @@ -1027,15 +1016,17 @@ impl DirEntry {
pub fn metadata(&self) -> io::Result<FileAttr> {
cfg_select! {
// Use directory handle where possible
any(
all(target_os = "linux", not(target_env = "musl")),
target_os = "android",
target_os = "fuchsia",
target_os = "hurd",
target_os = "illumos",
target_vendor = "apple",
) => {
let fd = cvt(unsafe { dirfd(self.dir.dirp.0) })?;
not(any(
target_os = "redox",
target_os = "nto",
target_os = "qnx",
target_os = "vita",
target_os = "espidf",
target_os = "horizon",
target_os = "vxworks",
target_os = "rtems",
)) => {
let fd = cvt(unsafe { libc::dirfd(self.dir.dirp.0) })?;

// Make this FD into a directory handle. We don't actually drop it,
// so having an `OwnedFd` is fine.
Expand Down
Loading