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