diff options
Diffstat (limited to 'libcxx/src/random.cpp')
| -rw-r--r-- | libcxx/src/random.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/libcxx/src/random.cpp b/libcxx/src/random.cpp index 21e21689a87..86017ef0d46 100644 --- a/libcxx/src/random.cpp +++ b/libcxx/src/random.cpp @@ -62,7 +62,22 @@ unsigned random_device::operator()() { unsigned r; - read(__f_, &r, sizeof(r)); + size_t n = sizeof(r); + char* p = reinterpret_cast<char*>(&r); + while (n > 0) + { + ssize_t s = read(__f_, p, n); + if (s == 0) + __throw_system_error(ENODATA, "random_device got EOF"); + if (s == -1) + { + if (errno != EINTR) + __throw_system_error(errno, "random_device got an unexpected error"); + continue; + } + n -= static_cast<size_t>(s); + p += static_cast<size_t>(s); + } return r; } #endif // defined(_WIN32) |

