1290001Sglebius/* 2290001Sglebius * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") 3290001Sglebius * Copyright (C) 2002 Internet Software Consortium. 4290001Sglebius * 5290001Sglebius * Permission to use, copy, modify, and/or distribute this software for any 6290001Sglebius * purpose with or without fee is hereby granted, provided that the above 7290001Sglebius * copyright notice and this permission notice appear in all copies. 8290001Sglebius * 9290001Sglebius * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10290001Sglebius * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11290001Sglebius * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12290001Sglebius * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13290001Sglebius * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14290001Sglebius * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15290001Sglebius * PERFORMANCE OF THIS SOFTWARE. 16290001Sglebius */ 17290001Sglebius 18290001Sglebius/* $Id: win32os.c,v 1.5 2007/06/19 23:47:19 tbox Exp $ */ 19290001Sglebius 20290001Sglebius#include <windows.h> 21290001Sglebius 22290001Sglebius#include <isc/win32os.h> 23290001Sglebius 24290001Sglebiusstatic BOOL bInit = FALSE; 25290001Sglebiusstatic OSVERSIONINFOEX osVer; 26290001Sglebius 27290001Sglebiusstatic void 28290001Sglebiusinitialize_action(void) { 29290001Sglebius BOOL bSuccess; 30290001Sglebius 31290001Sglebius if (bInit) 32290001Sglebius return; 33290001Sglebius /* 34290001Sglebius * NOTE: VC++ 6.0 gets this function declaration wrong 35290001Sglebius * so we compensate by casting the argument 36290001Sglebius */ 37290001Sglebius osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 38290001Sglebius bSuccess = GetVersionEx((OSVERSIONINFO *) &osVer); 39290001Sglebius 40290001Sglebius /* 41290001Sglebius * Versions of NT before NT4.0 SP6 did not return the 42290001Sglebius * extra info that the EX structure provides and returns 43290001Sglebius * a failure so we need to retry with the old structure. 44290001Sglebius */ 45290001Sglebius if(!bSuccess) { 46290001Sglebius osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 47290001Sglebius bSuccess = GetVersionEx((OSVERSIONINFO *) &osVer); 48290001Sglebius } 49290001Sglebius bInit = TRUE; 50290001Sglebius} 51290001Sglebius 52290001Sglebiusunsigned int 53290001Sglebiusisc_win32os_majorversion(void) { 54290001Sglebius initialize_action(); 55290001Sglebius return ((unsigned int)osVer.dwMajorVersion); 56290001Sglebius} 57290001Sglebius 58290001Sglebiusunsigned int 59290001Sglebiusisc_win32os_minorversion(void) { 60290001Sglebius initialize_action(); 61290001Sglebius return ((unsigned int)osVer.dwMinorVersion); 62290001Sglebius} 63290001Sglebius 64290001Sglebiusunsigned int 65290001Sglebiusisc_win32os_servicepackmajor(void) { 66290001Sglebius initialize_action(); 67290001Sglebius return ((unsigned int)osVer.wServicePackMajor); 68290001Sglebius} 69290001Sglebius 70290001Sglebiusunsigned int 71290001Sglebiusisc_win32os_servicepackminor(void) { 72290001Sglebius initialize_action(); 73290001Sglebius return ((unsigned int)osVer.wServicePackMinor); 74290001Sglebius} 75290001Sglebius 76290001Sglebiusint 77290001Sglebiusisc_win32os_versioncheck(unsigned int major, unsigned int minor, 78290001Sglebius unsigned int spmajor, unsigned int spminor) { 79290001Sglebius 80290001Sglebius initialize_action(); 81290001Sglebius 82290001Sglebius if (major < isc_win32os_majorversion()) 83290001Sglebius return (1); 84290001Sglebius if (major > isc_win32os_majorversion()) 85290001Sglebius return (-1); 86290001Sglebius if (minor < isc_win32os_minorversion()) 87290001Sglebius return (1); 88290001Sglebius if (minor > isc_win32os_minorversion()) 89290001Sglebius return (-1); 90290001Sglebius if (spmajor < isc_win32os_servicepackmajor()) 91290001Sglebius return (1); 92290001Sglebius if (spmajor > isc_win32os_servicepackmajor()) 93290001Sglebius return (-1); 94290001Sglebius if (spminor < isc_win32os_servicepackminor()) 95290001Sglebius return (1); 96290001Sglebius if (spminor > isc_win32os_servicepackminor()) 97290001Sglebius return (-1); 98290001Sglebius 99290001Sglebius /* Exact */ 100290001Sglebius return (0); 101290001Sglebius}