PageRenderTime 56ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/ports/winnt/include/config.h

https://gitlab.com/devicenull/ntpsec
C Header | 528 lines | 273 code | 76 blank | 179 comment | 6 complexity | 610e11f8c2db5984ad1dbabff9d795b1 MD5 | raw file
  1. /*
  2. * ports/winnt/include/config.h - static Windows config.h
  3. *
  4. * On most systems config.h is generated by the configure script.
  5. * For the Windows port, it's hand-maintained. Compilers earlier
  6. * than Visual C++ 2005 are no longer supported, enabling
  7. * portable use of "long long" and "%lld".
  8. */
  9. #ifndef CONFIG_H
  10. #define CONFIG_H
  11. /*
  12. * Known predifined MS compiler version codes:
  13. * 1800: MSVC++ 12.0 (Visual Studio 2013)
  14. * 1700: MSVC++ 11.0 (Visual Studio 2012)
  15. * 1600: MSVC++ 10.0 (Visual Studio 2010)
  16. * 1500: MSVC++ 9.0 (Visual Studio 2008)
  17. * 1400: MSVC++ 8.0 (Visual Studio 2005)
  18. * 1310: MSVC++ 7.1 (Visual Studio 2003)
  19. * 1300: MSVC++ 7.0
  20. * 1200: MSVC++ 6.0 (Visual C++ 6)
  21. * 1100: MSVC++ 5.0
  22. */
  23. #if defined(_MSC_VER) && _MSC_VER < 1400
  24. #error Minimum supported Microsoft compiler is Visual C++ 2005.
  25. #endif
  26. /*
  27. * We want structures and prototypes added after Windows NT 4.0 exposed
  28. * by Windows header files, so we define _WIN32_WINNT to target Windows
  29. * XP (version 5.1). By default, _WIN32_WINNT also controls the minimum
  30. * required Windows version to launch the .exe. As we want a single
  31. * binary to work on all supported Windows versions, we runtime link
  32. * newer functions, and use the linker /version:0x0400 option to
  33. * override the .EXE header minimum Windows version.
  34. *
  35. * When using the VC++ 2008 and later compilers, the resulting binaries
  36. * will not work on versions earlier than Windows XP, due to runtime
  37. * library dependencies. That is, Visual C++ 2005 is the last version
  38. * capable of producing binaries usable with Windows NT 4 and 2000.
  39. */
  40. #ifndef _WIN32_WINNT
  41. #define _WIN32_WINNT 0x0501
  42. #endif
  43. #define __attribute__(x) /* empty */
  44. #define _CRT_SECURE_NO_DEPRECATE 1
  45. /*
  46. * ANSI C compliance enabled
  47. */
  48. #define __STDC__ 1
  49. /*
  50. * Enable the debug build of MS C runtime to dump leaks
  51. * at exit time (currently only if run under a debugger).
  52. */
  53. #if defined(_MSC_VER) && defined(_DEBUG)
  54. # define _CRTDBG_MAP_ALLOC
  55. # include <stdlib.h>
  56. # include <crtdbg.h>
  57. /* # define MALLOC_LINT */ /* defers free() */
  58. # define EREALLOC_IMPL(ptr, newsz, filenm, loc) \
  59. _realloc_dbg(ptr, newsz, _NORMAL_BLOCK, filenm, loc)
  60. #endif
  61. /*
  62. * We need to include stdio.h first before we #define snprintf
  63. * otherwise we can get errors during the build
  64. */
  65. #include <stdio.h>
  66. /* Prevent inclusion of winsock.h in windows.h */
  67. #ifndef _WINSOCKAPI_
  68. #define _WINSOCKAPI_
  69. #endif
  70. #ifndef __RPCASYNC_H__
  71. #define __RPCASYNC_H__
  72. #endif
  73. /*
  74. * On Unix struct sock_timeval is equivalent to struct timeval.
  75. * On Windows built with 64-bit time_t, sock_timeval.tv_sec is a long
  76. * as required by Windows' socket() interface timeout argument, while
  77. * timeval.tv_sec is time_t for the more common use as a UTC time
  78. * within NTP.
  79. *
  80. * winsock.h unconditionally defines struct timeval with long tv_sec
  81. * instead of time_t tv_sec. We redirect its declaration to struct
  82. * sock_timeval instead of struct timeval with a #define.
  83. */
  84. #define timeval sock_timeval
  85. /* Include Windows headers */
  86. #include <windows.h>
  87. #include <winsock2.h>
  88. #include <ws2tcpip.h>
  89. #undef timeval /* see sock_timeval #define and comment above */
  90. /*
  91. * Some definitions we are using are missing in the headers
  92. * shipping with VC6. However, if the SDK is installed then the
  93. * SDK's headers may declare the missing types. This is at least
  94. * the case in the Oct 2001 SDK. That SDK and all subsequent
  95. * versions also define the symbol _W64, so we can use that one
  96. * to determine whether some types need to be defined, or not.
  97. */
  98. #ifdef _W64
  99. /* VC6 can include wspiapi.h only if the SDK is installed */
  100. #include <wspiapi.h>
  101. #endif
  102. #undef interface
  103. #include <process.h>
  104. #include <time.h> /* time_t for timeval decl */
  105. #include <io.h>
  106. /* ---------------------------------------------------------------------
  107. * Above this line are #include lines and the few #define lines
  108. * needed before including headers.
  109. */
  110. struct timeval {
  111. time_t tv_sec;
  112. long tv_usec;
  113. };
  114. /*
  115. * ntohl and friends are actual functions on Windows, use our own
  116. * macros instead to save the function call overhead. All releases
  117. * of Windows are little-endian.
  118. */
  119. #ifdef ntohl
  120. #error ntohl is already defined in ports/winnt/include/config.h
  121. #else
  122. #define ntohl(ul) (((u_long)(ul) & 0xff) << 24 | \
  123. ((u_long)(ul) & 0xff00) << 8 | \
  124. ((u_long)(ul) & 0xff0000) >> 8 | \
  125. ((u_long)(ul) & 0xff000000) >> 24)
  126. #define htonl(ul) ntohl(ul)
  127. #define ntohs(us) ((u_short) \
  128. (((u_short)(us) & 0xff) << 8 | \
  129. ((u_short)(us) & 0xff00) >> 8))
  130. #define htons(us) ntohs(us)
  131. #endif
  132. /*
  133. * On Unix open() works for tty (serial) devices just fine, while on
  134. * Windows refclock serial devices are opened using CreateFile, a lower
  135. * level than the CRT-provided descriptors, because the C runtime lacks
  136. * tty APIs. For refclocks which wish to use open() as well as or
  137. * instead of refclock_open(), tty_open() is equivalent to open() on
  138. * Unix and implemented in the Windows port similarly to
  139. * refclock_open().
  140. */
  141. extern int tty_open(char *, int, int);
  142. /*
  143. * disable use of __declspec(dllexport) by libisc routines
  144. */
  145. #define ISC_STATIC_WIN 1
  146. /*
  147. * ntp_rfc2553.h has cruft under #ifdef SYS_WINNT which is
  148. * appropriate for older Microsoft IPv6 definitions, such
  149. * as in_addr6 being the struct type. We can differentiate
  150. * the RFC2553-compliant newer headers because they have
  151. * #define in_addr6 in6_addr
  152. * for backward compatibility. With the newer headers,
  153. * we define ISC_PLATFORM_0HAVEIPV6 and disable the cruft.
  154. */
  155. #ifdef in_addr6
  156. #define ENABLE_IPV6
  157. #define ISC_PLATFORM_HAVEIPV6
  158. #define ISC_PLATFORM_HAVESCOPEID
  159. #define HAVE_STRUCT_SOCKADDR_STORAGE
  160. #define ISC_PLATFORM_HAVEIN6PKTINFO
  161. #endif /* in_addr6 / RFC2553-compliant IPv6 headers */
  162. #define NO_OPTION_NAME_WARNINGS
  163. #if !defined( _W64 )
  164. /*
  165. * if ULONG_PTR needs to be defined then the build environment
  166. * is pure 32 bit Windows. Since ULONG_PTR and DWORD have
  167. * the same size in 32 bit Windows we can safely define
  168. * a replacement.
  169. */
  170. typedef DWORD ULONG_PTR;
  171. /* VC6 doesn't know about socklen_t, except if the SDK is installed */
  172. typedef int socklen_t;
  173. #endif /* _W64 */
  174. #define ISC_PLATFORM_NEEDIN6ADDRANY
  175. #define HAVE_SOCKADDR_IN6
  176. /*
  177. * The type of the socklen_t defined for getnameinfo() and getaddrinfo()
  178. * is int for VS compilers on Windows but the type is already declared
  179. */
  180. #define GETSOCKNAME_SOCKLEN_TYPE socklen_t
  181. /*
  182. * Older SDKs do not define SO_EXCLUSIVEADDRUSE in winsock2.h
  183. */
  184. #ifndef SO_EXCLUSIVEADDRUSE
  185. #define SO_EXCLUSIVEADDRUSE ((int)(~SO_REUSEADDR))
  186. #endif
  187. #if defined _MSC_VER && _MSC_VER < 1400
  188. /*
  189. * Use 32-bit time definitions for versions prior to VS 2005
  190. * VS 2005 defaults to 64-bit time
  191. */
  192. # define SIZEOF_TIME_T 4
  193. #else
  194. # define SIZEOF_TIME_T 8
  195. #endif
  196. /*
  197. * An attempt to cut down the number of warnings generated during compilation.
  198. * All of these should be benign to disable.
  199. */
  200. #pragma warning(disable: 4100) /* unreferenced formal parameter */
  201. #pragma warning(disable: 4127) /* conditional expression is constant */
  202. #pragma warning(disable: 4996) /* more secure replacement available */
  203. /*
  204. * Windows NT Configuration Values
  205. */
  206. #if defined _DEBUG /* Use VC standard macro definitions */
  207. # define DEBUG 1
  208. #endif
  209. #define __windows__ 1
  210. /* Define if you have the ANSI C header files. */
  211. #define STDC_HEADERS 1
  212. #define OPEN_BCAST_SOCKET 1 /* for ntp_io.c */
  213. #define TYPEOF_IP_MULTICAST_LOOP BOOL
  214. #define SETSOCKOPT_ARG_CAST (const char *)
  215. #define HAVE_RANDOM
  216. #define SAVECONFIG 1
  217. /*
  218. * Multimedia timer enable
  219. */
  220. #define USE_MM_TIMER
  221. /* check for OpenSSL */
  222. #ifdef HAVE_OPENSSL
  223. # define USE_OPENSSL_CRYPTO_RAND 1
  224. #endif
  225. extern void arc4random_buf(void *buf, size_t nbytes);
  226. /*
  227. * Keywords and functions that Microsoft maps
  228. * to other names
  229. */
  230. #define inline __inline
  231. #define stricmp _stricmp
  232. #define strcasecmp _stricmp
  233. #define isascii __isascii
  234. #define finite _finite
  235. #define random rand
  236. #define srandom srand
  237. #define fdopen _fdopen
  238. #define read _read
  239. #define open _open
  240. #ifndef close
  241. #define close _close
  242. #endif
  243. #define write _write
  244. #define strdup _strdup
  245. #define alloca _alloca
  246. #define stat _stat /*struct stat from <sys/stat.h> */
  247. #define fstat _fstat
  248. #define unlink _unlink
  249. /*
  250. * punt on fchmod on Windows
  251. */
  252. #define fchmod(x,y) {}
  253. #define lseek _lseek
  254. #define pipe _pipe
  255. #define dup2 _dup2
  256. /*
  257. * scale, unix sleep is seconds, Windows Sleep is msec
  258. */
  259. #define sleep(x) Sleep((unsigned)(x) * 1000)
  260. #define fileno _fileno
  261. #define isatty _isatty
  262. #define mktemp _mktemp
  263. #define getpid _getpid
  264. #define timegm _mkgmtime
  265. #define errno_to_str isc__strerror
  266. /*
  267. * symbol returning the name of the current function
  268. */
  269. #define __func__ __FUNCTION__
  270. typedef int pid_t; /* PID is an int */
  271. typedef int ssize_t; /* ssize is an int */
  272. /*
  273. * Map the stream to the file number
  274. */
  275. #define STDOUT_FILENO _fileno(stdout)
  276. #define STDERR_FILENO _fileno(stderr)
  277. /*
  278. * To minimize Windows-specific changes to the rest of the NTP code,
  279. * particularly reference clocks, ntp_stdlib.h will
  280. *
  281. * #define strerror(e) ntp_strerror(e)
  282. *
  283. * to deal with our mixture of C runtime (open, write) and Windows
  284. * (sockets, serial ports) error codes. This is an ugly hack because
  285. * both use the lowest values differently, but particularly for ntpd,
  286. * it's not a problem.
  287. */
  288. #define strerror(e) ntp_strerror(e)
  289. extern char * ntp_strerror (int e);
  290. #define MCAST /* Enable Multicast Support */
  291. #define MULTICAST_NONEWSOCKET /* Don't create a new socket for mcast address */
  292. # define REFCLOCK /* from ntpd.mak */
  293. /* #define CLOCK_PARSE */
  294. #define CLOCK_ACTS
  295. #define CLOCK_ARBITER
  296. #define CLOCK_ARCRON_MSF
  297. #define OWN_PPS_NTP_TIMESTAMP_FROM_COUNTER /* timepps.h */
  298. #define HAVE_TIMEPPS_H
  299. #define HAVE_PPSAPI
  300. #define CLOCK_ATOM
  301. #define CLOCK_CHU
  302. #define CLOCK_CHRONOLOG
  303. #define CLOCK_DUMBCLOCK
  304. #define CLOCK_HOPF_SERIAL /* device 38, hopf DCF77/GPS serial line receiver */
  305. #define CLOCK_HOPF_PCI /* device 39, hopf DCF77/GPS PCI-Bus receiver */
  306. #define CLOCK_JUPITER
  307. #define CLOCK_LOCAL
  308. #define CLOCK_NMEA
  309. #define CLOCK_ONCORE
  310. #define CLOCK_PALISADE /* from ntpd.mak */
  311. #define CLOCK_PARSE
  312. /* parse component drivers */
  313. #define CLOCK_COMPUTIME
  314. #define CLOCK_DCF7000
  315. #define CLOCK_HOPF6021
  316. #define CLOCK_MEINBERG
  317. #define CLOCK_RAWDCF
  318. #define CLOCK_RCC8000
  319. #define CLOCK_SCHMID
  320. #define CLOCK_TRIMTAIP
  321. #define CLOCK_TRIMTSIP
  322. #define CLOCK_VARITEXT
  323. #define CLOCK_WHARTON_400A
  324. /* end parse component drivers */
  325. /* # define CLOCK_SHM */
  326. #define CLOCK_SPECTRACOM /* refclock_spectracom.c */
  327. #define CLOCK_TRIMBLEDC
  328. #define CLOCK_TRUETIME
  329. #define NTP_LITTLE_ENDIAN /* from libntp.mak */
  330. #define NTP_POSIX_SOURCE
  331. #define SYSLOG_FILE /* from libntp.mak */
  332. #define HAVE_LONG_LONG_INT 1
  333. #define HAVE_UNSIGNED_LONG_LONG_INT 1
  334. #define HAVE_SIZE_T 1
  335. #define HAVE_PTRDIFF_T 1
  336. # define SIZEOF_SIGNED_CHAR 1
  337. # define SIZEOF_SHORT 2
  338. # define SIZEOF_INT 4
  339. # define SIZEOF_LONG 4
  340. # define SIZEOF_LONG_LONG 8
  341. /* libntp/snprintf.c doesn't know %I64d */
  342. #define ISC_PLATFORM_QUADFORMAT "ll"
  343. # define HAVE_ALLOCA 1
  344. # define HAVE_GETCLOCK 1
  345. # define HAVE_MEMMOVE 1
  346. # define HAVE_TIMEGM 1 /* actually _mkgmtime */
  347. # define HAVE_IO_COMPLETION_PORT
  348. # define ISC_PLATFORM_NEEDNTOP
  349. # define ISC_PLATFORM_NEEDPTON
  350. #define HAVE_BSD_NICE /* emulate BSD setpriority() */
  351. #define HW_WANT_RPL_VSNPRINTF 1
  352. #define vsnprintf rpl_vsnprintf
  353. #include <stdarg.h>
  354. int rpl_vsnprintf(char *, size_t, const char *, va_list);
  355. #define HW_WANT_RPL_SNPRINTF 1
  356. #define snprintf rpl_snprintf
  357. int rpl_snprintf(char *, size_t, const char *, ...);
  358. #define HAVE_VSNPRINTF 1
  359. #define HAVE_SNPRINTF 1
  360. typedef char *caddr_t;
  361. #ifdef _WCTYPE_T_DEFINED /* see vc/include/crtdefs.h */
  362. #define HAVE_WINT_T 1
  363. #endif
  364. #ifndef _INTPTR_T_DEFINED
  365. typedef long intptr_t;
  366. #define _INTPTR_T_DEFINED
  367. #endif
  368. #define HAVE_INTPTR_T 1
  369. #ifndef _UINTPTR_T_DEFINED
  370. typedef unsigned long uintptr_t;
  371. #define _UINTPTR_T_DEFINED
  372. #endif
  373. #define HAVE_UINTPTR_T 1
  374. #if !defined( _W64 )
  375. /*
  376. * if DWORD_PTR needs to be defined then the build environment
  377. * is pure 32 bit Windows. Since DWORD_PTR and DWORD have
  378. * the same size in 32 bit Windows we can safely define
  379. * a replacement.
  380. */
  381. typedef DWORD DWORD_PTR;
  382. #endif
  383. #define NEED_S_CHAR_TYPEDEF
  384. /* C99 exact size integer support. */
  385. #if defined(_MSC_VER) && _MSC_VER<1800
  386. # define MISSING_INTTYPES_H 1 /* not provided by VS2012 and earlier */
  387. # define MISSING_STDBOOL_H 1 /* not provided by VS2012 and earlier */
  388. # define MISSING_C99_STRUCT_INIT 1 /* see [Bug 2728] */
  389. #else
  390. #if defined(_MSC_VER) && _MSC_VER>=1800
  391. /* VS2013 and above support C99 types */
  392. # define HAVE_INT8_T 1
  393. # define HAVE_UINT8_T 1
  394. # define HAVE_INT16_T 1
  395. # define HAVE_UINT16_T 1
  396. # define HAVE_INT32_T 1
  397. # define HAVE_UINT32_T 1
  398. #endif
  399. #endif
  400. #if !defined (MISSING_STDBOOL_H)
  401. # define HAVE_STDBOOL_H
  402. #endif
  403. /* Directory separator, usually / or \ */
  404. #define DIR_SEP '\\'
  405. #define POSIX_SHELL "/bin/sh"
  406. #define ULONG_CONST(a) a ## UL
  407. #define NOKMEM
  408. #ifndef STR_SYSTEM
  409. #define STR_SYSTEM "Windows"
  410. #endif
  411. #ifndef STR_PROCESSOR
  412. #define STRINGIZE(arg) #arg
  413. #ifdef _M_IX86
  414. #ifndef _M_IX86_FP
  415. #define STR_PROCESSOR "x86"
  416. #else
  417. #if !_M_IX86_FP
  418. #define STR_PROCESSOR "x86"
  419. #else
  420. #if _M_IX86_FP > 2
  421. #define STR_PROCESSOR "x86-FP-" STRINGIZE(_M_IX86_FP)
  422. #else
  423. #if _M_IX86_FP == 2
  424. #define STR_PROCESSOR "x86-SSE2"
  425. #else
  426. #define STR_PROCESSOR "x86-SSE"
  427. #endif /* _M_IX86 == 2 */
  428. #endif /* _M_IX86_FP > 2 */
  429. #endif /* !_M_IX86_FP */
  430. #endif /* !defined(_M_IX86_FP) */
  431. #endif /* !defined(_M_IX86) */
  432. #ifdef _M_IA64
  433. #define STR_PROCESSOR "Itanium"
  434. #endif
  435. #ifdef _M_X64
  436. #define STR_PROCESSOR "x64"
  437. #endif
  438. #endif /* !defined(STR_PROCESSOR) */
  439. #undef STRINGIZE
  440. #define SIOCGIFFLAGS SIO_GET_INTERFACE_LIST /* used in ntp_io.c */
  441. /*
  442. * Below this line are includes which must happen after the bulk of
  443. * config.h is processed. If you need to add another #include to this
  444. * file the preferred location is near the top, above the similar
  445. * line of hyphens.
  446. * ---------------------------------------------------------------------
  447. */
  448. /*
  449. * Include standard stat information
  450. */
  451. #include <isc/stat.h>
  452. #endif /* CONFIG_H */