8 uchar buf[sizeof(ulong)];
9 static int randfd = -1;
10 static char *randfile;
13 randfd = open(randfile="/dev/random", OREAD);
14 /* OpenBSD lets you open /dev/random but not read it! */
15 if(randfd < 0 || read(randfd, buf, 1) != 1)
16 randfd = open(randfile="/dev/srandom", OREAD); /* OpenBSD */
18 sysfatal("can't open %s: %r", randfile);
19 fcntl(randfd, F_SETFD, FD_CLOEXEC);
21 for(i=0; i<sizeof(buf); i += n)
22 if((n = readn(randfd, buf+i, sizeof(buf)-i)) < 0)
23 sysfatal("can't read %s: %r", randfile);
24 return *((ulong*)buf);