[llvm] r257415 - Avoid the deprecated GetVersionEx API
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 11 15:33:03 PST 2016
Author: rnk
Date: Mon Jan 11 17:33:03 2016
New Revision: 257415
URL: http://llvm.org/viewvc/llvm-project?rev=257415&view=rev
Log:
Avoid the deprecated GetVersionEx API
Apparently the preferred version is the incredibly complicated
VerifyVersionInfoW function.
Rename the function to avoid potential future name clashes.
Modified:
llvm/trunk/lib/Support/Windows/WindowsSupport.h
llvm/trunk/lib/Support/raw_ostream.cpp
Modified: llvm/trunk/lib/Support/Windows/WindowsSupport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/WindowsSupport.h?rev=257415&r1=257414&r2=257415&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/WindowsSupport.h (original)
+++ llvm/trunk/lib/Support/Windows/WindowsSupport.h Mon Jan 11 17:33:03 2016
@@ -48,16 +48,25 @@
#include <vector>
/// 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) {
Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=257415&r1=257414&r2=257415&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Mon Jan 11 17:33:03 2016
@@ -577,7 +577,7 @@ void raw_fd_ostream::write_impl(const ch
// 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 {
More information about the llvm-commits
mailing list