Mercurial > libavutil.hg
comparison random_seed.c @ 964:08c117c60753 libavutil
random_seed: allow to block on /dev/random
If both /dev/random and /dev/urandom failed to return data, an
uninitialised value might be returned. Since most systems have a
non-blocking /dev/urandom or have /dev/random with similar properties,
the chance of blocking is minimal, and the alternative of returning
non-random data is worse.
author | mru |
---|---|
date | Thu, 01 Jul 2010 11:40:50 +0000 |
parents | 2894d4c208dc |
children | 2acd85ae41ca |
comparison
equal
deleted
inserted
replaced
963:bb7159d1f769 | 964:08c117c60753 |
---|---|
29 int fd = open(file, O_RDONLY); | 29 int fd = open(file, O_RDONLY); |
30 int err = -1; | 30 int err = -1; |
31 | 31 |
32 if (fd == -1) | 32 if (fd == -1) |
33 return -1; | 33 return -1; |
34 #if HAVE_FCNTL && defined(O_NONBLOCK) | |
35 if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) != -1) | |
36 #endif | |
37 err = read(fd, dst, sizeof(*dst)); | 34 err = read(fd, dst, sizeof(*dst)); |
38 close(fd); | 35 close(fd); |
39 | 36 |
40 return err; | 37 return err; |
41 } | 38 } |