37 lines
793 B
C++
37 lines
793 B
C++
|
#include <assert.h>
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
static FILE* randfp = nullptr;
|
||
|
|
||
|
void close_randfp()
|
||
|
{
|
||
|
fclose(randfp);
|
||
|
}
|
||
|
|
||
|
extern "C"
|
||
|
{
|
||
|
int rand() // FIXME: This function is a dirty and extremely hacky way to get going, /dev/random should only be used
|
||
|
// for initial seeding, userspace should do their own random calculations.
|
||
|
{
|
||
|
if (!randfp)
|
||
|
{
|
||
|
randfp = fopen("/dev/random", "rw");
|
||
|
assert(randfp != nullptr);
|
||
|
atexit(close_randfp);
|
||
|
}
|
||
|
int result;
|
||
|
fread(&result, sizeof(result), 1, randfp);
|
||
|
if (ferror(randfp))
|
||
|
{
|
||
|
perror("read(randfp)");
|
||
|
abort();
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
void srand(unsigned int)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
}
|