Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/uu/date/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
18 changes: 11 additions & 7 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -1047,12 +1047,16 @@ fn set_system_datetime(_date: Zoned) -> UResult<()> {
/// `<https://linux.die.net/man/3/clock_settime>`
/// `<https://www.gnu.org/software/libc/manual/html_node/Time-Types.html>`
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"))
}

Expand Down
1 change: 0 additions & 1 deletion src/uu/date/src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading