musl: read the timezone from /etc/TZ
[openwrt/openwrt.git] / toolchain / musl / patches / 110-read_timezone_from_fs.patch
1 --- a/src/time/__tz.c
2 +++ b/src/time/__tz.c
3 @@ -23,6 +23,9 @@ static int r0[5], r1[5];
4 static const unsigned char *zi, *trans, *index, *types, *abbrevs, *abbrevs_end;
5 static size_t map_size;
6
7 +static const char *tzfile;
8 +static size_t tzfile_size;
9 +
10 static char old_tz_buf[32];
11 static char *old_tz = old_tz_buf;
12 static size_t old_tz_size = sizeof old_tz_buf;
13 @@ -125,6 +128,15 @@ static void do_tzset()
14 "/usr/share/zoneinfo/\0/share/zoneinfo/\0/etc/zoneinfo/\0";
15
16 s = getenv("TZ");
17 +
18 + /* if TZ is empty try to read it from /etc/TZ */
19 + if (!s || !*s) {
20 + if (tzfile)
21 + __munmap((void*)tzfile, tzfile_size);
22 +
23 + s = tzfile = (void *)__map_file("/etc/TZ", &tzfile_size);
24 + }
25 +
26 if (!s || !*s) s = "/etc/localtime";
27
28 if (old_tz && !strcmp(s, old_tz)) return;