Skip to content

Commit 3eeb3ca

Browse files
committed
fs: Use readdir() instead of readdir_r() on Android
Bionic also guarantees that readdir() is thread-safe enough.
1 parent bc04a4e commit 3eeb3ca

File tree

1 file changed

+10
-0
lines changed
  • library/std/src/sys/unix

1 file changed

+10
-0
lines changed

library/std/src/sys/unix/fs.rs

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use libc::dirfd;
3535
#[cfg(any(target_os = "linux", target_os = "emscripten"))]
3636
use libc::fstatat64;
3737
#[cfg(any(
38+
target_os = "android",
3839
target_os = "solaris",
3940
target_os = "fuchsia",
4041
target_os = "redox",
@@ -46,6 +47,7 @@ use libc::readdir64;
4647
#[cfg(any(target_os = "emscripten", target_os = "l4re"))]
4748
use libc::readdir64_r;
4849
#[cfg(not(any(
50+
target_os = "android",
4951
target_os = "linux",
5052
target_os = "emscripten",
5153
target_os = "solaris",
@@ -211,6 +213,7 @@ struct InnerReadDir {
211213
pub struct ReadDir {
212214
inner: Arc<InnerReadDir>,
213215
#[cfg(not(any(
216+
target_os = "android",
214217
target_os = "linux",
215218
target_os = "solaris",
216219
target_os = "illumos",
@@ -232,6 +235,7 @@ pub struct DirEntry {
232235
// readdir() (not readdir_r()), because a) struct dirent may use a flexible
233236
// array to store the name, b) it lives only until the next readdir() call.
234237
#[cfg(any(
238+
target_os = "android",
235239
target_os = "linux",
236240
target_os = "solaris",
237241
target_os = "illumos",
@@ -459,6 +463,7 @@ impl Iterator for ReadDir {
459463
type Item = io::Result<DirEntry>;
460464

461465
#[cfg(any(
466+
target_os = "android",
462467
target_os = "linux",
463468
target_os = "solaris",
464469
target_os = "fuchsia",
@@ -498,6 +503,7 @@ impl Iterator for ReadDir {
498503
}
499504

500505
#[cfg(not(any(
506+
target_os = "android",
501507
target_os = "linux",
502508
target_os = "solaris",
503509
target_os = "fuchsia",
@@ -665,6 +671,7 @@ impl DirEntry {
665671
}
666672

667673
#[cfg(not(any(
674+
target_os = "android",
668675
target_os = "linux",
669676
target_os = "solaris",
670677
target_os = "illumos",
@@ -675,6 +682,7 @@ impl DirEntry {
675682
unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()) }
676683
}
677684
#[cfg(any(
685+
target_os = "android",
678686
target_os = "linux",
679687
target_os = "solaris",
680688
target_os = "illumos",
@@ -1086,6 +1094,7 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
10861094
Ok(ReadDir {
10871095
inner: Arc::new(inner),
10881096
#[cfg(not(any(
1097+
target_os = "android",
10891098
target_os = "linux",
10901099
target_os = "solaris",
10911100
target_os = "illumos",
@@ -1622,6 +1631,7 @@ mod remove_dir_impl {
16221631
ReadDir {
16231632
inner: Arc::new(InnerReadDir { dirp, root: dummy_root }),
16241633
#[cfg(not(any(
1634+
target_os = "android",
16251635
target_os = "linux",
16261636
target_os = "solaris",
16271637
target_os = "illumos",

0 commit comments

Comments
 (0)