From 14b41d1af95d521c82de0f6dfb2751851f510428 Mon Sep 17 00:00:00 2001 From: Ivan Chikish Date: Fri, 14 Jul 2023 18:48:21 +0300 Subject: [PATCH] [orbis-kernel] Fix sys_gettimeofday --- orbis-kernel/include/orbis/sys/sysproto.hpp | 11 ++--------- orbis-kernel/include/orbis/time.hpp | 8 ++++++++ orbis-kernel/src/sys/sys_time.cpp | 11 +++++++---- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/orbis-kernel/include/orbis/sys/sysproto.hpp b/orbis-kernel/include/orbis/sys/sysproto.hpp index bbe2e386f..b1d8d3594 100644 --- a/orbis-kernel/include/orbis/sys/sysproto.hpp +++ b/orbis-kernel/include/orbis/sys/sysproto.hpp @@ -11,15 +11,8 @@ using cpuwhich_t = sint; using cpulevel_t = sint; using SceKernelModule = ModuleHandle; -struct timeval { - int64_t tv_sec; - int64_t tv_usec; -}; - -struct timezone { - sint tz_minuteswest; - sint tz_dsttime; -}; +struct timeval; +struct timezone; struct ModuleInfo; struct ModuleInfoEx; diff --git a/orbis-kernel/include/orbis/time.hpp b/orbis-kernel/include/orbis/time.hpp index 8a566b0fb..e8779ccfd 100644 --- a/orbis-kernel/include/orbis/time.hpp +++ b/orbis-kernel/include/orbis/time.hpp @@ -7,4 +7,12 @@ struct timespec { uint64_t sec; uint64_t nsec; }; +struct timeval { + int64_t tv_sec; + int64_t tv_usec; +}; +struct timezone { + sint tz_minuteswest; + sint tz_dsttime; +}; } // namespace orbis diff --git a/orbis-kernel/src/sys/sys_time.cpp b/orbis-kernel/src/sys/sys_time.cpp index a9d1b2147..c07ec85ab 100644 --- a/orbis-kernel/src/sys/sys_time.cpp +++ b/orbis-kernel/src/sys/sys_time.cpp @@ -114,9 +114,9 @@ orbis::SysResult orbis::sys_nanosleep(Thread *thread, ptr rqtp, } orbis::SysResult orbis::sys_gettimeofday(Thread *thread, ptr tp, ptr tzp) { + ORBIS_LOG_TRACE(__FUNCTION__, tp, tzp); struct ::timeval tv; - struct ::timezone tz; - if (::gettimeofday(&tv, &tz) != 0) + if (::gettimeofday(&tv, nullptr) != 0) std::abort(); if (tp) { orbis::timeval value; @@ -126,9 +126,12 @@ orbis::SysResult orbis::sys_gettimeofday(Thread *thread, ptr tp, return e; } if (tzp) { + struct ::tm tp; + if (localtime_r(&tv.tv_sec, &tp) != &tp) + std::abort(); orbis::timezone value; - value.tz_dsttime = tz.tz_dsttime; - value.tz_minuteswest = tz.tz_minuteswest; + value.tz_dsttime = tp.tm_isdst; + value.tz_minuteswest = -tp.tm_gmtoff / 60; if (auto e = uwrite(tzp, value); e != ErrorCode{}) return e; }