Skip to content

Commit e9cce9b

Browse files
authored
Future-proof for FreeBSD 12 (#469)
FreeBSD 12 changes the dirent structure, among other things. libc currently binds a FreeBSD 11 ABI, but that will change some day. Tweak rustix's dirent initialization code to work with either FreeBSD 11 or 12.
1 parent d66ba5c commit e9cce9b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/backend/libc/fs/dir.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
242242
// with a field that we missed here. And we can avoid blindly copying the
243243
// whole `d_name` field, which may not be entirely allocated.
244244
#[cfg_attr(target_os = "wasi", allow(unused_mut))]
245-
#[cfg(not(target_os = "dragonfly"))]
245+
#[cfg(not(any(target_os = "freebsd", target_os = "dragonfly")))]
246246
let mut dirent = libc_dirent {
247247
#[cfg(not(any(
248248
target_os = "aix",
@@ -253,7 +253,7 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
253253
d_type,
254254
#[cfg(not(any(
255255
target_os = "aix",
256-
target_os = "freebsd",
256+
target_os = "freebsd", // Until FreeBSD 12
257257
target_os = "haiku",
258258
target_os = "ios",
259259
target_os = "macos",
@@ -306,14 +306,18 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
306306
pub d_name: [::c_char; 1024], // Max length is _POSIX_PATH_MAX
307307
// */
308308

309-
// On dragonfly, `dirent` has some non-public padding fields so we can't
310-
// directly initialize it.
311-
#[cfg(target_os = "dragonfly")]
312-
let mut dirent = unsafe {
309+
// On dragonfly and FreeBSD 12, `dirent` has some non-public padding fields
310+
// so we can't directly initialize it.
311+
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
312+
let mut dirent = {
313313
let mut dirent: libc_dirent = zeroed();
314314
dirent.d_fileno = d_fileno;
315315
dirent.d_namlen = d_namlen;
316316
dirent.d_type = d_type;
317+
#[cfg(target_os = "freebsd")]
318+
{
319+
dirent.d_reclen = d_reclen;
320+
}
317321
dirent
318322
};
319323

0 commit comments

Comments
 (0)