summaryrefslogtreecommitdiffstats
path: root/libcxx/src/random.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Add support for arc4random() to random_device.Ed Schouten2015-03-101-35/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | Nuxi CloudABI (https://github.com/NuxiNL/cloudlibc) does not allow processes to access the global filesystem namespace. This breaks random_device, as it attempts to use /dev/{u,}random. This change adds support for arc4random(), which is present on CloudABI. In my opinion it would also make sense to use arc4random() on other operating systems, such as *BSD and Mac OS X, but I'd rather leave that to the maintainers of the respective platforms. Switching to arc4random() does change the ABI. This change also attempts to make some cleanups to the code. It adds a single #define for every random interface, instead of testing against operating systems explicitly. As discussed, also validate the token argument to be equal to "/dev/urandom" on all systems that only provide pseudo-random numbers. This should cause little to no breakage, as "/dev/urandom" is also the default argument value. Reviewed by: jfb Differential Revision: http://reviews.llvm.org/D8134 llvm-svn: 231764
* libc++: remove unused variable in random_device::operator()()JF Bastien2015-02-041-1/+0
| | | | | | | | | | Reviewers: jvoung Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D7416 llvm-svn: 228183
* libc++: add NaCl and PNaCl support for std::random_deviceJF Bastien2014-12-011-6/+43
| | | | | | | | | | | | | | | | | Summary: The NaCl sandbox doesn't allow opening files under /dev, but it offers an API which provides the same capabilities. This is the same random device emulation that nacl_io performs for POSIX support, but nacl_io is an optional library so libc++ can't assume that device emulation will be performed. Note that NaCl only supports /dev/urandom, not /dev/random. This patch also cleans up some of the preprocessor #endif, and fixes the test for Win32 (it accepts any token, and would therefore never throw regardless of the token provided). Test Plan: ninja check-libcxx Reviewers: dschuff, mclow.lists, danalbert Subscribers: jfb, cfe-commits Differential Revision: http://reviews.llvm.org/D6442 llvm-svn: 223068
* [libc++] Don't return uninitialized data from random_device::operator()David Majnemer2014-06-031-1/+16
| | | | | | | | | | Make sure we appropriately retry calls to read if the return result is less than what we asked for. Additionally, check and handle IO errors: EINTR results in the read operation getting restarted; other errors turn into exceptions. llvm-svn: 210061
* [libc++] random_device fails if open returns zeroDavid Majnemer2014-06-031-1/+1
| | | | | | | | | | | | | random_device::random_device(const string&) wrongly assumes that open can only validly return a file descriptor greater than zero. This results in random_device believing that it didn't successfully open the device causing it to throw in it's constructor, this ends up leaking a file descriptor. The fix is simple, don't error on file descriptors which are zero. llvm-svn: 210060
* G M suggestion: conditionally include files on _WIN32.Yaron Keren2013-11-181-0/+2
| | | | llvm-svn: 195045
* patch by Yaron: Uses rand_s() from stdlib.h (when building for Windows)Marshall Clow2013-10-091-0/+26
| | | | llvm-svn: 192325
* noexcept applied to <random>.Howard Hinnant2012-07-201-1/+1
| | | | llvm-svn: 160579
* Solaris port. Currently sees around 200 test failures, mostly related toDavid Chisnall2012-02-291-0/+3
| | | | | | | | | | Solaris not providing some of the locales that the test suite uses. Note: This depends on an xlocale (partial) implementation for Solaris and a couple of fixed standard headers. These will be committed to a branch later today. llvm-svn: 151720
* license changeHoward Hinnant2010-11-161-2/+2
| | | | llvm-svn: 119395
* Fixing whitespace problemsHoward Hinnant2010-08-221-1/+0
| | | | llvm-svn: 111751
* Wiped out some non-ascii characters that snuck into the copyright.Howard Hinnant2010-05-111-1/+1
| | | | llvm-svn: 103516
* libcxx initial importHoward Hinnant2010-05-111-0/+46
llvm-svn: 103490
OpenPOWER on IntegriCloud