Skip to content

Commit

Permalink
fs: Use readdir() instead of readdir_r() on Android
Browse files Browse the repository at this point in the history
Bionic also guarantees that readdir() is thread-safe enough.
  • Loading branch information
tavianator committed Jan 21, 2022
1 parent bc04a4e commit 3eeb3ca
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions library/std/src/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use libc::dirfd;
#[cfg(any(target_os = "linux", target_os = "emscripten"))]
use libc::fstatat64;
#[cfg(any(
target_os = "android",
target_os = "solaris",
target_os = "fuchsia",
target_os = "redox",
Expand All @@ -46,6 +47,7 @@ use libc::readdir64;
#[cfg(any(target_os = "emscripten", target_os = "l4re"))]
use libc::readdir64_r;
#[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "emscripten",
target_os = "solaris",
Expand Down Expand Up @@ -211,6 +213,7 @@ struct InnerReadDir {
pub struct ReadDir {
inner: Arc<InnerReadDir>,
#[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "solaris",
target_os = "illumos",
Expand All @@ -232,6 +235,7 @@ pub struct DirEntry {
// readdir() (not readdir_r()), because a) struct dirent may use a flexible
// array to store the name, b) it lives only until the next readdir() call.
#[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "solaris",
target_os = "illumos",
Expand Down Expand Up @@ -459,6 +463,7 @@ impl Iterator for ReadDir {
type Item = io::Result<DirEntry>;

#[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "solaris",
target_os = "fuchsia",
Expand Down Expand Up @@ -498,6 +503,7 @@ impl Iterator for ReadDir {
}

#[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "solaris",
target_os = "fuchsia",
Expand Down Expand Up @@ -665,6 +671,7 @@ impl DirEntry {
}

#[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "solaris",
target_os = "illumos",
Expand All @@ -675,6 +682,7 @@ impl DirEntry {
unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()) }
}
#[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "solaris",
target_os = "illumos",
Expand Down Expand Up @@ -1086,6 +1094,7 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
Ok(ReadDir {
inner: Arc::new(inner),
#[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "solaris",
target_os = "illumos",
Expand Down Expand Up @@ -1622,6 +1631,7 @@ mod remove_dir_impl {
ReadDir {
inner: Arc::new(InnerReadDir { dirp, root: dummy_root }),
#[cfg(not(any(
target_os = "android",
target_os = "linux",
target_os = "solaris",
target_os = "illumos",
Expand Down

0 comments on commit 3eeb3ca

Please sign in to comment.