Mercurial > nomad > old-fuse
changeset 101:366635b72c32
Merge branch 'master' of https://github.com/jeffpc/nx01
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sat, 17 Oct 2015 11:51:00 -0400 |
parents | 2fcbd483c1c3 (current diff) 3aea54128fef (diff) |
children | 29867876857f |
files | |
diffstat | 2 files changed, 26 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/README Sat Oct 17 11:48:44 2015 -0400 +++ b/README Sat Oct 17 11:51:00 2015 -0400 @@ -19,7 +19,7 @@ $ make $ make install -This will build and install the binaries and libraries under the specficied +This will build and install the binaries and libraries under the specified prefix.
--- a/src/common/rand.c Sat Oct 17 11:48:44 2015 -0400 +++ b/src/common/rand.c Sat Oct 17 11:51:00 2015 -0400 @@ -1,5 +1,6 @@ /* * Copyright (c) 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> + * Copyright (c) 2015 Holly Sipek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,16 +21,39 @@ * SOFTWARE. */ +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> + #include <nomad/types.h> #include <nomad/rand.h> #include <nomad/config.h> +#include <nomad/error.h> uint32_t rand32(void) { #ifdef HAVE_ARC4RANDOM return arc4random(); #else -#error "Need a way to generate random uint32_t" + uint32_t ret; + int fd; + + fd = open("/dev/random", O_RDONLY); + if (fd == -1) { + fprintf(stderr, "Failed to get random number: %s", + strerror(errno)); + ASSERT(0); + } + + if (read(fd, &ret, sizeof(ret)) != sizeof(ret)) { + fprintf(stderr, "Failed to get random number: %s", + strerror(errno)); + ASSERT(0); + } + + close(fd); + + return ret; #endif }