1515
1616// Replaces musl's __tz.c
1717
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 };
2121
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 );
3122double emscripten_get_now_res ();
3223
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 () {
8025 static thread_local double start = 0 ;
8126 if (!start ) {
8227 start = emscripten_date_now ();
8328 }
8429 return (emscripten_date_now () - start ) * (CLOCKS_PER_SEC / 1000 );
8530}
8631
87- __attribute__((__weak__ ))
88- time_t __time (time_t * t ) {
32+ weak time_t __time (time_t * t ) {
8933 double ret = emscripten_date_now () / 1000 ;
9034 if (t ) {
9135 * t = ret ;
@@ -97,8 +41,7 @@ extern bool _emscripten_get_now_is_monotonic();
9741static thread_local bool checked_monotonic = false;
9842static thread_local bool is_monotonic = 0 ;
9943
100- __attribute__((__weak__ ))
101- int __clock_gettime (clockid_t clk , struct timespec * ts ) {
44+ weak int __clock_gettime (clockid_t clk , struct timespec * ts ) {
10245 if (!checked_monotonic ) {
10346 is_monotonic = _emscripten_get_now_is_monotonic ();
10447 checked_monotonic = true;
@@ -120,8 +63,7 @@ int __clock_gettime(clockid_t clk, struct timespec *ts) {
12063 return 0 ;
12164}
12265
123- __attribute__((__weak__ ))
124- int __clock_getres (clockid_t clk , struct timespec * ts ) {
66+ weak int __clock_getres (clockid_t clk , struct timespec * ts ) {
12567 if (!checked_monotonic ) {
12668 is_monotonic = _emscripten_get_now_is_monotonic ();
12769 checked_monotonic = true;
@@ -141,23 +83,19 @@ int __clock_getres(clockid_t clk, struct timespec *ts) {
14183 return 0 ;
14284}
14385
144- __attribute__((__weak__ ))
145- int __gettimeofday (struct timeval * restrict tv , void * restrict tz ) {
86+ weak int __gettimeofday (struct timeval * restrict tv , void * restrict tz ) {
14687 double now_ms = emscripten_date_now ();
14788 long long now_s = now_ms / 1000 ;
14889 tv -> tv_sec = now_s ; // seconds
14990 tv -> tv_usec = (now_ms - (now_s * 1000 )) * 1000 ; // nicroseconds
15091 return 0 ;
15192}
15293
153- __attribute__((__weak__ ))
154- int dysize (int year ) {
94+ weak int dysize (int year ) {
15595 int leap = ((year % 4 == 0 ) && ((year % 100 != 0 ) || (year % 400 == 0 )));
15696 return leap ? 366 : 365 ;
15797}
15898
159- weak_alias (__gmtime_r , gmtime_r );
160- weak_alias (__localtime_r , localtime_r );
16199weak_alias (__time , time );
162100weak_alias (__clock , clock );
163101weak_alias (__clock_gettime , clock_gettime );
0 commit comments