1 /* $NetBSD: ntp_syscall.h,v 1.5 2020/05/25 20:47:20 christos Exp $ */ 2 3 /* 4 * ntp_syscall.h - various ways to perform the ntp_adjtime() and ntp_gettime() 5 * system calls. 6 */ 7 8 #ifndef NTP_SYSCALL_H 9 #define NTP_SYSCALL_H 10 11 #ifdef HAVE_SYS_TIMEX_H 12 # include <sys/timex.h> 13 #endif 14 15 #ifndef NTP_SYSCALLS_LIBC 16 # ifdef NTP_SYSCALLS_STD 17 # define ntp_adjtime(t) syscall(SYS_ntp_adjtime, (t)) 18 # define ntp_gettime(t) syscall(SYS_ntp_gettime, (t)) 19 # else /* !NTP_SYSCALLS_STD */ 20 # ifdef HAVE_NTP_ADJTIME 21 extern int ntp_adjtime (struct timex *); 22 23 # ifndef HAVE_STRUCT_NTPTIMEVAL 24 struct ntptimeval 25 { 26 struct timeval time; /* current time (ro) */ 27 long int maxerror; /* maximum error (us) (ro) */ 28 long int esterror; /* estimated error (us) (ro) */ 29 }; 30 # endif 31 32 # ifndef HAVE_NTP_GETTIME 33 static inline int ntp_gettime(struct ntptimeval * ntv)34ntp_gettime( 35 struct ntptimeval *ntv 36 ) 37 { 38 struct timex tntx; 39 int result; 40 41 ZERO(tntx); 42 result = ntp_adjtime(&tntx); 43 ntv->time = tntx.time; 44 ntv->maxerror = tntx.maxerror; 45 ntv->esterror = tntx.esterror; 46 # ifdef NTP_API 47 # if NTP_API > 3 48 ntv->tai = tntx.tai; 49 # endif 50 # endif 51 return result; 52 } 53 # endif /* !HAVE_NTP_GETTIME */ 54 # endif /* !HAVE_NTP_ADJTIME */ 55 # endif /* !NTP_SYSCALLS_STD */ 56 #endif /* !NTP_SYSCALLS_LIBC */ 57 58 #endif /* NTP_SYSCALL_H */ 59