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.
This commit is contained in:
parent
76d18cfb89
commit
0e0c8aef87
@ -506,7 +506,8 @@ impl Iterator for ReadDir {
|
|||||||
let mut ret = DirEntry { entry: mem::zeroed(), dir: Arc::clone(&self.inner) };
|
let mut ret = DirEntry { entry: mem::zeroed(), dir: Arc::clone(&self.inner) };
|
||||||
let mut entry_ptr = ptr::null_mut();
|
let mut entry_ptr = ptr::null_mut();
|
||||||
loop {
|
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() {
|
if entry_ptr.is_null() {
|
||||||
// We encountered an error (which will be returned in this iteration), but
|
// 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`
|
// we also reached the end of the directory stream. The `end_of_stream`
|
||||||
@ -514,7 +515,7 @@ impl Iterator for ReadDir {
|
|||||||
// (instead of looping forever)
|
// (instead of looping forever)
|
||||||
self.end_of_stream = true;
|
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() {
|
if entry_ptr.is_null() {
|
||||||
return None;
|
return None;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user