fix gettimeofday (was off by one day)

This commit is contained in:
Wolfgang Thaller 2021-09-19 17:56:20 +02:00
parent beb4c2c518
commit c124cf98d9
1 changed files with 6 additions and 1 deletions

View File

@ -276,7 +276,12 @@ int _gettimeofday_r(struct _reent *reent, struct timeval *tp, void *__tz)
if(tp)
{
tp->tv_sec = secs - 86400 * (365 * 66 + 66/4);
const int epochDifferenceInYears = 1970 - 1904;
const int epochDifferenceInDays =
365 * epochDifferenceInYears
+ (epochDifferenceInYears + 3)/ 4; // round up for leap years
tp->tv_sec = secs - 86400 * epochDifferenceInDays;
tp->tv_usec = (ticks - savedTicks) * 20000000 / 2003;
}