Fix remaining BSD build issues

Now building on FreeBSD / OpenBSD / NetBSD / DragonflyBSD
This commit is contained in:
Peter Ammon
2025-10-13 17:00:53 +00:00
parent b07adb532a
commit 2b428fae38
3 changed files with 79 additions and 40 deletions

View File

@@ -36,15 +36,7 @@ pub mod common {
pub const NPROC: libc::c_int = libc::RLIMIT_NPROC as _;
}
);
cfg_if!(
if #[cfg(target_os = "openbsd")] {
pub const AS: libc::c_int = -1;
} else {
pub const AS: libc::c_int = libc::RLIMIT_AS as _;
}
);
}
pub use self::common::*;
#[cfg(target_os = "linux")]
@@ -55,9 +47,10 @@ pub mod linux {
pub const RTPRIO: libc::c_int = libc::RLIMIT_RTPRIO as _;
pub const RTTIME: libc::c_int = libc::RLIMIT_RTTIME as _;
pub const RSS: libc::c_int = libc::RLIMIT_RSS as _;
pub const AS: libc::c_int = libc::RLIMIT_AS as _;
pub const SBSIZE: libc::c_int = -1;
pub const NICE: libc::c_int = libc::RLIMIT_NICE as _;
pub const NICE: libc::c_int = -1;
pub const SWAP: libc::c_int = -1;
pub const KQUEUES: libc::c_int = -1;
pub const NPTS: libc::c_int = -1;
@@ -74,6 +67,7 @@ pub mod macos {
pub const MSGQUEUE: libc::c_int = -1;
pub const RTPRIO: libc::c_int = -1;
pub const RTTIME: libc::c_int = -1;
pub const AS: libc::c_int = libc::RLIMIT_AS as _;
pub const SBSIZE: libc::c_int = -1;
pub const NICE: libc::c_int = -1;
@@ -86,35 +80,79 @@ pub mod macos {
#[cfg(any(target_os = "ios", target_os = "macos"))]
pub use self::macos::*;
#[cfg(bsd)]
pub mod bsd {
use cfg_if::cfg_if;
#[cfg(target_os = "netbsd")]
pub mod netbsd {
use libc;
cfg_if!(
if #[cfg(any(target_os = "netbsd", target_os = "openbsd"))] {
#[cfg(target_os = "netbsd")]
pub const SBSIZE: libc::c_int = libc::RLIMIT_SBSIZE;
#[cfg(target_os = "openbsd")]
pub const SBSIZE: libc::c_int = -1;
pub const RSS: libc::c_int = libc::RLIMIT_RSS;
pub const SWAP: libc::c_int = -1;
pub const KQUEUES: libc::c_int = -1;
} else {
pub const SBSIZE: libc::c_int = libc::RLIMIT_SBSIZE;
pub const RSS: libc::c_int = libc::RLIMIT_RSS;
pub const SWAP: libc::c_int = libc::RLIMIT_SWAP;
pub const KQUEUES: libc::c_int = libc::RLIMIT_KQUEUES;
}
);
pub const SBSIZE: libc::c_int = libc::RLIMIT_SBSIZE;
pub const RSS: libc::c_int = libc::RLIMIT_RSS;
pub const NTHR: libc::c_int = libc::RLIMIT_NTHR;
pub const AS: libc::c_int = libc::RLIMIT_AS as _;
cfg_if!(
if #[cfg(target_os = "freebsd")] {
pub const NPTS: libc::c_int = libc::RLIMIT_NPTS;
} else {
pub const NPTS: libc::c_int = -1;
}
);
pub const KQUEUES: libc::c_int = -1;
pub const NPTS: libc::c_int = -1;
pub const SWAP: libc::c_int = -1;
pub const NICE: libc::c_int = -1;
pub const SIGPENDING: libc::c_int = -1;
pub const MSGQUEUE: libc::c_int = -1;
pub const RTPRIO: libc::c_int = -1;
pub const RTTIME: libc::c_int = -1;
}
#[cfg(target_os = "netbsd")]
pub use self::netbsd::*;
#[cfg(target_os = "openbsd")]
pub mod openbsd {
use libc;
pub const RSS: libc::c_int = libc::RLIMIT_RSS;
pub const SBSIZE: libc::c_int = -1;
pub const NTHR: libc::c_int = -1;
pub const KQUEUES: libc::c_int = -1;
pub const NPTS: libc::c_int = -1;
pub const SWAP: libc::c_int = -1;
pub const NICE: libc::c_int = -1;
pub const SIGPENDING: libc::c_int = -1;
pub const MSGQUEUE: libc::c_int = -1;
pub const RTPRIO: libc::c_int = -1;
pub const RTTIME: libc::c_int = -1;
pub const AS: libc::c_int = -1;
}
#[cfg(target_os = "openbsd")]
pub use self::openbsd::*;
#[cfg(target_os = "dragonfly")]
pub mod dragonfly {
use libc;
pub const SBSIZE: libc::c_int = libc::RLIMIT_SBSIZE;
pub const RSS: libc::c_int = libc::RLIMIT_RSS;
pub const AS: libc::c_int = libc::RLIMIT_AS;
pub const SWAP: libc::c_int = -1;
pub const KQUEUES: libc::c_int = -1;
pub const NPTS: libc::c_int = -1;
pub const NICE: libc::c_int = -1;
pub const NTHR: libc::c_int = -1;
pub const SIGPENDING: libc::c_int = -1;
pub const MSGQUEUE: libc::c_int = -1;
pub const RTPRIO: libc::c_int = -1;
pub const RTTIME: libc::c_int = -1;
}
#[cfg(target_os = "dragonfly")]
pub use self::dragonfly::*;
#[cfg(target_os = "freebsd")]
pub mod freebsd {
use libc;
pub const SBSIZE: libc::c_int = libc::RLIMIT_SBSIZE;
pub const RSS: libc::c_int = libc::RLIMIT_RSS;
pub const SWAP: libc::c_int = libc::RLIMIT_SWAP;
pub const KQUEUES: libc::c_int = libc::RLIMIT_KQUEUES;
pub const NPTS: libc::c_int = libc::RLIMIT_NPTS;
pub const AS: libc::c_int = libc::RLIMIT_AS;
pub const NICE: libc::c_int = -1;
pub const NTHR: libc::c_int = -1;
@@ -123,8 +161,8 @@ pub mod bsd {
pub const RTPRIO: libc::c_int = -1;
pub const RTTIME: libc::c_int = -1;
}
#[cfg(bsd)]
pub use self::bsd::*;
#[cfg(target_os = "freebsd")]
pub use self::freebsd::*;
#[cfg(cygwin)]
pub mod cygwin {
@@ -135,6 +173,7 @@ pub mod cygwin {
pub const RTPRIO: libc::c_int = -1;
pub const RTTIME: libc::c_int = -1;
pub const RSS: libc::c_int = -1;
pub const AS: libc::c_int = libc::RLIMIT_AS as _;
pub const SBSIZE: libc::c_int = -1;
pub const NICE: libc::c_int = -1;

View File

@@ -695,14 +695,14 @@ pub fn path_remoteness(path: &wstr) -> DirRemoteness {
#[cfg(not(any(target_os = "linux", cygwin)))]
{
let mut buf = MaybeUninit::uninit();
if unsafe { libc::statfs(narrow.as_ptr(), buf.as_mut_ptr()) } < 0 {
if unsafe { libc::statvfs(narrow.as_ptr(), buf.as_mut_ptr()) } < 0 {
return DirRemoteness::unknown;
}
let buf = unsafe { buf.assume_init() };
// statfs::f_flag is hard-coded as 64-bits on 32/64-bit FreeBSD but it's a (4-byte)
// long on 32-bit NetBSD.. and always 4-bytes on macOS (even on 64-bit builds).
#[allow(clippy::useless_conversion)]
let flags = u64::from(buf.f_flags);
let flags = buf.f_flag as u64;
#[allow(clippy::unnecessary_cast)]
if flags & (libc::MNT_LOCAL as u64) != 0 {
DirRemoteness::local

View File

@@ -287,7 +287,7 @@ pub fn next(&mut self) -> Option<io::Result<&DirEntry>> {
self.entry.reset();
self.entry.name = str2wcstring(d_name);
cfg_if!(
if #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] {
if #[cfg(bsd)] {
self.entry.inode = dent.d_fileno;
} else {
self.entry.inode = dent.d_ino;