xref: /freebsd/contrib/ntp/include/ntp_unixtime.h (revision e8e8c939350bdf3c228a411caa9660c607c27a11)
1 /*
2  * ntp_unixtime.h - much of what was here is now in timevalops.h
3  */
4 
5 #ifndef NTP_UNIXTIME_H
6 #define NTP_UNIXTIME_H
7 
8 #include "ntp_types.h"	/* picks up time.h via ntp_machine.h */
9 #include "ntp_calendar.h"
10 
11 #ifdef SIM
12 #   define GETTIMEOFDAY(a, b) (node_gettime(&ntp_node, a))
13 #   define SETTIMEOFDAY(a, b) (node_settime(&ntp_node, a))
14 #   define ADJTIMEOFDAY(a, b) (node_adjtime(&ntp_node, a, b))
15 #else
16 #   define ADJTIMEOFDAY(a, b) (adjtime(a, b))
17 /* gettimeofday() takes two args in BSD and only one in SYSV */
18 # if defined(HAVE_SYS_TIMERS_H) && defined(HAVE_GETCLOCK)
19 #  include <sys/timers.h>
20 int getclock (int clock_type, struct timespec *tp);
21 #   define GETTIMEOFDAY(a, b) (gettimeofday(a, b))
22 #   define SETTIMEOFDAY(a, b) (settimeofday(a, b))
23 # else /* not (HAVE_SYS_TIMERS_H && HAVE_GETCLOCK) */
24 #  ifdef SYSV_TIMEOFDAY
25 #   define GETTIMEOFDAY(a, b) (gettimeofday(a))
26 #   define SETTIMEOFDAY(a, b) (settimeofday(a))
27 #  else /* ! SYSV_TIMEOFDAY */
28 #if defined SYS_CYGWIN32
29 #   define GETTIMEOFDAY(a, b) (gettimeofday(a, b))
30 #   define SETTIMEOFDAY(a, b) (settimeofday_NT(a))
31 #else
32 #   define GETTIMEOFDAY(a, b) (gettimeofday(a, b))
33 #   define SETTIMEOFDAY(a, b) (settimeofday(a, b))
34 #endif
35 #  endif /* SYSV_TIMEOFDAY */
36 # endif /* not (HAVE_SYS_TIMERS_H && HAVE_GETCLOCK) */
37 #endif /* SIM */
38 
39 /*
40  * Time of day conversion constant.  Ntp's time scale starts in 1900,
41  * Unix in 1970.  The value is 1970 - 1900 in seconds, 0x83aa7e80 or
42  * 2208988800.  This is larger than 32-bit INT_MAX, so unsigned
43  * type is forced.
44  */
45 #define	JAN_1970 ((u_int)NTP_TO_UNIX_DAYS * (u_int)SECSPERDAY)
46 
47 #endif /* !defined(NTP_UNIXTIME_H) */
48