Skip to content

Commit daf73df

Browse files
committed
Ignore default timezone from filesystem
Moreover, it never worked because it uses __map_file, which is currently no-op.
1 parent 07e894f commit daf73df

File tree

1 file changed

+26
-0
lines changed
  • system/lib/libc/musl/src/time

1 file changed

+26
-0
lines changed

system/lib/libc/musl/src/time/__tz.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ const char __utc[] = "UTC";
2828
static int dst_off;
2929
static int r0[5], r1[5];
3030

31+
#ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
3132
static const unsigned char *zi, *trans, *index, *types, *abbrevs, *abbrevs_end;
3233
static size_t map_size;
34+
#endif
3335

3436
static char old_tz_buf[32];
3537
static char *old_tz = old_tz_buf;
@@ -104,6 +106,7 @@ static void getname(char *d, const char **p)
104106
d[i<TZNAME_MAX?i:TZNAME_MAX] = 0;
105107
}
106108

109+
#ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
107110
#define VEC(...) ((const unsigned char[]){__VA_ARGS__})
108111

109112
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
121124
}
122125
return y;
123126
}
127+
#endif
124128

125129
static void do_tzset()
126130
{
131+
#ifdef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
132+
const char *s;
133+
size_t i;
134+
#else
127135
char buf[NAME_MAX+25], *pathname=buf+24;
128136
const char *try, *s, *p;
129137
const unsigned char *map = 0;
130138
size_t i;
131139
static const char search[] =
132140
"/usr/share/zoneinfo/\0/share/zoneinfo/\0/etc/zoneinfo/\0";
141+
#endif
133142

134143
s = getenv("TZ");
144+
#ifdef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
145+
if (!s || !*s) s = __utc;
146+
#else
135147
if (!s) s = "/etc/localtime";
136148
if (!*s) s = __utc;
149+
#endif
137150

138151
if (old_tz && !strcmp(s, old_tz)) return;
139152

140153
for (i=0; i<5; i++) r0[i] = r1[i] = 0;
141154

155+
#ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
142156
if (zi) __munmap((void *)zi, map_size);
157+
#endif
143158

144159
/* Cache the old value of TZ to check if it has changed. Avoid
145160
* free so as not to pull it into static programs. Growth
@@ -154,6 +169,7 @@ static void do_tzset()
154169
}
155170
if (old_tz) memcpy(old_tz, s, i+1);
156171

172+
#ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
157173
/* Non-suid can use an absolute tzfile pathname or a relative
158174
* pathame beginning with "."; in secure mode, only the
159175
* standard path will be searched. */
@@ -225,6 +241,8 @@ static void do_tzset()
225241
}
226242

227243
if (!s) s = __utc;
244+
#endif
245+
228246
getname(std_name, &s);
229247
__tzname[0] = std_name;
230248
__timezone = getoff(&s);
@@ -245,6 +263,7 @@ static void do_tzset()
245263
if (*s == ',') s++, getrule(&s, r1);
246264
}
247265

266+
#ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
248267
/* Search zoneinfo rules to find the one that applies to the given time,
249268
* and determine alternate opposite-DST-status rule that may be needed. */
250269

@@ -312,6 +331,7 @@ static size_t scan_trans(long long t, int local, size_t *alt)
312331

313332
return index[a];
314333
}
334+
#endif
315335

316336
static int days_in_month(int m, int is_leap)
317337
{
@@ -358,6 +378,7 @@ void __secs_to_zone(long long t, int local, int *isdst, long *offset, long *oppo
358378

359379
do_tzset();
360380

381+
#ifndef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
361382
if (zi) {
362383
size_t alt, i = scan_trans(t, local, &alt);
363384
if (i != -1) {
@@ -369,6 +390,7 @@ void __secs_to_zone(long long t, int local, int *isdst, long *offset, long *oppo
369390
return;
370391
}
371392
}
393+
#endif
372394

373395
if (!__daylight) goto std;
374396

@@ -421,8 +443,12 @@ const char *__tm_to_tzname(const struct tm *tm)
421443
const void *p = tm->__tm_zone;
422444
LOCK(lock);
423445
do_tzset();
446+
#ifdef __EMSCRIPTEN__ // XXX Emscripten ignore default timezone from filesystem
447+
if (p != __utc && p != __tzname[0] && p != __tzname[1])
448+
#else
424449
if (p != __utc && p != __tzname[0] && p != __tzname[1] &&
425450
(!zi || (uintptr_t)p-(uintptr_t)abbrevs >= abbrevs_end - abbrevs))
451+
#endif
426452
p = "";
427453
UNLOCK(lock);
428454
return p;

0 commit comments

Comments
 (0)