@@ -581,7 +581,7 @@ bool parse_tz(const char *tz, char *tz_name, char *tz_name_dst, size_t tz_name_m
581
581
return false ;
582
582
}
583
583
584
- void parse_tzfile (const char *tz, char *tz_name, char *tz_name_dst, size_t tz_name_max) {
584
+ void parse_tzfile (const char *tz, size_t tz_name_max) {
585
585
// POSIX defines :*characters* as a valid but implementation-defined format.
586
586
// This was originally introduced as a way to support geographical
587
587
// timezones in the format :Area/Location, but the colon was dropped in POSIX.
@@ -614,10 +614,11 @@ void parse_tzfile(const char *tz, char *tz_name, char *tz_name_dst, size_t tz_na
614
614
}
615
615
616
616
mlibc::infoLogger () << " mlibc: reading TZ from " << path << frg::endlog;
617
+ file_window window {path};
617
618
618
619
// TODO(geert): we can probably cache this somehow
619
620
tzfile tzfile_time;
620
- memcpy (&tzfile_time, reinterpret_cast <char *>(get_localtime_window ()-> get ()), sizeof (tzfile));
621
+ memcpy (&tzfile_time, reinterpret_cast <char *>(window. get ()), sizeof (tzfile));
621
622
tzfile_time.tzh_ttisgmtcnt = mlibc::bit_util<uint32_t >::byteswap (tzfile_time.tzh_ttisgmtcnt );
622
623
tzfile_time.tzh_ttisstdcnt = mlibc::bit_util<uint32_t >::byteswap (tzfile_time.tzh_ttisstdcnt );
623
624
tzfile_time.tzh_leapcnt = mlibc::bit_util<uint32_t >::byteswap (tzfile_time.tzh_leapcnt );
@@ -627,12 +628,12 @@ void parse_tzfile(const char *tz, char *tz_name, char *tz_name_dst, size_t tz_na
627
628
628
629
if (tzfile_time.magic [0 ] != ' T' || tzfile_time.magic [1 ] != ' Z' || tzfile_time.magic [2 ] != ' i'
629
630
|| tzfile_time.magic [3 ] != ' f' ) {
630
- mlibc::infoLogger () << " mlibc: /etc/localtime is not a valid TZinfo file" << frg::endlog;
631
+ mlibc::infoLogger () << " mlibc: " << path << " is not a valid TZinfo file" << frg::endlog;
631
632
return ;
632
633
}
633
634
634
635
if (tzfile_time.version != ' \0 ' && tzfile_time.version != ' 2' && tzfile_time.version != ' 3' ) {
635
- mlibc::infoLogger () << " mlibc: /etc/localtime has an invalid TZinfo version"
636
+ mlibc::infoLogger () << " mlibc: " << path << " has an invalid TZinfo version"
636
637
<< frg::endlog;
637
638
return ;
638
639
}
@@ -641,18 +642,19 @@ void parse_tzfile(const char *tz, char *tz_name, char *tz_name_dst, size_t tz_na
641
642
// TODO: If there is not, we might want to fall back to UTC, no DST (?).
642
643
__ensure (tzfile_time.tzh_typecnt );
643
644
644
- char *abbrevs = reinterpret_cast <char *>(get_localtime_window ()-> get ()) + sizeof (tzfile)
645
+ char *abbrevs = reinterpret_cast <char *>(window. get ()) + sizeof (tzfile)
645
646
+ tzfile_time.tzh_timecnt * sizeof (int32_t )
646
647
+ tzfile_time.tzh_timecnt * sizeof (uint8_t )
647
648
+ tzfile_time.tzh_typecnt * sizeof (struct ttinfo );
648
649
// start from the last ttinfo entry, this matches the behaviour of glibc and musl
649
650
for (int i = tzfile_time.tzh_typecnt ; i > 0 ; i--) {
650
651
ttinfo time_info;
651
- memcpy (&time_info, reinterpret_cast <char *>(get_localtime_window ()-> get ()) + sizeof (tzfile)
652
+ memcpy (&time_info, reinterpret_cast <char *>(window. get ()) + sizeof (tzfile)
652
653
+ tzfile_time.tzh_timecnt * sizeof (int32_t )
653
654
+ tzfile_time.tzh_timecnt * sizeof (uint8_t )
654
655
+ i * sizeof (ttinfo), sizeof (ttinfo));
655
656
time_info.tt_gmtoff = mlibc::bit_util<uint32_t >::byteswap (time_info.tt_gmtoff );
657
+ // TODO: check tz_name_max
656
658
if (!time_info.tt_isdst && !tzname[0 ]) {
657
659
tzname[0 ] = abbrevs + time_info.tt_abbrind ;
658
660
timezone = -time_info.tt_gmtoff ;
@@ -695,7 +697,7 @@ void tzset(void) {
695
697
return ;
696
698
}
697
699
698
- parse_tzfile (tz, tz_name, tz_name_dst, tz_name_max);
700
+ parse_tzfile (tz, tz_name_max);
699
701
}
700
702
701
703
// POSIX extensions.
0 commit comments