From 174378d4c6a712f57bf900a377714fef39afb51e Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Mon, 31 Aug 2015 15:06:21 +0200 Subject: [PATCH] Port to CloudABI. CloudABI does not provide access to the global filesystem namespace. We can simply call into arc4random_buf() to get high-quality random data. --- src/random_device.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/random_device.cpp b/src/random_device.cpp index e80c9fa01e..6e2ba1a091 100644 --- a/src/random_device.cpp +++ b/src/random_device.cpp @@ -147,6 +147,29 @@ class boost::random::random_device::impl const std::string provider; }; +#elif defined(__CloudABI__) + +#include + +namespace { +const char * const default_token = ""; +} + +// CloudABI does not provide access to the global filesystem namespace. +// The only way to obtain random data is by calling arcrandom_buf(). +class boost::random::random_device::impl +{ +public: + impl(const std::string & token) {} + ~impl() {} + + unsigned int next() { + unsigned int result; + arc4random_buf(&result, sizeof(result)); + return result; + } +}; + #else namespace {