File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,11 @@ clock_t times(struct tms *buffer) {
21
21
.tms_cutime = 0
22
22
};
23
23
24
+ #ifdef __wasilibc_use_wasip2
25
+ monotonic_clock_instant_t realtime = monotonic_clock_now ();
26
+ #else
24
27
__wasi_timestamp_t realtime = 0 ;
25
28
(void )__wasi_clock_time_get (__WASI_CLOCKID_MONOTONIC , 0 , & realtime );
29
+ #endif
26
30
return realtime ;
27
31
}
Original file line number Diff line number Diff line change 8
8
#include <time.h>
9
9
10
10
time_t time (time_t * tloc ) {
11
+ #ifdef __wasilibc_use_wasip2
11
12
__wasi_timestamp_t ts = 0 ;
12
13
(void )__wasi_clock_time_get (__WASI_CLOCKID_REALTIME , NSEC_PER_SEC , & ts );
14
+ #else
15
+ monotonic_clock_instant_t ts = monotonic_clock_now ();
16
+ #endif
13
17
if (tloc != NULL )
14
18
* tloc = ts / NSEC_PER_SEC ;
15
19
return ts / NSEC_PER_SEC ;
Original file line number Diff line number Diff line change
1
+ //! add-flags.py(CFLAGS): -D_WASI_EMULATED_PROCESS_CLOCKS
2
+ //! add-flags.py(LDFLAGS): -lwasi-emulated-process-clocks
3
+ #include <stdlib.h>
4
+ #include <stdio.h>
5
+ #include <time.h>
6
+ #include <string.h>
7
+ #include <errno.h>
8
+ #include <sys/times.h>
9
+ #include "test.h"
10
+
11
+ #define TEST (c , ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0))
12
+
13
+ int main (void )
14
+ {
15
+ time_t t ;
16
+ struct tms buffer ;
17
+
18
+ clock_t result = times (& buffer );
19
+ TEST (result > 0 );
20
+ TEST (buffer .tms_utime > 0 );
21
+ TEST (buffer .tms_cutime == 0 ); // always 0 under WASI
22
+
23
+ time_t t1 = time (& t );
24
+ TEST (t == t1 );
25
+ TEST (t > 0 );
26
+
27
+ return t_status ;
28
+ }
You can’t perform that action at this time.
0 commit comments