Skip to content

Commit eed7f7e

Browse files
JesseRiemensCommit Queue
authored andcommitted
[vm/runtime] Call tzset() before localtime_r().
Closes #61302 GitOrigin-RevId: 5d29733 Change-Id: I74be3fa338aeab0e83d571877f42ac9f80dc89de Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444983 Commit-Queue: Slava Egorov <[email protected]> Reviewed-by: Slava Egorov <[email protected]>
1 parent 9cf56fb commit eed7f7e

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

runtime/vm/os_android.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ intptr_t OS::ProcessId() {
102102
static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) {
103103
time_t seconds = static_cast<time_t>(seconds_since_epoch);
104104
if (seconds != seconds_since_epoch) return false;
105+
// No need to call tzset() before localtime_r() because bionic
106+
// will handle timezone changes for us (starting from Android O).
107+
// See https://android.googlesource.com/platform/bionic/+/ea87716696bf635706b6f3fa56b8a145add83aff
105108
struct tm* error_code = localtime_r(&seconds, tm_result);
106109
return error_code != nullptr;
107110
}

runtime/vm/os_linux.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ intptr_t OS::ProcessId() {
418418
static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) {
419419
time_t seconds = static_cast<time_t>(seconds_since_epoch);
420420
if (seconds != seconds_since_epoch) return false;
421+
tzset(); // Not guaranteed by POSIX to be called by `localtime_r`.
421422
struct tm* error_code = localtime_r(&seconds, tm_result);
422423
return error_code != nullptr;
423424
}

0 commit comments

Comments
 (0)