@@ -28,8 +28,10 @@ const char __utc[] = "UTC";
28
28
static int dst_off ;
29
29
static int r0 [5 ], r1 [5 ];
30
30
31
+ #ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
31
32
static const unsigned char * zi , * trans , * index , * types , * abbrevs , * abbrevs_end ;
32
33
static size_t map_size ;
34
+ #endif
33
35
34
36
static char old_tz_buf [32 ];
35
37
static char * old_tz = old_tz_buf ;
@@ -104,6 +106,7 @@ static void getname(char *d, const char **p)
104
106
d [i < TZNAME_MAX ?i :TZNAME_MAX ] = 0 ;
105
107
}
106
108
109
+ #ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
107
110
#define VEC (...) ((const unsigned char[]){__VA_ARGS__})
108
111
109
112
static uint32_t zi_read32 (const unsigned char * z )
@@ -121,25 +124,37 @@ static size_t zi_dotprod(const unsigned char *z, const unsigned char *v, size_t
121
124
}
122
125
return y ;
123
126
}
127
+ #endif
124
128
125
129
static void do_tzset ()
126
130
{
131
+ #ifdef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
132
+ const char * s ;
133
+ size_t i ;
134
+ #else
127
135
char buf [NAME_MAX + 25 ], * pathname = buf + 24 ;
128
136
const char * try , * s , * p ;
129
137
const unsigned char * map = 0 ;
130
138
size_t i ;
131
139
static const char search [] =
132
140
"/usr/share/zoneinfo/\0/share/zoneinfo/\0/etc/zoneinfo/\0" ;
141
+ #endif
133
142
134
143
s = getenv ("TZ" );
144
+ #ifdef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
145
+ if (!s || !* s ) s = __utc ;
146
+ #else
135
147
if (!s ) s = "/etc/localtime" ;
136
148
if (!* s ) s = __utc ;
149
+ #endif
137
150
138
151
if (old_tz && !strcmp (s , old_tz )) return ;
139
152
140
153
for (i = 0 ; i < 5 ; i ++ ) r0 [i ] = r1 [i ] = 0 ;
141
154
155
+ #ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
142
156
if (zi ) __munmap ((void * )zi , map_size );
157
+ #endif
143
158
144
159
/* Cache the old value of TZ to check if it has changed. Avoid
145
160
* free so as not to pull it into static programs. Growth
@@ -154,6 +169,7 @@ static void do_tzset()
154
169
}
155
170
if (old_tz ) memcpy (old_tz , s , i + 1 );
156
171
172
+ #ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
157
173
/* Non-suid can use an absolute tzfile pathname or a relative
158
174
* pathame beginning with "."; in secure mode, only the
159
175
* standard path will be searched. */
@@ -225,6 +241,8 @@ static void do_tzset()
225
241
}
226
242
227
243
if (!s ) s = __utc ;
244
+ #endif
245
+
228
246
getname (std_name , & s );
229
247
__tzname [0 ] = std_name ;
230
248
__timezone = getoff (& s );
@@ -245,6 +263,7 @@ static void do_tzset()
245
263
if (* s == ',' ) s ++ , getrule (& s , r1 );
246
264
}
247
265
266
+ #ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
248
267
/* Search zoneinfo rules to find the one that applies to the given time,
249
268
* and determine alternate opposite-DST-status rule that may be needed. */
250
269
@@ -312,6 +331,7 @@ static size_t scan_trans(long long t, int local, size_t *alt)
312
331
313
332
return index [a ];
314
333
}
334
+ #endif
315
335
316
336
static int days_in_month (int m , int is_leap )
317
337
{
@@ -358,6 +378,7 @@ void __secs_to_zone(long long t, int local, int *isdst, long *offset, long *oppo
358
378
359
379
do_tzset ();
360
380
381
+ #ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
361
382
if (zi ) {
362
383
size_t alt , i = scan_trans (t , local , & alt );
363
384
if (i != -1 ) {
@@ -369,6 +390,7 @@ void __secs_to_zone(long long t, int local, int *isdst, long *offset, long *oppo
369
390
return ;
370
391
}
371
392
}
393
+ #endif
372
394
373
395
if (!__daylight ) goto std ;
374
396
@@ -421,8 +443,12 @@ const char *__tm_to_tzname(const struct tm *tm)
421
443
const void * p = tm -> __tm_zone ;
422
444
LOCK (lock );
423
445
do_tzset ();
446
+ #ifdef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
447
+ if (p != __utc && p != __tzname [0 ] && p != __tzname [1 ])
448
+ #else
424
449
if (p != __utc && p != __tzname [0 ] && p != __tzname [1 ] &&
425
450
(!zi || (uintptr_t )p - (uintptr_t )abbrevs >= abbrevs_end - abbrevs ))
451
+ #endif
426
452
p = "" ;
427
453
UNLOCK (lock );
428
454
return p ;
0 commit comments