Skip to content

Commit 7e9b3ba

Browse files
authored
Add some comments to emscripten_time.c. NFC (emscripten-core#26285)
As an internal detail we also skip defining the `__` prefixed versions, since they are not used anywhere and not part of the musl impl either. Landing this instead of emscripten-core#26284
1 parent 90bc49b commit 7e9b3ba

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

system/lib/libc/emscripten_time.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,32 @@
55
* found in the LICENSE file.
66
*/
77

8-
#include <emscripten/html5.h> // For `emscripten_data_now`
8+
#include <emscripten/html5.h> // For `emscripten_date_now`
99
#include <time.h>
1010
#include <sys/time.h>
1111

12-
#include "libc.h" // For `weak`/`weak_alias`
12+
#include "libc.h" // For `weak`
1313

14-
15-
time_t __time(time_t *t) {
14+
// emscripten-specific implementations. These works out slightly smaller than
15+
// musl's since it they avoid depending on the more general clock_gettime.
16+
weak time_t time(time_t *t) {
1617
double ret = emscripten_date_now() / 1000;
1718
if (t) {
1819
*t = ret;
1920
}
2021
return ret;
2122
}
2223

23-
int __gettimeofday(struct timeval *restrict tv, void *restrict tz) {
24+
weak int gettimeofday(struct timeval *restrict tv, void *restrict tz) {
2425
double now_ms = emscripten_date_now();
2526
long long now_s = now_ms / 1000;
2627
tv->tv_sec = now_s; // seconds
2728
tv->tv_usec = (now_ms - (now_s * 1000)) * 1000; // microseconds
2829
return 0;
2930
}
3031

32+
// Non-standard glibc/BSD extension that is not implemented by musl
3133
weak int dysize(int year) {
3234
int leap = ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)));
3335
return leap ? 366 : 365;
3436
}
35-
36-
weak_alias(__time, time);
37-
weak_alias(__gettimeofday, gettimeofday);

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"a.out.js": 244691,
3-
"a.out.nodebug.wasm": 577706,
4-
"total": 822397,
3+
"a.out.nodebug.wasm": 577678,
4+
"total": 822369,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",
@@ -1708,7 +1708,6 @@
17081708
"__getf2",
17091709
"__getitimer",
17101710
"__gettextdomain",
1711-
"__gettimeofday",
17121711
"__gnu_f2h_ieee",
17131712
"__gnu_h2f_ieee",
17141713
"__gtdf2",
@@ -1909,7 +1908,6 @@
19091908
"__syscall_wait4",
19101909
"__sysv_signal",
19111910
"__threwValue",
1912-
"__time",
19131911
"__timezone",
19141912
"__tolower_l",
19151913
"__toupper_l",
@@ -3575,7 +3573,6 @@
35753573
"$__getopt_long_core",
35763574
"$__getopt_msg",
35773575
"$__gettextdomain",
3578-
"$__gettimeofday",
35793576
"$__gmtime_r",
35803577
"$__gnu_f2h_ieee",
35813578
"$__gnu_h2f_ieee",
@@ -3770,7 +3767,6 @@
37703767
"$__tan",
37713768
"$__tandf",
37723769
"$__tanl",
3773-
"$__time",
37743770
"$__tolower_l",
37753771
"$__toread",
37763772
"$__toupper_l",
@@ -4323,6 +4319,7 @@
43234319
"$getsubopt",
43244320
"$gettext",
43254321
"$gettid",
4322+
"$gettimeofday",
43264323
"$getw",
43274324
"$getwc",
43284325
"$getwchar",
@@ -4884,6 +4881,7 @@
48844881
"$thrd_exit",
48854882
"$thrd_join",
48864883
"$thrd_sleep",
4884+
"$time",
48874885
"$timegm",
48884886
"$times",
48894887
"$timespec_get",

0 commit comments

Comments
 (0)