Skip to content

Commit

Permalink
Rollup merge of #88542 - tavianator:readdir_r-errno, r=jyn514
Browse files Browse the repository at this point in the history
Use the return value of readdir_r() instead of errno

POSIX says:

> If successful, the readdir_r() function shall return zero; otherwise,
> an error number shall be returned to indicate the error.

But we were previously using errno instead of the return value.  This
led to issue #86649.
  • Loading branch information
m-ou-se authored Sep 1, 2021
2 parents bbc94ed + 0e0c8ae commit 59588a9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/std/src/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,16 @@ impl Iterator for ReadDir {
let mut ret = DirEntry { entry: mem::zeroed(), dir: Arc::clone(&self.inner) };
let mut entry_ptr = ptr::null_mut();
loop {
if readdir64_r(self.inner.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 {
let err = readdir64_r(self.inner.dirp.0, &mut ret.entry, &mut entry_ptr);
if err != 0 {
if entry_ptr.is_null() {
// We encountered an error (which will be returned in this iteration), but
// we also reached the end of the directory stream. The `end_of_stream`
// flag is enabled to make sure that we return `None` in the next iteration
// (instead of looping forever)
self.end_of_stream = true;
}
return Some(Err(Error::last_os_error()));
return Some(Err(Error::from_raw_os_error(err)));
}
if entry_ptr.is_null() {
return None;
Expand Down

0 comments on commit 59588a9

Please sign in to comment.