mirror of https://git.ffmpeg.org/ffmpeg.git
avutil/random_seed: use fread() in read_random()
This ensures the requested amount of bytes is read. Also remove /dev/random as it's no longer necessary. Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
a357758ec5
commit
7a1128ca07
|
@ -49,17 +49,20 @@
|
||||||
static int read_random(uint32_t *dst, const char *file)
|
static int read_random(uint32_t *dst, const char *file)
|
||||||
{
|
{
|
||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
int fd = avpriv_open(file, O_RDONLY);
|
FILE *fp = avpriv_fopen_utf8(file, "r");
|
||||||
int err = -1;
|
size_t err;
|
||||||
|
|
||||||
if (fd == -1)
|
if (!fp)
|
||||||
return -1;
|
return AVERROR_UNKNOWN;
|
||||||
err = read(fd, dst, sizeof(*dst));
|
err = fread(dst, 1, sizeof(*dst), fp);
|
||||||
close(fd);
|
fclose(fp);
|
||||||
|
|
||||||
return err;
|
if (err != sizeof(*dst))
|
||||||
|
return AVERROR_UNKNOWN;
|
||||||
|
|
||||||
|
return 0;
|
||||||
#else
|
#else
|
||||||
return -1;
|
return AVERROR(ENOSYS);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,9 +141,7 @@ uint32_t av_get_random_seed(void)
|
||||||
return arc4random();
|
return arc4random();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (read_random(&seed, "/dev/urandom") == sizeof(seed))
|
if (!read_random(&seed, "/dev/urandom"))
|
||||||
return seed;
|
|
||||||
if (read_random(&seed, "/dev/random") == sizeof(seed))
|
|
||||||
return seed;
|
return seed;
|
||||||
return get_generic_seed();
|
return get_generic_seed();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue