about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-08-31 14:11:42 -0400
committerTavian Barnes <tavianator@tavianator.com>2021-08-31 14:11:42 -0400
commit0e0c8aef87fe78c797a455d34e7490254f3d22b2 (patch)
treeb07f8bcfb4682e70ed99c268542897b1e884ee6a /library/std/src/sys
parent76d18cfb8945f824c8777e04981e930d2037954e (diff)
downloadrust-0e0c8aef87fe78c797a455d34e7490254f3d22b2.tar.gz
rust-0e0c8aef87fe78c797a455d34e7490254f3d22b2.zip
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.
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/unix/fs.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs
index 6075eb5c7c5..6d7524a733a 100644
--- a/library/std/src/sys/unix/fs.rs
+++ b/library/std/src/sys/unix/fs.rs
@@ -506,7 +506,8 @@ 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`
@@ -514,7 +515,7 @@ impl Iterator for ReadDir {
                         // (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;