From 4e5af8fec07665154fd7b290c4ce2ab16000eee3 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Mon, 11 Jan 2016 23:33:03 +0000 Subject: [PATCH 1/1] 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 --- lib/Support/Windows/WindowsSupport.h | 27 ++++++++++++++++++--------- lib/Support/raw_ostream.cpp | 2 +- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/Support/Windows/WindowsSupport.h b/lib/Support/Windows/WindowsSupport.h index cb091f18640..60490f26643 100644 --- a/lib/Support/Windows/WindowsSupport.h +++ b/lib/Support/Windows/WindowsSupport.h @@ -48,16 +48,25 @@ #include /// Determines if the program is running on Windows 8 or newer. This -/// reimplements the helpers in the Windows 8.1 SDK, which are intended to -/// supercede raw calls to GetVersionEx, because old Windows SDKs, Cygwin, and -/// MinGW don't have VersionSupport.h yet. -inline bool IsWindows8OrGreater() { - OSVERSIONINFO osvi = {}; +/// reimplements one of the helpers in the Windows 8.1 SDK, which are intended +/// to supercede raw calls to GetVersionEx. Old SDKs, Cygwin, and MinGW don't +/// yet have VersionHelpers.h, so we have our own helper. +inline bool RunningWindows8OrGreater() { + // Windows 8 is version 6.2, service pack 0. + OSVERSIONINFOEXW osvi = {}; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if (!::GetVersionEx(&osvi)) - return false; - return (osvi.dwMajorVersion > 6 || - (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion >= 2)); + osvi.dwMajorVersion = 6; + osvi.dwMinorVersion = 2; + osvi.wServicePackMajor = 0; + + DWORDLONG Mask = 0; + Mask = VerSetConditionMask(Mask, VER_MAJORVERSION, VER_GREATER_EQUAL); + Mask = VerSetConditionMask(Mask, VER_MINORVERSION, VER_GREATER_EQUAL); + Mask = VerSetConditionMask(Mask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); + + return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | + VER_SERVICEPACKMAJOR, + Mask) != FALSE; } inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) { diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 57162dc6e95..15813fd3e66 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -577,7 +577,7 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { // Writing a large size of output to Windows console returns ENOMEM. It seems // that, prior to Windows 8, WriteFile() is redirecting to WriteConsole(), and // the latter has a size limit (66000 bytes or less, depending on heap usage). - bool ShouldWriteInChunks = !!::_isatty(FD) && !IsWindows8OrGreater(); + bool ShouldWriteInChunks = !!::_isatty(FD) && !RunningWindows8OrGreater(); #endif do { -- 2.34.1