1 /*
2  * Copyright (c) 2007-2009, 2014, 2016-2017 Paul Mattes.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the names of Paul Mattes nor the names of his contributors
13  *       may be used to endorse or promote products derived from this software
14  *       without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY PAUL MATTES "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL PAUL MATTES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /*
29  *	winvers.c
30  *		A Windows console-based 3270 Terminal Emulator
31  *		OS version query
32  */
33 
34 #include "globals.h"
35 
36 #include "winvers.h"
37 
38 #if defined(__GNUC__) /*[*/
39 /* MinGW doesn't have IsWindowsVersionOrGreater(). */
IsWindowsVersionOrGreater(WORD major_version,WORD minor_version,WORD service_pack_major)40 BOOL IsWindowsVersionOrGreater(WORD major_version, WORD minor_version,
41 	WORD service_pack_major)
42 {
43     OSVERSIONINFOEX version_info;
44     DWORDLONG condition_mask = 0;
45 
46     memset(&version_info, 0, sizeof(OSVERSIONINFOEX));
47     version_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
48     version_info.dwMajorVersion = major_version;
49     version_info.dwMinorVersion = minor_version;
50     version_info.wServicePackMajor = service_pack_major;
51     VER_SET_CONDITION(condition_mask, VER_MAJORVERSION, VER_GREATER_EQUAL);
52     VER_SET_CONDITION(condition_mask, VER_MINORVERSION, VER_GREATER_EQUAL);
53     VER_SET_CONDITION(condition_mask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
54     return VerifyVersionInfo(&version_info,
55 	    VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR,
56 	    condition_mask);
57 }
58 #endif /*]*/
59 
60 int
get_version_info(void)61 get_version_info(void)
62 {
63     /*
64      * Enforce our version requirements explicitly, though chances are
65      * missing DLL entry points will cause us to fall over long before we
66      * get to here.
67      */
68     if (!IsWindowsVersionOrGreater(5, 1, 0)) {
69 	fprintf(stderr, "Minimum supported Windows version is Windows XP "
70 		"(NT 5.1)\n");
71 	return -1;
72     }
73 
74     return 0;
75 }
76 
77 /* Returns true if running under Wine. */
78 bool
is_wine(void)79 is_wine(void)
80 {
81     static const char *(CDECL *pwine_get_version)(void);
82     HMODULE hntdll = GetModuleHandle("ntdll.dll");
83     if (!hntdll) {
84 	return false;
85     }
86 
87     pwine_get_version = (void *)GetProcAddress(hntdll, "wine_get_version");
88     return pwine_get_version != NULL;
89 }
90