Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / ntp / dist / lib / isc / win32 / win32os.c
bloba28ad2698fa29c29129f0d18ca1eb81aecf1eba8
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2002 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: win32os.c,v 1.5 2007/06/19 23:47:19 tbox Exp */
22 #include <windows.h>
24 #include <isc/win32os.h>
26 static BOOL bInit = FALSE;
27 static OSVERSIONINFOEX osVer;
29 static void
30 initialize_action(void) {
31 BOOL bSuccess;
33 if (bInit)
34 return;
36 * NOTE: VC++ 6.0 gets this function declaration wrong
37 * so we compensate by casting the argument
39 osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
40 bSuccess = GetVersionEx((OSVERSIONINFO *) &osVer);
43 * Versions of NT before NT4.0 SP6 did not return the
44 * extra info that the EX structure provides and returns
45 * a failure so we need to retry with the old structure.
47 if(!bSuccess) {
48 osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
49 bSuccess = GetVersionEx((OSVERSIONINFO *) &osVer);
51 bInit = TRUE;
54 unsigned int
55 isc_win32os_majorversion(void) {
56 initialize_action();
57 return ((unsigned int)osVer.dwMajorVersion);
60 unsigned int
61 isc_win32os_minorversion(void) {
62 initialize_action();
63 return ((unsigned int)osVer.dwMinorVersion);
66 unsigned int
67 isc_win32os_servicepackmajor(void) {
68 initialize_action();
69 return ((unsigned int)osVer.wServicePackMajor);
72 unsigned int
73 isc_win32os_servicepackminor(void) {
74 initialize_action();
75 return ((unsigned int)osVer.wServicePackMinor);
78 int
79 isc_win32os_versioncheck(unsigned int major, unsigned int minor,
80 unsigned int spmajor, unsigned int spminor) {
82 initialize_action();
84 if (major < isc_win32os_majorversion())
85 return (1);
86 if (major > isc_win32os_majorversion())
87 return (-1);
88 if (minor < isc_win32os_minorversion())
89 return (1);
90 if (minor > isc_win32os_minorversion())
91 return (-1);
92 if (spmajor < isc_win32os_servicepackmajor())
93 return (1);
94 if (spmajor > isc_win32os_servicepackmajor())
95 return (-1);
96 if (spminor < isc_win32os_servicepackminor())
97 return (1);
98 if (spminor > isc_win32os_servicepackminor())
99 return (-1);
101 /* Exact */
102 return (0);