Add support for timespec, UTIME_NOW, UTIME_OMIT on wasm32-wasi.

This commit is contained in:
Dan Gohman
2020-10-08 06:21:19 -07:00
parent 1b1ebd2d37
commit c9d8a73367
2 changed files with 12 additions and 6 deletions
+5 -3
View File
@@ -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::<timespec>::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::<timespec>::uninit();
zero_ok(unsafe { libc::clock_gettime(id as libc::clockid_t, timespec.as_mut_ptr()) }).unwrap();
+7 -3
View File
@@ -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};