mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 04:30:23 +00:00
Implemented support for Process::GetRandomNumber on Windows.
Patch thanks to Stephan Tolksdorf! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200767 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
055e70063b
commit
8753ba91d2
@ -12,6 +12,11 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Config/config.h"
|
||||
#if LLVM_ON_WIN32
|
||||
// This define makes stdlib.h declare the rand_s function.
|
||||
#define _CRT_RAND_S
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
|
||||
|
@ -360,3 +360,10 @@ const char *Process::ResetColor() {
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColors());
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned Process::GetRandomNumber() {
|
||||
unsigned int result;
|
||||
const errno_t ec = rand_s(&result);
|
||||
assert(ec == 0 && "rand_s failed");
|
||||
return result;
|
||||
}
|
||||
|
@ -39,6 +39,13 @@ TEST(ProcessTest, SelfProcess) {
|
||||
EXPECT_GT(TimeValue::MaxTime, process::get_self()->get_wall_time());
|
||||
}
|
||||
|
||||
TEST(ProcessTest, GetRandomNumberTest) {
|
||||
const unsigned r1 = Process::GetRandomNumber();
|
||||
const unsigned r2 = Process::GetRandomNumber();
|
||||
// It should be extremely unlikely that both r1 and r2 are 0.
|
||||
EXPECT_NE((r1 | r2), 0);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define setenv(name, var, ignore) _putenv_s(name, var)
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user