Skip to content

Commit

Permalink
cleanup: remove redundant unwrap in Dir::from_fd
Browse files Browse the repository at this point in the history
  • Loading branch information
scottlamb committed Mar 16, 2021
1 parent 2d36e3a commit f1c4753
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ impl Dir {

/// Converts from a file descriptor, closing it on success or failure.
pub fn from_fd(fd: RawFd) -> Result<Self> {
let d = unsafe { libc::fdopendir(fd) };
if d.is_null() {
let d = ptr::NonNull::new(unsafe { libc::fdopendir(fd) }).ok_or_else(|| {
let e = Error::last();
unsafe { libc::close(fd) };
return Err(e);
};
// Always guaranteed to be non-null by the previous check
Ok(Dir(ptr::NonNull::new(d).unwrap()))
e
})?;
Ok(Dir(d))
}

/// Returns an iterator of `Result<Entry>` which rewinds when finished.
Expand Down

0 comments on commit f1c4753

Please sign in to comment.