Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / ntp / dist / include / ntp_syscall.h
blob0f0ef80c59d5861f94e51547980affed336dbd0b
1 /* $NetBSD$ */
3 /*
4 * ntp_syscall.h - various ways to perform the ntp_adjtime() and ntp_gettime()
5 * system calls.
6 */
8 #ifndef NTP_SYSCALL_H
9 #define NTP_SYSCALL_H
11 #ifdef HAVE_CONFIG_H
12 #include <config.h>
13 #endif
15 #ifdef HAVE_SYS_TIMEX_H
16 # include <sys/timex.h>
17 #endif
19 #ifndef NTP_SYSCALLS_LIBC
20 #ifdef NTP_SYSCALLS_STD
21 # define ntp_adjtime(t) syscall(SYS_ntp_adjtime, (t))
22 # define ntp_gettime(t) syscall(SYS_ntp_gettime, (t))
23 #else /* !NTP_SYSCALLS_STD */
24 # ifdef HAVE___ADJTIMEX
25 extern int __adjtimex (struct timex *);
27 # define ntp_adjtime(t) __adjtimex((t))
29 #ifndef HAVE_STRUCT_NTPTIMEVAL
30 struct ntptimeval
32 struct timeval time; /* current time (ro) */
33 long int maxerror; /* maximum error (us) (ro) */
34 long int esterror; /* estimated error (us) (ro) */
36 #endif
38 static inline int
39 ntp_gettime(
40 struct ntptimeval *ntv
43 struct timex tntx;
44 int result;
46 tntx.modes = 0;
47 result = __adjtimex (&tntx);
48 ntv->time = tntx.time;
49 ntv->maxerror = tntx.maxerror;
50 ntv->esterror = tntx.esterror;
51 #ifdef NTP_API
52 # if NTP_API > 3
53 ntv->tai = tntx.tai;
54 # endif
55 #endif
56 return(result);
58 # else /* !HAVE__ADJTIMEX */
59 # ifdef HAVE___NTP_GETTIME
60 # define ntp_gettime(t) __ntp_gettime((t))
61 # endif
62 # endif /* !HAVE_ADJTIMEX */
63 #endif /* !NTP_SYSCALLS_STD */
64 #endif /* !NTP_SYSCALLS_LIBC */
66 #endif /* NTP_SYSCALL_H */