Skip to content
Open
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
6 changes: 3 additions & 3 deletions library/std/src/sys/fs/hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ pub struct DirBuilder {

impl FileAttr {
pub fn modified(&self) -> io::Result<SystemTime> {
Ok(SystemTime::new(self.stat_val.st_mtim.tv_sec, self.stat_val.st_mtim.tv_nsec))
SystemTime::new(self.stat_val.st_mtim.tv_sec, self.stat_val.st_mtim.tv_nsec.into())
}

pub fn accessed(&self) -> io::Result<SystemTime> {
Ok(SystemTime::new(self.stat_val.st_atim.tv_sec, self.stat_val.st_atim.tv_nsec))
SystemTime::new(self.stat_val.st_atim.tv_sec, self.stat_val.st_atim.tv_nsec.into())
}

pub fn created(&self) -> io::Result<SystemTime> {
Ok(SystemTime::new(self.stat_val.st_ctim.tv_sec, self.stat_val.st_ctim.tv_nsec))
SystemTime::new(self.stat_val.st_ctim.tv_sec, self.stat_val.st_ctim.tv_nsec.into())
}

pub fn size(&self) -> u64 {
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/pal/hermit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::os::raw::c_char;
use crate::sys::env;

pub mod futex;
#[path = "../unix/time.rs"]
pub mod time;

pub fn unsupported<T>() -> io::Result<T> {
Expand Down
110 changes: 0 additions & 110 deletions library/std/src/sys/pal/hermit/time.rs

This file was deleted.

3 changes: 2 additions & 1 deletion library/std/src/sys/pal/unix/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(in crate::sys) const TIMESPEC_MAX_CAPPED: libc::timespec = libc::timespec {
tv_nsec: (u64::MAX % NSEC_PER_SEC) as i64,
};

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub(crate) struct Timespec {
pub tv_sec: i64,
pub tv_nsec: Nanoseconds,
Expand Down Expand Up @@ -66,6 +66,7 @@ impl Timespec {
}
}

#[allow(dead_code)]
pub fn now(clock: libc::clockid_t) -> Timespec {
use crate::mem::MaybeUninit;
use crate::sys::cvt;
Expand Down
22 changes: 11 additions & 11 deletions library/std/src/sys/time/hermit.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use hermit_abi::{self, CLOCK_MONOTONIC, CLOCK_REALTIME};

use crate::hash::Hash;
use crate::io;
use crate::sys::pal::time::Timespec;
use crate::time::Duration;

fn clock_gettime(clock: hermit_abi::clockid_t) -> Timespec {
let mut t = hermit_abi::timespec { tv_sec: 0, tv_nsec: 0 };
let _ = unsafe { hermit_abi::clock_gettime(clock, &raw mut t) };
Timespec::new(t.tv_sec, t.tv_nsec.into()).unwrap()
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub struct Instant(Timespec);

impl Instant {
pub fn now() -> Instant {
let mut time: Timespec = Timespec::zero();
let _ = unsafe { hermit_abi::clock_gettime(CLOCK_MONOTONIC, &raw mut time.t) };

Instant(time)
Instant(clock_gettime(CLOCK_MONOTONIC))
}

pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> {
Expand All @@ -38,15 +41,12 @@ impl SystemTime {

pub const MIN: SystemTime = SystemTime(Timespec::MIN);

pub fn new(tv_sec: i64, tv_nsec: i32) -> SystemTime {
SystemTime(Timespec::new(tv_sec, tv_nsec))
pub fn new(tv_sec: i64, tv_nsec: i64) -> Result<SystemTime, io::Error> {
Ok(SystemTime(Timespec::new(tv_sec, tv_nsec)?))
}

pub fn now() -> SystemTime {
let mut time: Timespec = Timespec::zero();
let _ = unsafe { hermit_abi::clock_gettime(CLOCK_REALTIME, &raw mut time.t) };

SystemTime(time)
SystemTime(clock_gettime(CLOCK_REALTIME))
}

pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> {
Expand Down
Loading