Client implementation of the 9P protocol for constrained devices
git clone https://git.8pit.net/ninenano.git
1#include <stdlib.h> 2#include <stdint.h> 3#include <fcntl.h> 4#include <unistd.h> 5#include <assert.h> 6 7#include <sys/stat.h> 8#include <sys/types.h> 910#include "9util.h"1112void13initrand(void)14{15 uint8_t seed;16 int fd;1718 /* If we can't read from /dev/random we will use a hardcode19 * value for seeding which not optimal but sufficient. */2021 if ((fd = open("/dev/random", O_RDONLY)) == -1) {22 seed = 23;23 goto srand;24 }2526 if (read(fd, &seed, 1) != 1)27 seed = 42;28 close(fd);2930srand:31 srand(seed);32}3334uint32_t35randu32(void)36{37 int ret;3839 /* From rand(3):40 * The rand() function returns a result in the range of 0 to41 * `RAND_MAX`.42 */43 ret = rand();44 assert(ret >= 0);4546 return (uint32_t)rand();47}