Skip to content

Switch Fuchsia to readdir (instead of readdir_r) #40023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/liblibc
21 changes: 11 additions & 10 deletions src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off_t as off64_t,
ftruncate as ftruncate64, lseek as lseek64, dirent as dirent64, open as open64};
#[cfg(not(any(target_os = "linux",
target_os = "emscripten",
target_os = "solaris")))]
target_os = "solaris",
target_os = "fuchsia")))]
use libc::{readdir_r as readdir64_r};

pub struct File(FileDesc);
Expand All @@ -59,10 +60,10 @@ pub struct DirEntry {
entry: dirent64,
root: Arc<PathBuf>,
// We need to store an owned copy of the directory name
// on Solaris because a) it uses a zero-length array to
// store the name, b) its lifetime between readdir calls
// is not guaranteed.
#[cfg(target_os = "solaris")]
// on Solaris and Fuchsia because a) it uses a zero-length
// array to store the name, b) its lifetime between readdir
// calls is not guaranteed.
#[cfg(any(target_os = "solaris", target_os = "fuchsia"))]
name: Box<[u8]>
}

Expand Down Expand Up @@ -205,14 +206,14 @@ impl fmt::Debug for ReadDir {
impl Iterator for ReadDir {
type Item = io::Result<DirEntry>;

#[cfg(target_os = "solaris")]
#[cfg(any(target_os = "solaris", target_os = "fuchsia"))]
fn next(&mut self) -> Option<io::Result<DirEntry>> {
unsafe {
loop {
// Although readdir_r(3) would be a correct function to use here because
// 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.
// of the thread safety, on Illumos and Fuchsia 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() {
Expand Down Expand Up @@ -240,7 +241,7 @@ impl Iterator for ReadDir {
}
}

#[cfg(not(target_os = "solaris"))]
#[cfg(not(any(target_os = "solaris", target_os = "fuchsia")))]
fn next(&mut self) -> Option<io::Result<DirEntry>> {
unsafe {
let mut ret = DirEntry {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn errno() -> i32 {
}

/// Sets the platform-specific value of errno
#[cfg(target_os = "solaris")] // only needed for readdir so far
#[cfg(any(target_os = "solaris", target_os = "fuchsia"))] // only needed for readdir so far
pub fn set_errno(e: i32) {
unsafe {
*errno_location() = e as c_int
Expand Down