Skip to content

Commit 559006e

Browse files
authored
Rollup merge of rust-lang#88542 - tavianator:readdir_r-errno, r=jyn514
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.
2 parents 7cafc78 + 9ddab06 commit 559006e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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)