[orbis-kernel] Fix sys_gettimeofday

This commit is contained in:
Ivan Chikish 2023-07-14 18:48:21 +03:00
parent 24d8a8ae8e
commit 14b41d1af9
3 changed files with 17 additions and 13 deletions

View file

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

View file

@ -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

View file

@ -114,9 +114,9 @@ orbis::SysResult orbis::sys_nanosleep(Thread *thread, ptr<const timespec> rqtp,
}
orbis::SysResult orbis::sys_gettimeofday(Thread *thread, ptr<orbis::timeval> tp,
ptr<orbis::timezone> 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<orbis::timeval> 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;
}