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