//===----------------------------------------------------------------------===//
#include "llvm/Support/Allocator.h"
+#include <malloc.h>
+// The Windows.h header must be after LLVM and standard headers.
#include "Windows.h"
+
#include <direct.h>
#include <io.h>
-#include <malloc.h>
#include <psapi.h>
-#include <Shellapi.h>
+#include <shellapi.h>
#ifdef __MINGW32__
#if (HAVE_LIBPSAPI != 1)
#error "libshell32.a should be present"
#endif
#else
-#pragma comment(lib, "psapi.lib")
-#pragma comment(lib, "Shell32.lib")
+ #pragma comment(lib, "psapi.lib")
+ #pragma comment(lib, "shell32.lib")
#endif
//===----------------------------------------------------------------------===//
size_t Size = MAX_PATH;
do {
Buf.reserve(Size);
- Size = GetEnvironmentVariableW(&NameUTF16[0], &Buf[0], Buf.capacity());
+ Size =
+ GetEnvironmentVariableW(NameUTF16.data(), Buf.data(), Buf.capacity());
if (Size == 0)
return None;
// Convert the result from UTF-16 to UTF-8.
SmallVector<char, MAX_PATH> Res;
- if (error_code ec = windows::UTF16ToUTF8(&Buf[0], Size, Res))
+ if (error_code ec = windows::UTF16ToUTF8(Buf.data(), Size, Res))
return None;
- return std::string(&Res[0]);
+ return std::string(Res.data());
}
error_code
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColors());
return 0;
}
+
+unsigned Process::GetRandomNumber() {
+ HCRYPTPROV HCPC;
+ if (!::CryptAcquireContextW(&HCPC, NULL, NULL, PROV_RSA_FULL,
+ CRYPT_VERIFYCONTEXT))
+ assert(false && "Could not acquire a cryptographic context");
+
+ ScopedCryptContext CryptoProvider(HCPC);
+ unsigned Ret;
+ if (!::CryptGenRandom(CryptoProvider, sizeof(Ret),
+ reinterpret_cast<BYTE *>(&Ret)))
+ assert(false && "Could not generate a random number");
+ return Ret;
+}