Commit 064fffbc authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

mtime: use timespec_get() in NTPtime64()

parent a392c101
......@@ -230,35 +230,19 @@ mtime_t date_Decrement( date_t *p_date, uint32_t i_nb_samples )
/**
* @return NTP 64-bits timestamp in host byte order.
*/
uint64_t NTPtime64 (void)
uint64_t NTPtime64(void)
{
#if (_POSIX_TIMERS > 0)
struct timespec ts;
clock_gettime (CLOCK_REALTIME, &ts);
#else
struct timeval tv;
struct
{
uint32_t tv_sec;
uint32_t tv_nsec;
} ts;
gettimeofday (&tv, NULL);
ts.tv_sec = tv.tv_sec;
ts.tv_nsec = tv.tv_usec * 1000;
#endif
timespec_get(&ts, TIME_UTC);
/* Convert nanoseconds to 32-bits fraction (232 picosecond units) */
uint64_t t = (uint64_t)(ts.tv_nsec) << 32;
t /= 1000000000;
/* There is 70 years (incl. 17 leap ones) offset to the Unix Epoch.
* No leap seconds during that period since they were not invented yet.
/* The offset to Unix epoch is 70 years (incl. 17 leap ones). There were
* no leap seconds during that period since they had not been invented yet.
*/
assert (t < 0x100000000);
t |= ((UINT64_C(70) * 365 + 17) * 24 * 60 * 60 + ts.tv_sec) << 32;
return t;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment