mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-11 11:34:02 +00:00
Using the helper API for random number generation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201125 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
91b585bccc
commit
bec3b4865e
@ -15,6 +15,7 @@
|
|||||||
#include "llvm/Support/Endian.h"
|
#include "llvm/Support/Endian.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
|
#include "llvm/Support/Process.h"
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Unix.h"
|
#include "Unix.h"
|
||||||
#include "llvm/Support/Process.h"
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#if HAVE_SYS_STAT_H
|
#if HAVE_SYS_STAT_H
|
||||||
|
@ -112,25 +112,13 @@ static error_code createUniqueEntity(const Twine &model, int &result_fd,
|
|||||||
// needed if the randomly chosen path already exists.
|
// needed if the randomly chosen path already exists.
|
||||||
SmallVector<wchar_t, 128> random_path_utf16;
|
SmallVector<wchar_t, 128> random_path_utf16;
|
||||||
|
|
||||||
// Get a Crypto Provider for CryptGenRandom.
|
|
||||||
HCRYPTPROV HCPC;
|
|
||||||
if (!::CryptAcquireContextW(&HCPC,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
PROV_RSA_FULL,
|
|
||||||
CRYPT_VERIFYCONTEXT))
|
|
||||||
return windows_error(::GetLastError());
|
|
||||||
ScopedCryptContext CryptoProvider(HCPC);
|
|
||||||
|
|
||||||
retry_random_path:
|
retry_random_path:
|
||||||
random_path_utf16.set_size(0);
|
random_path_utf16.set_size(0);
|
||||||
for (SmallVectorImpl<wchar_t>::const_iterator i = model_utf16.begin(),
|
for (SmallVectorImpl<wchar_t>::const_iterator i = model_utf16.begin(),
|
||||||
e = model_utf16.end();
|
e = model_utf16.end();
|
||||||
i != e; ++i) {
|
i != e; ++i) {
|
||||||
if (*i == L'%') {
|
if (*i == L'%') {
|
||||||
BYTE val = 0;
|
unsigned val = sys::Process::GetRandomNumber();
|
||||||
if (!::CryptGenRandom(CryptoProvider, 1, &val))
|
|
||||||
return windows_error(::GetLastError());
|
|
||||||
random_path_utf16.push_back(L"0123456789abcdef"[val & 15]);
|
random_path_utf16.push_back(L"0123456789abcdef"[val & 15]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user