1/* $NetBSD: win32os.c,v 1.6 2020/05/25 20:47:23 christos Exp $ */ 2 3/* 4 * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (C) 2002 Internet Software Consortium. 6 * 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. 10 * 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. 18 */ 19 20/* Id: win32os.c,v 1.5 2007/06/19 23:47:19 tbox Exp */ 21 22#include <windows.h> 23 24#include <isc/win32os.h> 25 26static BOOL bInit = FALSE; 27static OSVERSIONINFOEX osVer; 28 29static void 30initialize_action(void) { 31 BOOL bSuccess; 32 33 if (bInit) 34 return; 35 /* 36 * NOTE: VC++ 6.0 gets this function declaration wrong 37 * so we compensate by casting the argument 38 */ 39 osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 40 bSuccess = GetVersionEx((OSVERSIONINFO *) &osVer); 41 42 /* 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. 46 */ 47 if(!bSuccess) { 48 osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 49 bSuccess = GetVersionEx((OSVERSIONINFO *) &osVer); 50 } 51 bInit = TRUE; 52} 53 54unsigned int 55isc_win32os_majorversion(void) { 56 initialize_action(); 57 return ((unsigned int)osVer.dwMajorVersion); 58} 59 60unsigned int 61isc_win32os_minorversion(void) { 62 initialize_action(); 63 return ((unsigned int)osVer.dwMinorVersion); 64} 65 66unsigned int 67isc_win32os_servicepackmajor(void) { 68 initialize_action(); 69 return ((unsigned int)osVer.wServicePackMajor); 70} 71 72unsigned int 73isc_win32os_servicepackminor(void) { 74 initialize_action(); 75 return ((unsigned int)osVer.wServicePackMinor); 76} 77 78int 79isc_win32os_versioncheck(unsigned int major, unsigned int minor, 80 unsigned int spmajor, unsigned int spminor) { 81 82 initialize_action(); 83 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); 100 101 /* Exact */ 102 return (0); 103} 104