sysclock_get.c (590B)
1 /* ISC license. */ 2 3 #include <skalibs/sysdeps.h> 4 #include <skalibs/tai.h> 5 6 #ifdef SKALIBS_HASCLOCKRT 7 8 #include <time.h> 9 10 int sysclock_get (tain *a) 11 { 12 tain aa ; 13 struct timespec now ; 14 if (clock_gettime(CLOCK_REALTIME, &now) < 0) return 0 ; 15 if (!tain_from_timespec(&aa, &now)) return 0 ; 16 tain_add(a, &aa, &tain_nano500) ; 17 return 1 ; 18 } 19 20 #else 21 22 #include <sys/time.h> 23 24 int sysclock_get (tain *a) 25 { 26 tain aa ; 27 struct timeval now ; 28 if (gettimeofday(&now, 0) < 0) return 0 ; 29 if (!tain_from_timeval(&aa, &now)) return 0 ; 30 tain_add(a, &aa, &tain_nano500) ; 31 return 1 ; 32 } 33 34 #endif