Split out rand

This commit is contained in:
Ian Gulliver
2016-02-22 14:45:18 -08:00
parent f255170967
commit 16685b8d05
6 changed files with 37 additions and 28 deletions

22
adsbus/rand.c Normal file
View File

@@ -0,0 +1,22 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
#include <unistd.h>
#include "rand.h"
static int rand_fd;
void rand_init() {
rand_fd = open("/dev/urandom", O_RDONLY);
assert(rand_fd >= 0);
}
void rand_cleanup() {
assert(!close(rand_fd));
}
void rand_fill(void *value, size_t size) {
assert(read(rand_fd, value, size) == size);
}