mirror of
https://github.com/openharmony/third_party_rust_rustix.git
synced 2026-07-01 20:54:01 -04:00
Add support for timespec, UTIME_NOW, UTIME_OMIT on wasm32-wasi.
This commit is contained in:
+5
-3
@@ -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
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user