Skip to content

Commit a7939c7

Browse files
committed
date: replace nix by rustix
1 parent 7ade5c1 commit a7939c7

5 files changed

Lines changed: 17 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fuzz/Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/date/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ regex = { workspace = true }
4444
uucore = { workspace = true, features = ["parser", "i18n-datetime"] }
4545

4646
[target.'cfg(unix)'.dependencies]
47-
nix = { workspace = true, features = ["time"] }
47+
libc = { workspace = true }
48+
rustix = { workspace = true, features = ["time"] }
4849

4950
[target.'cfg(windows)'.dependencies]
5051
windows-sys = { workspace = true, features = [

src/uu/date/src/date.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -985,12 +985,12 @@ fn get_clock_resolution() -> Timestamp {
985985
/// as `CLOCK_REALTIME` is required to be supported.
986986
/// Failure would indicate a non-conforming or otherwise broken implementation.
987987
fn get_clock_resolution() -> Timestamp {
988-
use nix::time::{ClockId, clock_getres};
988+
use rustix::time::{ClockId, clock_getres};
989989

990-
let timespec = clock_getres(ClockId::CLOCK_REALTIME).unwrap();
990+
let timespec = clock_getres(ClockId::Realtime);
991991

992-
#[allow(clippy::unnecessary_cast)] // Cast required on 32-bit platforms
993-
Timestamp::constant(timespec.tv_sec() as _, timespec.tv_nsec() as _)
992+
#[allow(clippy::unnecessary_cast, reason = "needed for 32 bit target")]
993+
Timestamp::constant(timespec.tv_sec as _, timespec.tv_nsec as _)
994994
}
995995

996996
#[cfg(all(unix, target_os = "redox"))]
@@ -1047,12 +1047,16 @@ fn set_system_datetime(_date: Zoned) -> UResult<()> {
10471047
/// `<https://linux.die.net/man/3/clock_settime>`
10481048
/// `<https://www.gnu.org/software/libc/manual/html_node/Time-Types.html>`
10491049
fn set_system_datetime(date: Zoned) -> UResult<()> {
1050-
use nix::{sys::time::TimeSpec, time::ClockId};
1050+
use rustix::time::{ClockId, Timespec, clock_settime};
10511051

10521052
let ts = date.timestamp();
1053-
let timespec = TimeSpec::new(ts.as_second() as _, ts.subsec_nanosecond() as _);
1053+
let timespec = Timespec {
1054+
tv_sec: ts.as_second() as _,
1055+
tv_nsec: ts.subsec_nanosecond() as _,
1056+
};
10541057

1055-
nix::time::clock_settime(ClockId::CLOCK_REALTIME, timespec)
1058+
clock_settime(ClockId::Realtime, timespec)
1059+
.map_err(std::io::Error::from)
10561060
.map_err_context(|| translate!("date-error-cannot-set-date"))
10571061
}
10581062

src/uu/date/src/locale.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ macro_rules! cfg_langinfo {
2828
cfg_langinfo! {
2929
use std::ffi::CStr;
3030
use std::sync::OnceLock;
31-
use nix::libc;
3231

3332
#[cfg(test)]
3433
use std::sync::Mutex;

0 commit comments

Comments
 (0)