mirror of
https://gitlab.xiph.org/xiph/ezstream.git
synced 2024-11-03 04:17:18 -05:00
Retire rand() in favor of the upcoming getrandom() on Linux
Only the non-getrandom() code paths have been tested at this point.
This commit is contained in:
parent
8499362ce6
commit
aaa32bf812
@ -106,7 +106,7 @@ dnl ## HEADERS #########################################################
|
||||
dnl #############
|
||||
|
||||
AC_CHECK_HEADERS([ \
|
||||
sys/time.h libgen.h paths.h \
|
||||
sys/random.h sys/time.h libgen.h paths.h \
|
||||
], [], [],
|
||||
[
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
@ -172,7 +172,7 @@ dnl #######################
|
||||
|
||||
AC_CHECK_FUNCS([ \
|
||||
arc4random \
|
||||
srandomdev \
|
||||
getrandom \
|
||||
])
|
||||
|
||||
AC_REPLACE_FUNCS([ \
|
||||
|
@ -19,6 +19,9 @@
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#ifdef HAVE_SYS_RANDOM_H
|
||||
# include <sys/random.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
@ -98,10 +101,14 @@ _playlist_random(void)
|
||||
|
||||
#ifdef HAVE_ARC4RANDOM
|
||||
ret = arc4random();
|
||||
#elif HAVE_RANDOM
|
||||
ret = (unsigned int)random();
|
||||
#elif HAVE_GETRANDOM
|
||||
if (sizeof(ret) != getrandom(&ret, sizeof(ret), 0)) {
|
||||
log_alert("getrandom: %s", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
ret = (unsigned int)rand();
|
||||
# warning "using deterministic randomness for shuffling playlists"
|
||||
ret = (unsigned int)random();
|
||||
#endif
|
||||
|
||||
return (ret);
|
||||
@ -157,15 +164,8 @@ _playlist_run_program(struct playlist *pl)
|
||||
int
|
||||
playlist_init(void)
|
||||
{
|
||||
#ifdef HAVE_RANDOM
|
||||
# ifdef HAVE_SRANDOMDEV
|
||||
srandomdev();
|
||||
# else
|
||||
srandom((unsigned int)time(NULL));
|
||||
# endif /* HAVE_SRANDOMDEV */
|
||||
#else
|
||||
srand((unsigned int)time(NULL));
|
||||
#endif /* HAVE_RANDOM */
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user