diff --git a/Cargo.lock b/Cargo.lock index 3de0ea0cc..275c7b231 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4138,10 +4138,12 @@ dependencies = [ "fluent", "foldhash 0.2.0", "itertools 0.14.0", + "libc", "memchr", "nix", "rand 0.10.1", "rayon", + "rustix", "self_cell", "tempfile", "thiserror 2.0.18", diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index e8c40a555..769daabe9 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -2010,10 +2010,12 @@ dependencies = [ "fluent", "foldhash 0.2.0", "itertools", + "libc", "memchr", "nix", "rand", "rayon", + "rustix", "self_cell", "tempfile", "thiserror", diff --git a/src/uu/sort/Cargo.toml b/src/uu/sort/Cargo.toml index d789d68b4..206fe2949 100644 --- a/src/uu/sort/Cargo.toml +++ b/src/uu/sort/Cargo.toml @@ -47,11 +47,17 @@ uucore = { workspace = true, features = [ fluent = { workspace = true } foldhash = { workspace = true } +[target.'cfg(all(unix, not(any(target_os = "redox", target_os = "fuchsia", target_os = "haiku", target_os = "solaris", target_os = "illumos"))))'.dependencies] +rustix = { workspace = true, features = ["process"] } + [target.'cfg(not(any(target_os = "redox", target_os = "wasi")))'.dependencies] ctrlc = { workspace = true } +[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] +nix = { workspace = true } + [target.'cfg(unix)'.dependencies] -nix = { workspace = true, features = ["resource"] } +libc = { workspace = true } [dev-dependencies] divan = { workspace = true } diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index a360f5f95..9d117d152 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -7,7 +7,7 @@ // https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html // https://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html -// spell-checker:ignore (misc) HFKJFK Mbdfhn getrlimit RLIMIT_NOFILE rlim bigdecimal extendedbigdecimal hexdigit behaviour keydef GETFD localeconv foldhash +// spell-checker:ignore (misc) HFKJFK Mbdfhn getrlimit Nofile rlim bigdecimal extendedbigdecimal hexdigit behaviour keydef GETFD localeconv foldhash // spell-checker:ignore (misc) uppercased qsort getmonth juin juil mod buffer_hint; @@ -1371,13 +1371,12 @@ fn make_sort_mode_arg(mode: &'static str, short: char, help: String) -> Arg { )) ))] fn get_rlimit() -> UResult { - use nix::sys::resource::{RLIM_INFINITY, Resource, getrlimit}; + use rustix::process::{Resource, getrlimit}; + + let rlim_cur = getrlimit(Resource::Nofile) + .current + .ok_or_else(|| UUsageError::new(2, translate!("sort-failed-fetch-rlimit")))?; - let (rlim_cur, _rlim_max) = getrlimit(Resource::RLIMIT_NOFILE) - .map_err(|_| UUsageError::new(2, translate!("sort-failed-fetch-rlimit")))?; - if rlim_cur == RLIM_INFINITY { - return Err(UUsageError::new(2, translate!("sort-failed-fetch-rlimit"))); - } usize::try_from(rlim_cur) .map_err(|_| UUsageError::new(2, translate!("sort-failed-fetch-rlimit"))) } @@ -1410,8 +1409,6 @@ pub(crate) fn fd_soft_limit() -> Option { #[cfg(unix)] pub(crate) fn current_open_fd_count() -> Option { - use nix::libc; - fn count_dir(path: &str) -> Option { let entries = std::fs::read_dir(path).ok()?; let mut count = 0usize; @@ -1770,7 +1767,6 @@ fn locale_failed_to_set() -> bool { #[cfg(unix)] fn locale_failed_to_set() -> bool { - use nix::libc; unsafe { libc::setlocale(libc::LC_COLLATE, c"".as_ptr()).is_null() } }