Skip to content
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

Future-proof for FreeBSD 12 #469

Merged
merged 1 commit into from Dec 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/backend/libc/fs/dir.rs
Expand Up @@ -242,7 +242,7 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
// with a field that we missed here. And we can avoid blindly copying the
// whole `d_name` field, which may not be entirely allocated.
#[cfg_attr(target_os = "wasi", allow(unused_mut))]
#[cfg(not(target_os = "dragonfly"))]
#[cfg(not(any(target_os = "freebsd", target_os = "dragonfly")))]
let mut dirent = libc_dirent {
#[cfg(not(any(
target_os = "aix",
Expand All @@ -253,7 +253,7 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
d_type,
#[cfg(not(any(
target_os = "aix",
target_os = "freebsd",
target_os = "freebsd", // Until FreeBSD 12
target_os = "haiku",
target_os = "ios",
target_os = "macos",
Expand Down Expand Up @@ -306,14 +306,18 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
pub d_name: [::c_char; 1024], // Max length is _POSIX_PATH_MAX
// */

// On dragonfly, `dirent` has some non-public padding fields so we can't
// directly initialize it.
#[cfg(target_os = "dragonfly")]
let mut dirent = unsafe {
// On dragonfly and FreeBSD 12, `dirent` has some non-public padding fields
// so we can't directly initialize it.
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
let mut dirent = {
let mut dirent: libc_dirent = zeroed();
dirent.d_fileno = d_fileno;
dirent.d_namlen = d_namlen;
dirent.d_type = d_type;
#[cfg(target_os = "freebsd")]
{
dirent.d_reclen = d_reclen;
}
dirent
};

Expand Down