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