From 2b428fae38e81bbb5c7081d6c7ccddecddf713c4 Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Mon, 13 Oct 2025 17:00:53 +0000 Subject: [PATCH] Fix remaining BSD build issues Now building on FreeBSD / OpenBSD / NetBSD / DragonflyBSD --- src/builtins/ulimit.rs | 113 +++++++++++++++++++++++++++-------------- src/path.rs | 4 +- src/wutil/dir_iter.rs | 2 +- 3 files changed, 79 insertions(+), 40 deletions(-) diff --git a/src/builtins/ulimit.rs b/src/builtins/ulimit.rs index c1a9b4b46..45fdf72f7 100644 --- a/src/builtins/ulimit.rs +++ b/src/builtins/ulimit.rs @@ -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; diff --git a/src/path.rs b/src/path.rs index c64b1c8f5..906ec8c67 100644 --- a/src/path.rs +++ b/src/path.rs @@ -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 diff --git a/src/wutil/dir_iter.rs b/src/wutil/dir_iter.rs index d85a6e3bd..41d3e0e2d 100644 --- a/src/wutil/dir_iter.rs +++ b/src/wutil/dir_iter.rs @@ -287,7 +287,7 @@ pub fn next(&mut self) -> Option> { 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;