Skip to content

Commit 1ac1cb8

Browse files
committed
Check exit code in Dir::as_raw_fd
1 parent dad24fb commit 1ac1cb8

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

changelog/2747.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`Dir::as_raw_fd` now panics if `libc::dirfd` returns a negative value.

src/dir.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ impl std::os::fd::AsFd for Dir {
137137

138138
impl AsRawFd for Dir {
139139
fn as_raw_fd(&self) -> RawFd {
140-
unsafe { libc::dirfd(self.0.as_ptr()) }
140+
let fd = unsafe { libc::dirfd(self.0.as_ptr()) };
141+
assert!(fd >= 0, "dirfd returned error: {}", Errno::last());
142+
fd
141143
}
142144
}
143145

0 commit comments

Comments
 (0)