summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/src/random.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libc++/src/random.cpp')
-rw-r--r--contrib/libc++/src/random.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/contrib/libc++/src/random.cpp b/contrib/libc++/src/random.cpp
new file mode 100644
index 0000000..6140b74
--- /dev/null
+++ b/contrib/libc++/src/random.cpp
@@ -0,0 +1,48 @@
+//===-------------------------- random.cpp --------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "random"
+#include "system_error"
+
+#ifdef __sun__
+#define rename solaris_headers_are_broken
+#endif
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+random_device::random_device(const string& __token)
+ : __f_(open(__token.c_str(), O_RDONLY))
+{
+ if (__f_ <= 0)
+ __throw_system_error(errno, ("random_device failed to open " + __token).c_str());
+}
+
+random_device::~random_device()
+{
+ close(__f_);
+}
+
+unsigned
+random_device::operator()()
+{
+ unsigned r;
+ read(__f_, &r, sizeof(r));
+ return r;
+}
+
+double
+random_device::entropy() const
+{
+ return 0;
+}
+
+_LIBCPP_END_NAMESPACE_STD
OpenPOWER on IntegriCloud