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

#include <sys/time.h>
#include <errno.h>
#include <skalibs/sysdeps.h>
#include <skalibs/uint64.h>
#include <skalibs/tai.h>

int timeval_from_tai_relative (struct timeval *tv, tai_t const *t)
{
  if (tai_sec(t) >= (uint64)1 << 63) return (errno = EINVAL, 0) ;
#if SKALIBS_SIZEOFTIME < 8
  if (tai_sec(t) > 0xffffffffU) return (errno = ERANGE, 0) ;
#endif
  tv->tv_sec = (time_t)tai_sec(t) ;
  tv->tv_usec = 0 ;
  return 1 ;
}