15
15
16
16
// Replaces musl's __tz.c
17
17
18
- __attribute__(( __weak__ )) long timezone = 0 ;
19
- __attribute__(( __weak__ )) int daylight = 0 ;
20
- __attribute__(( __weak__ )) char * tzname [2 ] = { 0 , 0 };
18
+ weak long timezone = 0 ;
19
+ weak int daylight = 0 ;
20
+ weak char * tzname [2 ] = { 0 , 0 };
21
21
22
- void _tzset_js (long * timezone , int * daylight , char * * tzname );
23
- // Declare these functions `int` rather than time_t to avoid int64 at the wasm
24
- // boundary (avoids 64-bit complexity at the boundary when WASM_BIGINT is
25
- // missing).
26
- // TODO(sbc): Covert back to `time_t` before 2038 ...
27
- int _timegm_js (struct tm * tm );
28
- int _mktime_js (struct tm * tm );
29
- void _localtime_js (const time_t * restrict t , struct tm * restrict tm );
30
- void _gmtime_js (const time_t * restrict t , struct tm * restrict tm );
31
22
double emscripten_get_now_res ();
32
23
33
- __attribute__((__weak__ ))
34
- void tzset () {
35
- static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER ;
36
- static _Atomic bool done_init = false;
37
- if (!done_init ) {
38
- pthread_mutex_lock (& lock );
39
- if (!done_init ) {
40
- _tzset_js (& timezone , & daylight , tzname );
41
- done_init = true;
42
- }
43
- pthread_mutex_unlock (& lock );
44
- }
45
- }
46
-
47
- __attribute__((__weak__ ))
48
- time_t timegm (struct tm * tm ) {
49
- tzset ();
50
- return _timegm_js (tm );
51
- }
52
-
53
- __attribute__((__weak__ ))
54
- time_t mktime (struct tm * tm ) {
55
- tzset ();
56
- return _mktime_js (tm );
57
- }
58
-
59
- __attribute__((__weak__ ))
60
- struct tm * __localtime_r (const time_t * restrict t , struct tm * restrict tm ) {
61
- tzset ();
62
- _localtime_js (t , tm );
63
- // __localtime_js sets everything but the tmzone pointer
64
- tm -> __tm_zone = tm -> tm_isdst ? tzname [1 ] :tzname [0 ];
65
- return tm ;
66
- }
67
-
68
- __attribute__((__weak__ ))
69
- struct tm * __gmtime_r (const time_t * restrict t , struct tm * restrict tm ) {
70
- tzset ();
71
- _gmtime_js (t , tm );
72
- tm -> tm_isdst = 0 ;
73
- tm -> __tm_gmtoff = 0 ;
74
- tm -> __tm_zone = "GMT" ;
75
- return tm ;
76
- }
77
-
78
- __attribute__((__weak__ ))
79
- clock_t __clock () {
24
+ weak clock_t __clock () {
80
25
static thread_local double start = 0 ;
81
26
if (!start ) {
82
27
start = emscripten_date_now ();
83
28
}
84
29
return (emscripten_date_now () - start ) * (CLOCKS_PER_SEC / 1000 );
85
30
}
86
31
87
- __attribute__((__weak__ ))
88
- time_t __time (time_t * t ) {
32
+ weak time_t __time (time_t * t ) {
89
33
double ret = emscripten_date_now () / 1000 ;
90
34
if (t ) {
91
35
* t = ret ;
@@ -97,8 +41,7 @@ extern bool _emscripten_get_now_is_monotonic();
97
41
static thread_local bool checked_monotonic = false;
98
42
static thread_local bool is_monotonic = 0 ;
99
43
100
- __attribute__((__weak__ ))
101
- int __clock_gettime (clockid_t clk , struct timespec * ts ) {
44
+ weak int __clock_gettime (clockid_t clk , struct timespec * ts ) {
102
45
if (!checked_monotonic ) {
103
46
is_monotonic = _emscripten_get_now_is_monotonic ();
104
47
checked_monotonic = true;
@@ -120,8 +63,7 @@ int __clock_gettime(clockid_t clk, struct timespec *ts) {
120
63
return 0 ;
121
64
}
122
65
123
- __attribute__((__weak__ ))
124
- int __clock_getres (clockid_t clk , struct timespec * ts ) {
66
+ weak int __clock_getres (clockid_t clk , struct timespec * ts ) {
125
67
if (!checked_monotonic ) {
126
68
is_monotonic = _emscripten_get_now_is_monotonic ();
127
69
checked_monotonic = true;
@@ -141,23 +83,19 @@ int __clock_getres(clockid_t clk, struct timespec *ts) {
141
83
return 0 ;
142
84
}
143
85
144
- __attribute__((__weak__ ))
145
- int __gettimeofday (struct timeval * restrict tv , void * restrict tz ) {
86
+ weak int __gettimeofday (struct timeval * restrict tv , void * restrict tz ) {
146
87
double now_ms = emscripten_date_now ();
147
88
long long now_s = now_ms / 1000 ;
148
89
tv -> tv_sec = now_s ; // seconds
149
90
tv -> tv_usec = (now_ms - (now_s * 1000 )) * 1000 ; // nicroseconds
150
91
return 0 ;
151
92
}
152
93
153
- __attribute__((__weak__ ))
154
- int dysize (int year ) {
94
+ weak int dysize (int year ) {
155
95
int leap = ((year % 4 == 0 ) && ((year % 100 != 0 ) || (year % 400 == 0 )));
156
96
return leap ? 366 : 365 ;
157
97
}
158
98
159
- weak_alias (__gmtime_r , gmtime_r );
160
- weak_alias (__localtime_r , localtime_r );
161
99
weak_alias (__time , time );
162
100
weak_alias (__clock , clock );
163
101
weak_alias (__clock_gettime , clock_gettime );
0 commit comments