1515
1616#include "emscripten_internal.h"
1717
18- weak clock_t __clock () {
19- static thread_local double start = 0 ;
20- if (!start ) {
21- start = emscripten_date_now ();
22- }
23- return (emscripten_date_now () - start ) * (CLOCKS_PER_SEC / 1000 );
24- }
25-
2618weak time_t __time (time_t * t ) {
2719 double ret = emscripten_date_now () / 1000 ;
2820 if (t ) {
@@ -34,48 +26,6 @@ weak time_t __time(time_t *t) {
3426static thread_local bool checked_monotonic = false;
3527static thread_local bool is_monotonic = 0 ;
3628
37- weak int __clock_gettime (clockid_t clk , struct timespec * ts ) {
38- if (!checked_monotonic ) {
39- is_monotonic = _emscripten_get_now_is_monotonic ();
40- checked_monotonic = true;
41- }
42-
43- double now_ms ;
44- if (clk == CLOCK_REALTIME ) {
45- now_ms = emscripten_date_now ();
46- } else if ((clk == CLOCK_MONOTONIC || clk == CLOCK_MONOTONIC_RAW ) && is_monotonic ) {
47- now_ms = emscripten_get_now ();
48- } else {
49- errno = EINVAL ;
50- return -1 ;
51- }
52-
53- long long now_s = now_ms / 1000 ;
54- ts -> tv_sec = now_s ; // seconds
55- ts -> tv_nsec = (now_ms - (now_s * 1000 )) * 1000 * 1000 ; // nanoseconds
56- return 0 ;
57- }
58-
59- weak int __clock_getres (clockid_t clk , struct timespec * ts ) {
60- if (!checked_monotonic ) {
61- is_monotonic = _emscripten_get_now_is_monotonic ();
62- checked_monotonic = true;
63- }
64-
65- double nsec ;
66- if (clk == CLOCK_REALTIME ) {
67- nsec = 1000 * 1000 ; // educated guess that it's milliseconds
68- } else if (clk == CLOCK_MONOTONIC && is_monotonic ) {
69- nsec = emscripten_get_now_res ();
70- } else {
71- errno = EINVAL ;
72- return -1 ;
73- }
74- ts -> tv_sec = (nsec / (1000 * 1000 * 1000 ));
75- ts -> tv_nsec = nsec ;
76- return 0 ;
77- }
78-
7929weak int __gettimeofday (struct timeval * restrict tv , void * restrict tz ) {
8030 double now_ms = emscripten_date_now ();
8131 long long now_s = now_ms / 1000 ;
@@ -90,7 +40,4 @@ weak int dysize(int year) {
9040}
9141
9242weak_alias (__time , time );
93- weak_alias (__clock , clock );
94- weak_alias (__clock_gettime , clock_gettime );
95- weak_alias (__clock_getres , clock_getres );
9643weak_alias (__gettimeofday , gettimeofday );
0 commit comments