Skip to content

Commit bbbb5d8

Browse files
committed
Enable clock_gettime on wasi
1 parent fc22d2c commit bbbb5d8

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/wasi.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ pub enum __locale_struct {}
5151

5252
pub type locale_t = *mut __locale_struct;
5353

54+
s_paren! {
55+
// in wasi-libc clockid_t is const struct __clockid* (where __clockid is an opaque struct),
56+
// but that's an implementation detail that we don't want to have to deal with
57+
#[repr(transparent)]
58+
pub struct clockid_t(*const u8);
59+
}
60+
61+
unsafe impl Send for clockid_t {}
62+
unsafe impl Sync for clockid_t {}
63+
5464
s! {
5565
#[repr(align(8))]
5666
pub struct fpos_t {
@@ -342,6 +352,11 @@ pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE;
342352
pub const _SC_IOV_MAX: c_int = 60;
343353
pub const _SC_SYMLOOP_MAX: c_int = 173;
344354

355+
pub static CLOCK_MONOTONIC: clockid_t = unsafe { clockid_t(&_CLOCK_MONOTONIC) };
356+
pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t = unsafe { clockid_t(&_CLOCK_PROCESS_CPUTIME_ID) };
357+
pub static CLOCK_REALTIME: clockid_t = unsafe { clockid_t(&_CLOCK_REALTIME) };
358+
pub static CLOCK_THREAD_CPUTIME_ID: clockid_t = unsafe { clockid_t(&_CLOCK_THREAD_CPUTIME_ID) };
359+
345360
#[cfg_attr(
346361
feature = "rustc-dep-of-std",
347362
link(name = "c", kind = "static", cfg(target_feature = "crt-static"))
@@ -417,15 +432,14 @@ extern "C" {
417432
pub fn asctime_r(a: *const tm, b: *mut c_char) -> *mut c_char;
418433
pub fn ctime_r(a: *const time_t, b: *mut c_char) -> *mut c_char;
419434

435+
static _CLOCK_MONOTONIC: u8;
436+
static _CLOCK_PROCESS_CPUTIME_ID: u8;
437+
static _CLOCK_REALTIME: u8;
438+
static _CLOCK_THREAD_CPUTIME_ID: u8;
420439
pub fn nanosleep(a: *const timespec, b: *mut timespec) -> c_int;
421-
// pub fn clock_getres(a: clockid_t, b: *mut timespec) -> c_int;
422-
// pub fn clock_gettime(a: clockid_t, b: *mut timespec) -> c_int;
423-
// pub fn clock_nanosleep(
424-
// a: clockid_t,
425-
// a2: c_int,
426-
// b: *const timespec,
427-
// c: *mut timespec,
428-
// ) -> c_int;
440+
pub fn clock_getres(a: clockid_t, b: *mut timespec) -> c_int;
441+
pub fn clock_gettime(a: clockid_t, b: *mut timespec) -> c_int;
442+
pub fn clock_nanosleep(a: clockid_t, a2: c_int, b: *const timespec, c: *mut timespec) -> c_int;
429443

430444
pub fn isalnum(c: c_int) -> c_int;
431445
pub fn isalpha(c: c_int) -> c_int;

0 commit comments

Comments
 (0)