summaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2014-02-04 14:49:21 +0000
committerAaron Ballman <aaron@aaronballman.com>2014-02-04 14:49:21 +0000
commit8753ba91d28cd0fe7e6767466dec320b1fe2af86 (patch)
treeee4c88dc7727c0d38f5ee1dcf1757fd8df9a0a33 /lib/Support
parent055e70063b4b2de004c489b56ba04d382c47f621 (diff)
downloadllvm-8753ba91d28cd0fe7e6767466dec320b1fe2af86.tar.gz
llvm-8753ba91d28cd0fe7e6767466dec320b1fe2af86.tar.bz2
llvm-8753ba91d28cd0fe7e6767466dec320b1fe2af86.tar.xz
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
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/Process.cpp5
-rw-r--r--lib/Support/Windows/Process.inc7
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp
index d5168f03a6..1360842753 100644
--- a/lib/Support/Process.cpp
+++ b/lib/Support/Process.cpp
@@ -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"
diff --git a/lib/Support/Windows/Process.inc b/lib/Support/Windows/Process.inc
index 750097eecf..16e4092e9f 100644
--- a/lib/Support/Windows/Process.inc
+++ b/lib/Support/Windows/Process.inc
@@ -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;
+}