int _gettimeofday_r(struct _reent* unused, struct timeval *tp, void *tzp) { (void) unused; (void) tzp; if (tp) { if (!timeshift64_is_set) tune_timeshift64(sntp_get_current_timestamp() * 1000000ULL); uint64_t currentTime_us = timeshift64 + micros64(); tp->tv_sec = currentTime_us / 1000000ULL; tp->tv_usec = currentTime_us % 1000000ULL; } return 0; }
int settimeofday(const struct timeval* tv, const struct timezone* tz) { if (tz) /*before*/ { sntp_set_timezone_in_seconds(tz->tz_minuteswest * 60); // apparently tz->tz_dsttime is a bitfield and should not be further used (cf man) sntp_set_daylight(0); } if (tv) /* after*/ { // reset time subsystem tune_timeshift64(tv->tv_sec * 1000000ULL + tv->tv_usec); sntp_set_system_time(tv->tv_sec); if (_settimeofday_cb) _settimeofday_cb(); } return 0; }