Skip to content

Commit ab951b1

Browse files
committed
fixups
1 parent 59928fe commit ab951b1

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

options/ansi/generic/time.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ bool parse_tz(const char *tz, char *tz_name, char *tz_name_dst, size_t tz_name_m
581581
return false;
582582
}
583583

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) {
585585
// POSIX defines :*characters* as a valid but implementation-defined format.
586586
// This was originally introduced as a way to support geographical
587587
// 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
614614
}
615615

616616
mlibc::infoLogger() << "mlibc: reading TZ from " << path << frg::endlog;
617+
file_window window {path};
617618

618619
// TODO(geert): we can probably cache this somehow
619620
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));
621622
tzfile_time.tzh_ttisgmtcnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_ttisgmtcnt);
622623
tzfile_time.tzh_ttisstdcnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_ttisstdcnt);
623624
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
627628

628629
if(tzfile_time.magic[0] != 'T' || tzfile_time.magic[1] != 'Z' || tzfile_time.magic[2] != 'i'
629630
|| 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;
631632
return;
632633
}
633634

634635
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"
636637
<< frg::endlog;
637638
return;
638639
}
@@ -641,18 +642,19 @@ void parse_tzfile(const char *tz, char *tz_name, char *tz_name_dst, size_t tz_na
641642
// TODO: If there is not, we might want to fall back to UTC, no DST (?).
642643
__ensure(tzfile_time.tzh_typecnt);
643644

644-
char *abbrevs = reinterpret_cast<char *>(get_localtime_window()->get()) + sizeof(tzfile)
645+
char *abbrevs = reinterpret_cast<char *>(window.get()) + sizeof(tzfile)
645646
+ tzfile_time.tzh_timecnt * sizeof(int32_t)
646647
+ tzfile_time.tzh_timecnt * sizeof(uint8_t)
647648
+ tzfile_time.tzh_typecnt * sizeof(struct ttinfo);
648649
// start from the last ttinfo entry, this matches the behaviour of glibc and musl
649650
for (int i = tzfile_time.tzh_typecnt; i > 0; i--) {
650651
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)
652653
+ tzfile_time.tzh_timecnt * sizeof(int32_t)
653654
+ tzfile_time.tzh_timecnt * sizeof(uint8_t)
654655
+ i * sizeof(ttinfo), sizeof(ttinfo));
655656
time_info.tt_gmtoff = mlibc::bit_util<uint32_t>::byteswap(time_info.tt_gmtoff);
657+
// TODO: check tz_name_max
656658
if (!time_info.tt_isdst && !tzname[0]) {
657659
tzname[0] = abbrevs + time_info.tt_abbrind;
658660
timezone = -time_info.tt_gmtoff;
@@ -695,7 +697,7 @@ void tzset(void) {
695697
return;
696698
}
697699

698-
parse_tzfile(tz, tz_name, tz_name_dst, tz_name_max);
700+
parse_tzfile(tz, tz_name_max);
699701
}
700702

701703
// POSIX extensions.

0 commit comments

Comments
 (0)