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