From 703ec474f5349d6790a71e6805c3314ead276784 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 29 Apr 2021 00:07:14 +0300 Subject: [PATCH] Fixup for sys_time_get_timezone (3rd path) Also simplify Linux path a bit. --- rpcs3/Emu/Cell/lv2/sys_time.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_time.cpp b/rpcs3/Emu/Cell/lv2/sys_time.cpp index 450ed78e62..93199296ae 100644 --- a/rpcs3/Emu/Cell/lv2/sys_time.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_time.cpp @@ -218,11 +218,8 @@ error_code sys_time_get_timezone(vm::ptr timezone, vm::ptr summertime) } } #elif __linux__ - tzset(); - *timezone = ::narrow(-::timezone / 60); - *summertime = 0; - - if (::daylight) + *timezone = ::narrow(-::timezone / 60); + *summertime = !::daylight ? 0 : []() -> s32 { struct tm test{}; ensure(&test == localtime_r(&start_time.tv_sec, &test)); @@ -231,18 +228,25 @@ error_code sys_time_get_timezone(vm::ptr timezone, vm::ptr summertime) if (test.tm_isdst & -2) { sys_time.error("No information for timezone DST bias (timezone=%.2fh, tm_gmtoff=%d)", -::timezone / 3600.0, test.tm_gmtoff); + return 0; } else { - *summertime = ::narrow(test.tm_isdst ? (test.tm_gmtoff + ::timezone) / 60 : 0); + return test.tm_isdst ? ::narrow((test.tm_gmtoff + ::timezone) / 60) : 0; } - } + }(); #else - struct timeval _tv{}; + // gettimeofday doesn't return timezone on linux anymore, but this should work on other OSes? struct timezone tz{}; - ensure(gettimeofday(&_tv, &tz) == 0); - *timezone = -tz.tz_minuteswest; - *summertime = tz.tz_dsttime ? 60 : 0; // TODO + ensure(gettimeofday(nullptr, &tz) == 0); + *timezone = ::narrow(-tz.tz_minuteswest); + *summertime = !tz.tz_dsttime ? 0 : [&]() -> s32 + { + struct tm test{}; + ensure(&test == localtime_r(&start_time.tv_sec, &test)); + + return test.tm_isdst ? ::narrow(test.tm_gmtoff / 60 + tz.tz_minuteswest) : 0; + }(); #endif return CELL_OK;