-
Notifications
You must be signed in to change notification settings - Fork 856
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix server crash due to /dev/urandom
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <random> | ||
#include <unistd.h> | ||
|
||
// TODO(jart): delete this with next cosmocc update | ||
|
||
namespace std { | ||
|
||
random_device::random_device(const string& __token) | ||
{ | ||
if (__token != "/dev/urandom") | ||
__throw_system_error(ENOENT, ("random device not supported " + __token).c_str()); | ||
} | ||
|
||
random_device::~random_device() | ||
{ | ||
} | ||
|
||
unsigned | ||
random_device::operator()() | ||
{ | ||
unsigned r; | ||
size_t n = sizeof(r); | ||
int err = getentropy(&r, n); | ||
if (err) | ||
__throw_system_error(errno, "random_device getentropy failed"); | ||
return r; | ||
} | ||
|
||
double | ||
random_device::entropy() const noexcept | ||
{ | ||
return 0; | ||
} | ||
|
||
} // namespace std |