Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/libc/mktime.c
6162 views
1
/*
2
* Copyright 2023 The Emscripten Authors. All rights reserved.
3
* Emscripten is available under two separate licenses, the MIT license and the
4
* University of Illinois/NCSA Open Source License. Both these licenses can be
5
* found in the LICENSE file.
6
*/
7
#include <errno.h>
8
#include <time.h>
9
10
#include "emscripten_internal.h"
11
12
weak time_t timegm(struct tm *tm) {
13
tzset();
14
return _timegm_js(tm);
15
}
16
17
weak time_t mktime(struct tm *tm) {
18
tzset();
19
time_t t = _mktime_js(tm);
20
if (t == -1) {
21
errno = EOVERFLOW;
22
}
23
return t;
24
}
25
26
weak struct tm *__localtime_r(const time_t *restrict t, struct tm *restrict tm) {
27
tzset();
28
_localtime_js(*t, tm);
29
// __localtime_js sets everything but the tmzone pointer
30
tm->__tm_zone = tm->tm_isdst ? tzname[1] :tzname[0];
31
return tm;
32
}
33
34
weak struct tm *__gmtime_r(const time_t *restrict t, struct tm *restrict tm) {
35
tzset();
36
_gmtime_js(*t, tm);
37
tm->tm_isdst = 0;
38
tm->__tm_gmtoff = 0;
39
tm->__tm_zone = "GMT";
40
return tm;
41
}
42
43
weak_alias(__gmtime_r, gmtime_r);
44
weak_alias(__localtime_r, localtime_r);
45
46