We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3f8a66d + 49ed986 commit 6af11c1Copy full SHA for 6af11c1
src/dir.rs
@@ -53,14 +53,12 @@ impl Dir {
53
54
/// Converts from a file descriptor, closing it on success or failure.
55
pub fn from_fd(fd: RawFd) -> Result<Self> {
56
- let d = unsafe { libc::fdopendir(fd) };
57
- if d.is_null() {
+ let d = ptr::NonNull::new(unsafe { libc::fdopendir(fd) }).ok_or_else(|| {
58
let e = Error::last();
59
unsafe { libc::close(fd) };
60
- return Err(e);
61
- };
62
- // Always guaranteed to be non-null by the previous check
63
- Ok(Dir(ptr::NonNull::new(d).unwrap()))
+ e
+ })?;
+ Ok(Dir(d))
64
}
65
66
/// Returns an iterator of `Result<Entry>` which rewinds when finished.
0 commit comments