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