summaryrefslogtreecommitdiffstats
path: root/libcxx/src/random.cpp
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2013-10-09 21:49:03 +0000
committerMarshall Clow <mclow.lists@gmail.com>2013-10-09 21:49:03 +0000
commit0354b92992a537330e67d280cf65a232a8ea1119 (patch)
treeb51cd254b48db22c68d40053ceeb1228620a565e /libcxx/src/random.cpp
parentc665c9ecf446092cab5af76f48a72f5dc6480e5c (diff)
downloadbcm5719-llvm-0354b92992a537330e67d280cf65a232a8ea1119.tar.gz
bcm5719-llvm-0354b92992a537330e67d280cf65a232a8ea1119.zip
patch by Yaron: Uses rand_s() from stdlib.h (when building for Windows)
llvm-svn: 192325
Diffstat (limited to 'libcxx/src/random.cpp')
-rw-r--r--libcxx/src/random.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/libcxx/src/random.cpp b/libcxx/src/random.cpp
index 97a40c509dc..47cdee402b7 100644
--- a/libcxx/src/random.cpp
+++ b/libcxx/src/random.cpp
@@ -7,6 +7,12 @@
//
//===----------------------------------------------------------------------===//
+#if defined(_WIN32)
+// Must be defined before including stdlib.h to enable rand_s().
+#define _CRT_RAND_S
+#include <stdio.h>
+#endif
+
#include "random"
#include "system_error"
@@ -19,6 +25,25 @@
_LIBCPP_BEGIN_NAMESPACE_STD
+#if defined(_WIN32)
+random_device::random_device(const string&)
+{
+}
+
+random_device::~random_device()
+{
+}
+
+unsigned
+random_device::operator()()
+{
+ unsigned r;
+ errno_t err = rand_s(&r);
+ if (err)
+ __throw_system_error(err, "random_device rand_s failed.");
+ return r;
+}
+#else
random_device::random_device(const string& __token)
: __f_(open(__token.c_str(), O_RDONLY))
{
@@ -38,6 +63,7 @@ random_device::operator()()
read(__f_, &r, sizeof(r));
return r;
}
+#endif // defined(_WIN32)
double
random_device::entropy() const _NOEXCEPT
OpenPOWER on IntegriCloud