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
This commit is contained in:
Paolo Carlini 2013-07-22 15:22:52 +00:00 committed by Paolo Carlini
parent ae382ebd8c
commit 94e7477f0c
3 changed files with 16 additions and 1 deletions

View file

@ -1,3 +1,10 @@
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.
2013-07-21 Tim Shen <timshen91@gmail.com>
Partially implement regex_search.

View file

@ -36,7 +36,6 @@
#else
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iosfwd>

View file

@ -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;
}