1 /* $NetBSD: win32os.c,v 1.6 2015/07/08 17:29:00 christos Exp $ */
4 * Copyright (C) 2004, 2007, 2013-2015 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.
23 #include <isc/win32os.h>
29 isc_win32os_versioncheck(unsigned int major
, unsigned int minor
,
30 unsigned int spmajor
, unsigned int spminor
)
32 OSVERSIONINFOEX osVer
;
34 ULONGLONG conditionMask
;
36 memset(&osVer
, 0, sizeof(OSVERSIONINFOEX
));
37 osVer
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
41 /* Optimistic: likely greater */
42 osVer
.dwMajorVersion
= major
;
43 typeMask
|= VER_MAJORVERSION
;
44 conditionMask
= VerSetConditionMask(conditionMask
,
47 osVer
.dwMinorVersion
= minor
;
48 typeMask
|= VER_MINORVERSION
;
49 conditionMask
= VerSetConditionMask(conditionMask
,
52 osVer
.wServicePackMajor
= spmajor
;
53 typeMask
|= VER_SERVICEPACKMAJOR
;
54 conditionMask
= VerSetConditionMask(conditionMask
,
57 osVer
.wServicePackMinor
= spminor
;
58 typeMask
|= VER_SERVICEPACKMINOR
;
59 conditionMask
= VerSetConditionMask(conditionMask
,
62 if (VerifyVersionInfo(&osVer
, typeMask
, conditionMask
))
65 /* Failed: retry with equal */
67 conditionMask
= VerSetConditionMask(conditionMask
,
70 conditionMask
= VerSetConditionMask(conditionMask
,
73 conditionMask
= VerSetConditionMask(conditionMask
,
76 conditionMask
= VerSetConditionMask(conditionMask
,
79 if (VerifyVersionInfo(&osVer
, typeMask
, conditionMask
))
87 main(int argc
, char **argv
) {
88 unsigned int major
= 0;
89 unsigned int minor
= 0;
90 unsigned int spmajor
= 0;
91 unsigned int spminor
= 0;
97 major
= (unsigned int) atoi(argv
[0]);
102 minor
= (unsigned int) atoi(argv
[0]);
107 spmajor
= (unsigned int) atoi(argv
[0]);
112 spminor
= (unsigned int) atoi(argv
[0]);
115 ret
= isc_win32os_versioncheck(major
, minor
, spmajor
, spminor
);
117 printf("%s major %u minor %u SP major %u SP minor %u\n",
118 ret
> 0 ? "greater" : (ret
== 0 ? "equal" : "less"),
119 major
, minor
, spmajor
, spminor
);