22 #ifndef LLVM_SUPPORT_WINDOWSSUPPORT_H 23 #define LLVM_SUPPORT_WINDOWSSUPPORT_H 30 #define _WIN32_WINNT 0x0601 31 #define _WIN32_IE 0x0800 // MinGW at it again. FIXME: verify if still needed. 32 #define WIN32_LEAN_AND_MEAN 37 #include "llvm/SmallVector.h" 38 #include "llvm/StringExtras.h" 39 #include "llvm/StringRef.h" 40 #include "llvm/Twine.h" 41 #include "llvm/Compiler.h" 42 #include <system_error> 51 inline bool RunningWindows8OrGreater() {
53 OSVERSIONINFOEXW osvi = {};
54 osvi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
55 osvi.dwMajorVersion = 6;
56 osvi.dwMinorVersion = 2;
57 osvi.wServicePackMajor = 0;
60 Mask = VerSetConditionMask(Mask, VER_MAJORVERSION, VER_GREATER_EQUAL);
61 Mask = VerSetConditionMask(Mask, VER_MINORVERSION, VER_GREATER_EQUAL);
62 Mask = VerSetConditionMask(Mask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
64 return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION |
69 inline bool MakeErrMsg(std::string *ErrMsg,
const std::string &prefix) {
73 DWORD LastError = GetLastError();
74 DWORD R = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
75 FORMAT_MESSAGE_FROM_SYSTEM |
76 FORMAT_MESSAGE_MAX_WIDTH_MASK,
77 NULL, LastError, 0, (LPSTR)&buffer, 1, NULL);
79 *ErrMsg = prefix +
": " + buffer;
81 *ErrMsg = prefix +
": Unknown error";
82 *ErrMsg +=
" (0x" + llvm::utohexstr(LastError) +
")";
88 template <
typename HandleTraits>
90 typedef typename HandleTraits::handle_type handle_type;
97 : Handle(HandleTraits::GetInvalid()) {}
103 if (HandleTraits::IsValid(Handle))
104 HandleTraits::Close(Handle);
108 handle_type t = Handle;
109 Handle = HandleTraits::GetInvalid();
114 if (HandleTraits::IsValid(Handle))
115 HandleTraits::Close(Handle);
121 explicit operator bool()
const {
122 return HandleTraits::IsValid(Handle) ?
true :
false;
125 operator handle_type()
const {
131 typedef HANDLE handle_type;
133 static handle_type GetInvalid() {
134 return INVALID_HANDLE_VALUE;
137 static void Close(handle_type h) {
141 static bool IsValid(handle_type h) {
142 return h != GetInvalid();
147 static handle_type GetInvalid() {
153 typedef HKEY handle_type;
155 static handle_type GetInvalid() {
159 static void Close(handle_type h) {
163 static bool IsValid(handle_type h) {
164 return h != GetInvalid();
169 static void Close(handle_type h) {
187 typename SmallVectorImpl<T>::const_pointer
196 std::error_code widenPath(
const Twine &Path8,
202 std::error_code UTF16ToUTF8(
const wchar_t *utf16,
size_t utf16_len,
205 std::error_code UTF16ToCurCP(
const wchar_t *utf16,
size_t utf16_len,
Definition: WindowsSupport.h:152
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
Definition: WindowsSupport.h:89
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: WindowsSupport.h:184
Definition: WindowsSupport.h:146
Definition: WindowsSupport.h:168
Definition: WindowsSupport.h:130
Definition: WindowsSupport.h:174
pointer data()
Return a pointer to the vector's buffer, even if empty().
Definition: SmallVector.h:134
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42