1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
--- gcc-5-branch/libstdc++-v3/src/c++11/random.cc 2015/10/02 19:43:41 228418
+++ gcc-5-branch/libstdc++-v3/src/c++11/random.cc 2015/10/02 20:08:04 228419
@@ -31,6 +31,7 @@
# include <cpuid.h>
#endif
+#include <cerrno>
#include <cstdio>
#ifdef _GLIBCXX_HAVE_UNISTD_H
@@ -130,13 +131,27 @@
#endif
result_type __ret;
+ void* p = &__ret;
+ size_t n = sizeof(result_type);
#ifdef _GLIBCXX_HAVE_UNISTD_H
- read(fileno(static_cast<FILE*>(_M_file)),
- static_cast<void*>(&__ret), sizeof(result_type));
+ do
+ {
+ const int e = read(fileno(static_cast<FILE*>(_M_file)), p, n);
+ if (e > 0)
+ {
+ n -= e;
+ p = static_cast<char*>(p) + e;
+ }
+ else if (e != -1 || errno != EINTR)
+ __throw_runtime_error(__N("random_device could not be read"));
+ }
+ while (n > 0);
#else
- std::fread(static_cast<void*>(&__ret), sizeof(result_type),
- 1, static_cast<FILE*>(_M_file));
+ const size_t e = std::fread(p, n, 1, static_cast<FILE*>(_M_file));
+ if (e != 1)
+ __throw_runtime_error(__N("random_device could not be read"));
#endif
+
return __ret;
}
|