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; }