aboutsummaryrefslogtreecommitdiff
path: root/system/lib/libcxx/random.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-01-17 14:08:09 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-01-17 14:08:09 -0800
commit76ddb8091266741ae046d1b6fdeef4f782617d5b (patch)
tree21fc75bfcbdce916ab91b8a61d196ab059e082d3 /system/lib/libcxx/random.cpp
parent8a9fa2c6d739a53221ee717121c6f4d318abd3dd (diff)
libc++ sources
Diffstat (limited to 'system/lib/libcxx/random.cpp')
-rw-r--r--system/lib/libcxx/random.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/system/lib/libcxx/random.cpp b/system/lib/libcxx/random.cpp
new file mode 100644
index 00000000..eca97bc8
--- /dev/null
+++ b/system/lib/libcxx/random.cpp
@@ -0,0 +1,45 @@
+//===-------------------------- 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"
+
+#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