summaryrefslogtreecommitdiffstats
path: root/src/random.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2014-01-29 19:30:27 +0000
committerdim <dim@FreeBSD.org>2014-01-29 19:30:27 +0000
commitc3e10da3dc0f616b78ccf85206fdcf4c92f8ac85 (patch)
tree5812a629bd48b0968dee7411809c6a6a19680390 /src/random.cpp
parent30a0ccc9e6a2233c7d9f03028880be3e205fd7d1 (diff)
downloadFreeBSD-src-c3e10da3dc0f616b78ccf85206fdcf4c92f8ac85.zip
FreeBSD-src-c3e10da3dc0f616b78ccf85206fdcf4c92f8ac85.tar.gz
Vendor import of libc++ tags/RELEASE_34/final r197960:
https://llvm.org/svn/llvm-project/libcxx/tags/RELEASE_34/final@197960
Diffstat (limited to 'src/random.cpp')
-rw-r--r--src/random.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/random.cpp b/src/random.cpp
index 97a40c5..bd24f2e 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -7,18 +7,45 @@
//
//===----------------------------------------------------------------------===//
+#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"
#ifdef __sun__
#define rename solaris_headers_are_broken
#endif
+#if !defined(_WIN32)
#include <fcntl.h>
#include <unistd.h>
+#endif // defined(_WIN32)
#include <errno.h>
_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 +65,7 @@ random_device::operator()()
read(__f_, &r, sizeof(r));
return r;
}
+#endif // defined(_WIN32)
double
random_device::entropy() const _NOEXCEPT
OpenPOWER on IntegriCloud