in src/pal/pal_posix.h [368:409]
static uint64_t dev_urandom()
{
union
{
uint64_t result;
char buffer[sizeof(uint64_t)];
};
ssize_t ret;
int flags = O_RDONLY;
#if defined(O_CLOEXEC)
flags |= O_CLOEXEC;
#endif
auto fd = open("/dev/urandom", flags, 0);
if (fd > 0)
{
auto current = std::begin(buffer);
auto target = std::end(buffer);
while (auto length = static_cast<size_t>(target - current))
{
ret = read(fd, current, length);
if (ret <= 0)
{
if (errno != EAGAIN && errno != EINTR)
{
break;
}
}
else
{
current += ret;
}
}
ret = close(fd);
SNMALLOC_ASSERT(0 == ret);
if (SNMALLOC_LIKELY(target == current))
{
return result;
}
}
error("Failed to get system randomness");
}