sysclock_set.c (818B)
1 /* ISC license. */ 2 3 /* MT-unsafe */ 4 5 #include <skalibs/sysdeps.h> 6 7 #ifdef SKALIBS_HASCLOCKRT 8 9 #include <time.h> 10 #include <skalibs/tai.h> 11 12 int sysclock_set (tain const *a) 13 { 14 struct timespec now ; 15 tain aa ; 16 tain_add(&aa, a, &tain_nano500) ; 17 if (!timespec_from_tain(&now, &aa)) return 0 ; 18 if (clock_settime(CLOCK_REALTIME, &now) < 0) return 0 ; 19 return 1 ; 20 } 21 22 #else 23 #ifdef SKALIBS_HASSETTIMEOFDAY 24 25 #include <skalibs/nonposix.h> 26 #include <sys/time.h> 27 #include <skalibs/tai.h> 28 29 int sysclock_set (tain const *a) 30 { 31 struct timeval now ; 32 tain aa ; 33 tain_add(&aa, a, &tain_nano500) ; 34 if (!timeval_from_tain(&now, &aa)) return 0 ; 35 if (settimeofday(&now, 0) < 0) return 0 ; 36 return 1 ; 37 } 38 39 #else 40 41 #error "neither clockrt nor settimeofday sysdeps are present. How do your set your system clock?" 42 43 #endif 44 #endif