Skip to content

[vm/runtime] Call tzset() before localtime_r(). #61302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions runtime/vm/os_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ intptr_t OS::ProcessId() {
static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) {
time_t seconds = static_cast<time_t>(seconds_since_epoch);
if (seconds != seconds_since_epoch) return false;
// No need to call tzset() before localtime_r() because bionic
// will handle timezone changes for us (starting from Android O).
// See https://android.googlesource.com/platform/bionic/+/ea87716696bf635706b6f3fa56b8a145add83aff
struct tm* error_code = localtime_r(&seconds, tm_result);
return error_code != nullptr;
}
Expand Down
1 change: 1 addition & 0 deletions runtime/vm/os_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ intptr_t OS::ProcessId() {
static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) {
time_t seconds = static_cast<time_t>(seconds_since_epoch);
if (seconds != seconds_since_epoch) return false;
tzset(); // Not guaranteed by POSIX to be called by `localtime_r`.
struct tm* error_code = localtime_r(&seconds, tm_result);
return error_code != nullptr;
}
Expand Down