diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2013-07-22 15:22:52 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2013-07-22 15:22:52 +0000 |
commit | 94e7477f0cb3a9b7d0523d2c2fbf039ab19cf081 (patch) | |
tree | 5a680837da70bd375bf6a218dbb0ae584a14fbcc /libstdc++-v3/src | |
parent | ae382ebd8cbd04ae9d6bd24507b307f00d7ff5b4 (diff) | |
download | gcc-94e7477f0cb3a9b7d0523d2c2fbf039ab19cf081.zip gcc-94e7477f0cb3a9b7d0523d2c2fbf039ab19cf081.tar.gz gcc-94e7477f0cb3a9b7d0523d2c2fbf039ab19cf081.tar.bz2 |
re PR libstdc++/57920 ([c++11] Linux: std::random_device reads too much from /dev/urandom)
2013-07-22 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/57920
* src/c++11/random.cc (random_device::_M_getval): If possible, use
read instead of std::fread.
* include/std/random: Do not include <cstdio> unnecessarily.
From-SVN: r201133
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r-- | libstdc++-v3/src/c++11/random.cc | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libstdc++-v3/src/c++11/random.cc b/libstdc++-v3/src/c++11/random.cc index 2bd7132..1646786 100644 --- a/libstdc++-v3/src/c++11/random.cc +++ b/libstdc++-v3/src/c++11/random.cc @@ -30,6 +30,11 @@ # include <cpuid.h> #endif +#include <cstdio> + +#ifdef _GLIBCXX_HAVE_UNISTD_H +# include <unistd.h> +#endif namespace std _GLIBCXX_VISIBILITY(default) { @@ -126,8 +131,12 @@ namespace std _GLIBCXX_VISIBILITY(default) #endif result_type __ret; +#ifdef _GLIBCXX_HAVE_UNISTD_H + read(fileno(_M_file), reinterpret_cast<void*>(&__ret), sizeof(result_type)); +#else std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type), 1, _M_file); +#endif return __ret; } |