22 #ifndef LLVM_SUPPORT_WINDOWSSUPPORT_H
23 #define LLVM_SUPPORT_WINDOWSSUPPORT_H
30 #define _WIN32_WINNT 0x0501
31 #define _WIN32_IE 0x0600 // MinGW at it again.
32 #define WIN32_LEAN_AND_MEAN
37 #include "llvm/Config/config.h"
39 #include <system_error>
46 inline bool MakeErrMsg(std::string* ErrMsg,
const std::string& prefix) {
50 DWORD R = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
51 FORMAT_MESSAGE_FROM_SYSTEM,
52 NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
54 *ErrMsg = prefix + buffer;
56 *ErrMsg = prefix +
"Unknown error";
62 template <
typename HandleTraits>
64 typedef typename HandleTraits::handle_type handle_type;
71 : Handle(HandleTraits::GetInvalid()) {}
77 if (HandleTraits::IsValid(Handle))
78 HandleTraits::Close(Handle);
82 handle_type t = Handle;
83 Handle = HandleTraits::GetInvalid();
88 if (HandleTraits::IsValid(Handle))
89 HandleTraits::Close(Handle);
95 explicit operator bool()
const {
96 return HandleTraits::IsValid(Handle) ?
true :
false;
99 operator handle_type()
const {
108 return INVALID_HANDLE_VALUE;
134 ::CryptReleaseContext(h, 0);
158 class SmallVectorImpl;
161 typename SmallVectorImpl<T>::const_pointer
170 std::error_code
widenPath(
const Twine &Path8,
171 SmallVectorImpl<wchar_t> &Path16);
176 std::error_code
UTF16ToUTF8(
const wchar_t *utf16,
size_t utf16_len,
179 std::error_code
UTF16ToCurCP(
const wchar_t *utf16,
size_t utf16_len,
void push_back(const T &Elt)
static handle_type GetInvalid()
static void Close(handle_type h)
static bool IsValid(handle_type h)
static bool IsValid(handle_type h)
ScopedHandle< JobHandleTraits > ScopedJobHandle
ScopedHandle< CommonHandleTraits > ScopedCommonHandle
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static void Close(handle_type h)
static handle_type GetInvalid()
ScopedHandle(handle_type h)
std::error_code UTF8ToUTF16(StringRef utf8, SmallVectorImpl< wchar_t > &utf16)
ScopedHandle< FindHandleTraits > ScopedFindHandle
std::error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len, SmallVectorImpl< char > &utf8)
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
std::error_code UTF16ToCurCP(const wchar_t *utf16, size_t utf16_len, SmallVectorImpl< char > &utf8)
Convert from UTF16 to the current code page used in the system.
bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix)
pointer data()
Return a pointer to the vector's buffer, even if empty().
ScopedHandle & operator=(handle_type h)
ScopedHandle< FileHandleTraits > ScopedFileHandle
static handle_type GetInvalid()
static void Close(handle_type h)
ScopedHandle< CryptContextTraits > ScopedCryptContext
StringRef - Represent a constant reference to a string, i.e.
std::error_code widenPath(const Twine &Path8, SmallVectorImpl< wchar_t > &Path16)