]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/sys/unix/fs.rs
Auto merge of #34776 - cuviper:solaris-readdir, r=alexcrichton
[rust.git] / src / libstd / sys / unix / fs.rs
index a004ff7afe1ecf12073f35f3a6c8af7208738f85..b315e6762633b3fd982566c5a311360a3ad4065b 100644 (file)
@@ -205,9 +205,15 @@ fn next(&mut self) -> Option<io::Result<DirEntry>> {
                 // of the thread safety, on Illumos the readdir(3C) function is safe to use
                 // in threaded applications and it is generally preferred over the
                 // readdir_r(3C) function.
+                super::os::set_errno(0);
                 let entry_ptr = libc::readdir(self.dirp.0);
                 if entry_ptr.is_null() {
-                    return None
+                    // NULL can mean either the end is reached or an error occurred.
+                    // So we had to clear errno beforehand to check for an error now.
+                    return match super::os::errno() {
+                        0 => None,
+                        e => Some(Err(Error::from_raw_os_error(e))),
+                    }
                 }
 
                 let name = (*entry_ptr).d_name.as_ptr();