Accomodate OpenBSD with /dev/srandom

This commit is contained in:
rsc 2005-08-11 03:20:57 +00:00
parent bce0902a07
commit fea3228fec

View file

@ -10,10 +10,12 @@ truerand(void)
if(randfd < 0){ if(randfd < 0){
randfd = open("/dev/random", OREAD); randfd = open("/dev/random", OREAD);
fcntl(randfd, F_SETFD, FD_CLOEXEC); if(randfd < 0)
} randfd = open("/dev/srandom", OREAD); /* OpenBSD */
if(randfd < 0) if(randfd < 0)
sysfatal("can't open /dev/random: %r"); sysfatal("can't open /dev/random: %r");
fcntl(randfd, F_SETFD, FD_CLOEXEC);
}
for(i=0; i<sizeof(buf); i += n) for(i=0; i<sizeof(buf); i += n)
if((n = readn(randfd, buf+i, sizeof(buf)-i)) < 0) if((n = readn(randfd, buf+i, sizeof(buf)-i)) < 0)
sysfatal("can't read /dev/random: %r"); sysfatal("can't read /dev/random: %r");