llvm.org GIT mirror llvm / 4e5af8f
Avoid the deprecated GetVersionEx API Apparently the preferred version is the incredibly complicated VerifyVersionInfoW function. Rename the function to avoid potential future name clashes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257415 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 3 years ago
2 changed file(s) with 19 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
4747 #include
4848
4949 /// Determines if the program is running on Windows 8 or newer. This
50 /// reimplements the helpers in the Windows 8.1 SDK, which are intended to
51 /// supercede raw calls to GetVersionEx, because old Windows SDKs, Cygwin, and
52 /// MinGW don't have VersionSupport.h yet.
53 inline bool IsWindows8OrGreater() {
54 OSVERSIONINFO osvi = {};
50 /// reimplements one of the helpers in the Windows 8.1 SDK, which are intended
51 /// to supercede raw calls to GetVersionEx. Old SDKs, Cygwin, and MinGW don't
52 /// yet have VersionHelpers.h, so we have our own helper.
53 inline bool RunningWindows8OrGreater() {
54 // Windows 8 is version 6.2, service pack 0.
55 OSVERSIONINFOEXW osvi = {};
5556 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
56 if (!::GetVersionEx(&osvi))
57 return false;
58 return (osvi.dwMajorVersion > 6 ||
59 (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion >= 2));
57 osvi.dwMajorVersion = 6;
58 osvi.dwMinorVersion = 2;
59 osvi.wServicePackMajor = 0;
60
61 DWORDLONG Mask = 0;
62 Mask = VerSetConditionMask(Mask, VER_MAJORVERSION, VER_GREATER_EQUAL);
63 Mask = VerSetConditionMask(Mask, VER_MINORVERSION, VER_GREATER_EQUAL);
64 Mask = VerSetConditionMask(Mask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
65
66 return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION |
67 VER_SERVICEPACKMAJOR,
68 Mask) != FALSE;
6069 }
6170
6271 inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
576576 // Writing a large size of output to Windows console returns ENOMEM. It seems
577577 // that, prior to Windows 8, WriteFile() is redirecting to WriteConsole(), and
578578 // the latter has a size limit (66000 bytes or less, depending on heap usage).
579 bool ShouldWriteInChunks = !!::_isatty(FD) && !IsWindows8OrGreater();
579 bool ShouldWriteInChunks = !!::_isatty(FD) && !RunningWindows8OrGreater();
580580 #endif
581581
582582 do {