diff --git a/src/time/clock.rs b/src/time/clock.rs index f778229f..399e95e9 100644 --- a/src/time/clock.rs +++ b/src/time/clock.rs @@ -1,10 +1,10 @@ -use crate::zero_ok; -use std::mem::MaybeUninit; +#[cfg(not(target_os = "wasi"))] +use {crate::zero_ok, std::mem::MaybeUninit}; pub use libc::{timespec, UTIME_NOW, UTIME_OMIT}; /// `clockid_t` -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "wasi")))] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] #[repr(i32)] pub enum ClockId { @@ -42,6 +42,7 @@ pub enum ClockId { } /// `clock_getres(id)` +#[cfg(not(target_os = "wasi"))] pub fn clock_getres(id: ClockId) -> timespec { let mut timespec = MaybeUninit::::uninit(); zero_ok(unsafe { libc::clock_getres(id as libc::clockid_t, timespec.as_mut_ptr()) }).unwrap(); @@ -49,6 +50,7 @@ pub fn clock_getres(id: ClockId) -> timespec { } /// `clock_gettime(id)` +#[cfg(not(target_os = "wasi"))] pub fn clock_gettime(id: ClockId) -> timespec { let mut timespec = MaybeUninit::::uninit(); zero_ok(unsafe { libc::clock_gettime(id as libc::clockid_t, timespec.as_mut_ptr()) }).unwrap(); diff --git a/src/time/mod.rs b/src/time/mod.rs index f00b1dbe..6898a75e 100644 --- a/src/time/mod.rs +++ b/src/time/mod.rs @@ -1,8 +1,12 @@ //! Time-related operations. -#[cfg(not(any(target_os = "wasi", target_os = "redox")))] // not implemented in libc for WASI yet +#[cfg(not(target_os = "redox"))] mod clock; +// TODO: Convert WASI'S clock APIs to use handles rather than ambient +// clock identifiers, update `wasi-libc`, and then add support in `posish`. #[cfg(not(any(target_os = "wasi", target_os = "redox")))] -// not implemented in libc for WASI yet -pub use clock::{clock_getres, clock_gettime, timespec, ClockId, UTIME_NOW, UTIME_OMIT}; +pub use clock::{clock_getres, clock_gettime, ClockId}; + +#[cfg(not(target_os = "redox"))] +pub use clock::{timespec, UTIME_NOW, UTIME_OMIT};