diff --git a/Cargo.lock b/Cargo.lock index cffb0d9265a..b9b733e9a06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3442,9 +3442,10 @@ dependencies = [ "icu_locale", "jiff", "jiff-icu", - "nix", + "libc", "parse_datetime", "regex", + "rustix", "tempfile", "uucore", "windows-sys 0.61.2", diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 8879c35b585..c4948a40430 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -1970,9 +1970,10 @@ dependencies = [ "icu_locale", "jiff", "jiff-icu", - "nix", + "libc", "parse_datetime", "regex", + "rustix", "uucore", "windows-sys 0.61.2", ] diff --git a/src/uu/date/Cargo.toml b/src/uu/date/Cargo.toml index 36604d0c337..840b8602f15 100644 --- a/src/uu/date/Cargo.toml +++ b/src/uu/date/Cargo.toml @@ -44,7 +44,8 @@ regex = { workspace = true } uucore = { workspace = true, features = ["parser", "i18n-datetime"] } [target.'cfg(unix)'.dependencies] -nix = { workspace = true, features = ["time"] } +libc = { workspace = true } +rustix = { workspace = true, features = ["time"] } [target.'cfg(windows)'.dependencies] windows-sys = { workspace = true, features = [ diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index d9b48da08f3..89ee23fd31e 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -985,12 +985,12 @@ fn get_clock_resolution() -> Timestamp { /// as `CLOCK_REALTIME` is required to be supported. /// Failure would indicate a non-conforming or otherwise broken implementation. fn get_clock_resolution() -> Timestamp { - use nix::time::{ClockId, clock_getres}; + use rustix::time::{ClockId, clock_getres}; - let timespec = clock_getres(ClockId::CLOCK_REALTIME).unwrap(); + let timespec = clock_getres(ClockId::Realtime); - #[allow(clippy::unnecessary_cast)] // Cast required on 32-bit platforms - Timestamp::constant(timespec.tv_sec() as _, timespec.tv_nsec() as _) + #[allow(clippy::unnecessary_cast, reason = "needed for 32 bit target")] + Timestamp::constant(timespec.tv_sec as _, timespec.tv_nsec as _) } #[cfg(all(unix, target_os = "redox"))] @@ -1047,12 +1047,16 @@ fn set_system_datetime(_date: Zoned) -> UResult<()> { /// `` /// `` fn set_system_datetime(date: Zoned) -> UResult<()> { - use nix::{sys::time::TimeSpec, time::ClockId}; + use rustix::time::{ClockId, Timespec, clock_settime}; let ts = date.timestamp(); - let timespec = TimeSpec::new(ts.as_second() as _, ts.subsec_nanosecond() as _); + let timespec = Timespec { + tv_sec: ts.as_second() as _, + tv_nsec: ts.subsec_nanosecond() as _, + }; - nix::time::clock_settime(ClockId::CLOCK_REALTIME, timespec) + clock_settime(ClockId::Realtime, timespec) + .map_err(std::io::Error::from) .map_err_context(|| translate!("date-error-cannot-set-date")) } diff --git a/src/uu/date/src/locale.rs b/src/uu/date/src/locale.rs index 8d1c0b0133e..d5a044c734b 100644 --- a/src/uu/date/src/locale.rs +++ b/src/uu/date/src/locale.rs @@ -28,7 +28,6 @@ macro_rules! cfg_langinfo { cfg_langinfo! { use std::ffi::CStr; use std::sync::OnceLock; - use nix::libc; #[cfg(test)] use std::sync::Mutex;