Skip to content

Commit b5edfb7

Browse files
authored
Unrolled build for #146549
Rollup merge of #146549 - asomers:freebsd-readdir, r=Mark-Simulacrum On FreeBSD, use readdir instead of readdir_r readdir_r has the same problems on FreeBSD as it does on other platforms: it assumes a fixed NAME_MAX. And readdir has the same thread-safety guarantee as it does on other platforms: it's safe as long as only one thread tries to read from the directory stream at a given time. Furthermore, readdir_r is likely to be removed for FreeBSD 16, so we should stop using it now.
2 parents a454fcc + 572b423 commit b5edfb7

File tree

1 file changed

+63
-57
lines changed

1 file changed

+63
-57
lines changed

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

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,31 @@ use libc::fstatat as fstatat64;
2121
#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "hurd"))]
2222
use libc::fstatat64;
2323
#[cfg(any(
24+
target_os = "aix",
2425
target_os = "android",
25-
target_os = "solaris",
26+
target_os = "freebsd",
2627
target_os = "fuchsia",
27-
target_os = "redox",
2828
target_os = "illumos",
29-
target_os = "aix",
3029
target_os = "nto",
30+
target_os = "redox",
31+
target_os = "solaris",
3132
target_os = "vita",
3233
all(target_os = "linux", target_env = "musl"),
3334
))]
3435
use libc::readdir as readdir64;
3536
#[cfg(not(any(
37+
target_os = "aix",
3638
target_os = "android",
37-
target_os = "linux",
38-
target_os = "solaris",
39+
target_os = "freebsd",
40+
target_os = "fuchsia",
41+
target_os = "hurd",
3942
target_os = "illumos",
4043
target_os = "l4re",
41-
target_os = "fuchsia",
42-
target_os = "redox",
43-
target_os = "aix",
44+
target_os = "linux",
4445
target_os = "nto",
46+
target_os = "redox",
47+
target_os = "solaris",
4548
target_os = "vita",
46-
target_os = "hurd",
4749
)))]
4850
use libc::readdir_r as readdir64_r;
4951
#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "hurd"))]
@@ -271,16 +273,17 @@ unsafe impl Send for Dir {}
271273
unsafe impl Sync for Dir {}
272274

273275
#[cfg(any(
276+
target_os = "aix",
274277
target_os = "android",
275-
target_os = "linux",
276-
target_os = "solaris",
277-
target_os = "illumos",
278+
target_os = "freebsd",
278279
target_os = "fuchsia",
279-
target_os = "redox",
280-
target_os = "aix",
280+
target_os = "hurd",
281+
target_os = "illumos",
282+
target_os = "linux",
281283
target_os = "nto",
284+
target_os = "redox",
285+
target_os = "solaris",
282286
target_os = "vita",
283-
target_os = "hurd",
284287
))]
285288
pub struct DirEntry {
286289
dir: Arc<InnerReadDir>,
@@ -295,16 +298,17 @@ pub struct DirEntry {
295298
// we're not using the immediate `d_name` on these targets. Keeping this as an
296299
// `entry` field in `DirEntry` helps reduce the `cfg` boilerplate elsewhere.
297300
#[cfg(any(
301+
target_os = "aix",
298302
target_os = "android",
299-
target_os = "linux",
300-
target_os = "solaris",
301-
target_os = "illumos",
303+
target_os = "freebsd",
302304
target_os = "fuchsia",
303-
target_os = "redox",
304-
target_os = "aix",
305+
target_os = "hurd",
306+
target_os = "illumos",
307+
target_os = "linux",
305308
target_os = "nto",
309+
target_os = "redox",
310+
target_os = "solaris",
306311
target_os = "vita",
307-
target_os = "hurd",
308312
))]
309313
struct dirent64_min {
310314
d_ino: u64,
@@ -319,16 +323,17 @@ struct dirent64_min {
319323
}
320324

321325
#[cfg(not(any(
326+
target_os = "aix",
322327
target_os = "android",
323-
target_os = "linux",
324-
target_os = "solaris",
325-
target_os = "illumos",
328+
target_os = "freebsd",
326329
target_os = "fuchsia",
327-
target_os = "redox",
328-
target_os = "aix",
330+
target_os = "hurd",
331+
target_os = "illumos",
332+
target_os = "linux",
329333
target_os = "nto",
334+
target_os = "redox",
335+
target_os = "solaris",
330336
target_os = "vita",
331-
target_os = "hurd",
332337
)))]
333338
pub struct DirEntry {
334339
dir: Arc<InnerReadDir>,
@@ -698,16 +703,17 @@ impl Iterator for ReadDir {
698703
type Item = io::Result<DirEntry>;
699704

700705
#[cfg(any(
706+
target_os = "aix",
701707
target_os = "android",
702-
target_os = "linux",
703-
target_os = "solaris",
708+
target_os = "freebsd",
704709
target_os = "fuchsia",
705-
target_os = "redox",
710+
target_os = "hurd",
706711
target_os = "illumos",
707-
target_os = "aix",
712+
target_os = "linux",
708713
target_os = "nto",
714+
target_os = "redox",
715+
target_os = "solaris",
709716
target_os = "vita",
710-
target_os = "hurd",
711717
))]
712718
fn next(&mut self) -> Option<io::Result<DirEntry>> {
713719
use crate::sys::os::{errno, set_errno};
@@ -768,6 +774,9 @@ impl Iterator for ReadDir {
768774
// only access those bytes.
769775
#[cfg(not(target_os = "vita"))]
770776
let entry = dirent64_min {
777+
#[cfg(target_os = "freebsd")]
778+
d_ino: (*entry_ptr).d_fileno,
779+
#[cfg(not(target_os = "freebsd"))]
771780
d_ino: (*entry_ptr).d_ino as u64,
772781
#[cfg(not(any(
773782
target_os = "solaris",
@@ -791,16 +800,17 @@ impl Iterator for ReadDir {
791800
}
792801

793802
#[cfg(not(any(
803+
target_os = "aix",
794804
target_os = "android",
795-
target_os = "linux",
796-
target_os = "solaris",
805+
target_os = "freebsd",
797806
target_os = "fuchsia",
798-
target_os = "redox",
807+
target_os = "hurd",
799808
target_os = "illumos",
800-
target_os = "aix",
809+
target_os = "linux",
801810
target_os = "nto",
811+
target_os = "redox",
812+
target_os = "solaris",
802813
target_os = "vita",
803-
target_os = "hurd",
804814
)))]
805815
fn next(&mut self) -> Option<io::Result<DirEntry>> {
806816
if self.end_of_stream {
@@ -970,36 +980,32 @@ impl DirEntry {
970980
}
971981

972982
#[cfg(any(
973-
target_os = "linux",
983+
target_os = "aix",
984+
target_os = "android",
974985
target_os = "cygwin",
975986
target_os = "emscripten",
976-
target_os = "android",
977-
target_os = "solaris",
978-
target_os = "illumos",
979-
target_os = "haiku",
980-
target_os = "l4re",
981-
target_os = "fuchsia",
982-
target_os = "redox",
983-
target_os = "vxworks",
984987
target_os = "espidf",
988+
target_os = "freebsd",
989+
target_os = "fuchsia",
990+
target_os = "haiku",
985991
target_os = "horizon",
986-
target_os = "vita",
987-
target_os = "aix",
988-
target_os = "nto",
989992
target_os = "hurd",
993+
target_os = "illumos",
994+
target_os = "l4re",
995+
target_os = "linux",
996+
target_os = "nto",
997+
target_os = "redox",
990998
target_os = "rtems",
999+
target_os = "solaris",
1000+
target_os = "vita",
1001+
target_os = "vxworks",
9911002
target_vendor = "apple",
9921003
))]
9931004
pub fn ino(&self) -> u64 {
9941005
self.entry.d_ino as u64
9951006
}
9961007

997-
#[cfg(any(
998-
target_os = "freebsd",
999-
target_os = "openbsd",
1000-
target_os = "netbsd",
1001-
target_os = "dragonfly"
1002-
))]
1008+
#[cfg(any(target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly"))]
10031009
pub fn ino(&self) -> u64 {
10041010
self.entry.d_fileno as u64
10051011
}
@@ -1014,7 +1020,6 @@ impl DirEntry {
10141020
#[cfg(any(
10151021
target_os = "netbsd",
10161022
target_os = "openbsd",
1017-
target_os = "freebsd",
10181023
target_os = "dragonfly",
10191024
target_vendor = "apple",
10201025
))]
@@ -1030,7 +1035,6 @@ impl DirEntry {
10301035
#[cfg(not(any(
10311036
target_os = "netbsd",
10321037
target_os = "openbsd",
1033-
target_os = "freebsd",
10341038
target_os = "dragonfly",
10351039
target_vendor = "apple",
10361040
)))]
@@ -1040,6 +1044,7 @@ impl DirEntry {
10401044

10411045
#[cfg(not(any(
10421046
target_os = "android",
1047+
target_os = "freebsd",
10431048
target_os = "linux",
10441049
target_os = "solaris",
10451050
target_os = "illumos",
@@ -1055,6 +1060,7 @@ impl DirEntry {
10551060
}
10561061
#[cfg(any(
10571062
target_os = "android",
1063+
target_os = "freebsd",
10581064
target_os = "linux",
10591065
target_os = "solaris",
10601066
target_os = "illumos",

0 commit comments

Comments
 (0)