summaryrefslogtreecommitdiff
path: root/src/libstddjb/tain_from_ntp.c
blob: 5314a3882e4bb82c6c09d82118b2e305b1204403 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* ISC license. */

#include <skalibs/uint64.h>
#include <skalibs/tai.h>
#include <skalibs/djbtime.h>

int tain_from_ntp (tain_t *a, uint64 u)
{
  tai_t secs = { .x = u >> 32 } ;
  if (secs.x <= 0x7FFFFFFFUL) secs.x |= ((uint64)1 << 32) ;
  secs.x += TAI_MAGIC ;
  secs.x -= NTP_OFFSET ;
  if (!tai_from_utc(&secs, secs.x)) return 0 ;
  a->sec = secs ;
  a->nano = ((u & 0xFFFFFFFFUL) * 1000000000) >> 32 ;
  return 1 ;
}