mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 20:31:19 -03:00
Fix build on OpenBSD/NetBSD
Co-authored-by: Michael Nickerson <darkshadow02@me.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Tested on OpenBSD; we'll see about NetBSD. Closes #11893 Closes #11892 Closes #11904
This commit is contained in:
@@ -14,6 +14,7 @@ pub mod limits {
|
||||
/// Note these are uints on Linux but ints everywhere else - we use -1 as a sentinel
|
||||
/// so cast to int.
|
||||
pub mod common {
|
||||
use cfg_if::cfg_if;
|
||||
use libc;
|
||||
pub const CORE: libc::c_int = libc::RLIMIT_CORE as _;
|
||||
pub const DATA: libc::c_int = libc::RLIMIT_DATA as _;
|
||||
@@ -23,8 +24,15 @@ pub mod common {
|
||||
pub const STACK: libc::c_int = libc::RLIMIT_STACK as _;
|
||||
pub const CPU: libc::c_int = libc::RLIMIT_CPU as _;
|
||||
pub const NPROC: libc::c_int = libc::RLIMIT_NPROC as _;
|
||||
pub const AS: libc::c_int = libc::RLIMIT_AS 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")]
|
||||
@@ -68,13 +76,33 @@ pub mod macos {
|
||||
|
||||
#[cfg(bsd)]
|
||||
pub mod bsd {
|
||||
use cfg_if::cfg_if;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
);
|
||||
|
||||
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 NICE: libc::c_int = -1;
|
||||
pub const NTHR: libc::c_int = -1;
|
||||
|
||||
16
src/env/environment.rs
vendored
16
src/env/environment.rs
vendored
@@ -26,6 +26,7 @@
|
||||
use crate::wcstringutil::join_strings;
|
||||
use crate::wutil::{fish_wcstol, wgetcwd, wgettext};
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use libc::{c_int, uid_t};
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
use std::collections::HashMap;
|
||||
@@ -567,11 +568,16 @@ fn setup_user(vars: &EnvStack) {
|
||||
|
||||
pub(crate) static FALLBACK_PATH: Lazy<&[WString]> = Lazy::new(|| {
|
||||
// _CS_PATH: colon-separated paths to find POSIX utilities. Same as USER_CS_PATH.
|
||||
// BSDs only have the "USER_" form, while Linux only has the "CS_" form.
|
||||
#[cfg(any(apple, bsd))]
|
||||
let cs_path = libc::USER_CS_PATH;
|
||||
#[cfg(not(any(apple, bsd)))]
|
||||
let cs_path = libc::_CS_PATH;
|
||||
cfg_if!(
|
||||
// TODO use _CS_PATH (https://github.com/rust-lang/libc/pull/4738)
|
||||
if #[cfg(any(target_os = "netbsd", target_os = "openbsd"))] {
|
||||
let cs_path = 1;
|
||||
} else if #[cfg(bsd)] {
|
||||
let cs_path = libc::USER_CS_PATH;
|
||||
} else {
|
||||
let cs_path = libc::_CS_PATH;
|
||||
}
|
||||
);
|
||||
|
||||
let buf_size = unsafe { libc::confstr(cs_path, std::ptr::null_mut(), 0) };
|
||||
let paths: Vec<WString> = if buf_size > 0 {
|
||||
|
||||
Reference in New Issue
Block a user