Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0e0c8ae

Browse files
committedAug 31, 2021
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 rust-lang#86649.
1 parent 76d18cf commit 0e0c8ae

File tree

1 file changed

+3
-2
lines changed
  • library/std/src/sys/unix

1 file changed

+3
-2
lines changed
 

‎library/std/src/sys/unix/fs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,16 @@ impl Iterator for ReadDir {
506506
let mut ret = DirEntry { entry: mem::zeroed(), dir: Arc::clone(&self.inner) };
507507
let mut entry_ptr = ptr::null_mut();
508508
loop {
509-
if readdir64_r(self.inner.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 {
509+
let err = readdir64_r(self.inner.dirp.0, &mut ret.entry, &mut entry_ptr);
510+
if err != 0 {
510511
if entry_ptr.is_null() {
511512
// We encountered an error (which will be returned in this iteration), but
512513
// we also reached the end of the directory stream. The `end_of_stream`
513514
// flag is enabled to make sure that we return `None` in the next iteration
514515
// (instead of looping forever)
515516
self.end_of_stream = true;
516517
}
517-
return Some(Err(Error::last_os_error()));
518+
return Some(Err(Error::from_raw_os_error(err)));
518519
}
519520
if entry_ptr.is_null() {
520521
return None;

0 commit comments

Comments
 (0)
This repository has been archived.