aboutsummaryrefslogtreecommitdiff
path: root/system/lib/libcxx/random.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-11-08 16:01:27 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-11-08 16:04:05 -0800
commitb873dc778f52461129b1e28fb12dd3d4a309851c (patch)
treee82913bc549a83104ce8abfb518eca6cb6d8aa83 /system/lib/libcxx/random.cpp
parent140ea9e81feb09d8f2559995c73d49a39424ef5d (diff)
parente0268fa1035a718341c53921eee9318d4a8033cd (diff)
Merge branch 'incoming' into f32
Conflicts: src/parseTools.js src/preamble.js
Diffstat (limited to 'system/lib/libcxx/random.cpp')
-rw-r--r--system/lib/libcxx/random.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/system/lib/libcxx/random.cpp b/system/lib/libcxx/random.cpp
index 97a40c50..47cdee40 100644
--- a/system/lib/libcxx/random.cpp
+++ b/system/lib/libcxx/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