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