summaryrefslogtreecommitdiff
path: root/src/libstddjb/sysclock_get.c
blob: 6c5041d8813a5952bb42881a89bf77bd5e5fd9f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* ISC license. */

#include <skalibs/sysdeps.h>
#include <skalibs/tai.h>

#ifdef SKALIBS_HASCLOCKRT

#include <time.h>

int sysclock_get (tain_t *a)
{
  tain_t aa ;
  struct timespec now ;
  if (clock_gettime(CLOCK_REALTIME, &now) < 0) return 0 ;
  if (!tain_from_timespec(&aa, &now)) return 0 ;
  tain_add(a, &aa, &tain_nano500) ;
  return 1 ;
}

#else

#include <sys/time.h>

int sysclock_get (tain_t *a)
{
  tain_t aa ;
  struct timeval now ;
  if (gettimeofday(&now, 0) < 0) return 0 ;
  if (!tain_from_timeval(&aa, &now)) return 0 ;
  tain_add(a, &aa, &tain_nano500) ;
  return 1 ;
}

#endif