mirror of
https://gitlab.xiph.org/xiph/ezstream.git
synced 2025-06-30 22:18:27 -04: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 #############
|
dnl #############
|
||||||
|
|
||||||
AC_CHECK_HEADERS([ \
|
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
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
@ -172,7 +172,7 @@ dnl #######################
|
|||||||
|
|
||||||
AC_CHECK_FUNCS([ \
|
AC_CHECK_FUNCS([ \
|
||||||
arc4random \
|
arc4random \
|
||||||
srandomdev \
|
getrandom \
|
||||||
])
|
])
|
||||||
|
|
||||||
AC_REPLACE_FUNCS([ \
|
AC_REPLACE_FUNCS([ \
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#ifdef HAVE_SYS_RANDOM_H
|
||||||
|
# include <sys/random.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
@ -98,10 +101,14 @@ _playlist_random(void)
|
|||||||
|
|
||||||
#ifdef HAVE_ARC4RANDOM
|
#ifdef HAVE_ARC4RANDOM
|
||||||
ret = arc4random();
|
ret = arc4random();
|
||||||
#elif HAVE_RANDOM
|
#elif HAVE_GETRANDOM
|
||||||
ret = (unsigned int)random();
|
if (sizeof(ret) != getrandom(&ret, sizeof(ret), 0)) {
|
||||||
|
log_alert("getrandom: %s", strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
ret = (unsigned int)rand();
|
# warning "using deterministic randomness for shuffling playlists"
|
||||||
|
ret = (unsigned int)random();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
@ -157,15 +164,8 @@ _playlist_run_program(struct playlist *pl)
|
|||||||
int
|
int
|
||||||
playlist_init(void)
|
playlist_init(void)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_RANDOM
|
|
||||||
# ifdef HAVE_SRANDOMDEV
|
|
||||||
srandomdev();
|
|
||||||
# else
|
|
||||||
srandom((unsigned int)time(NULL));
|
srandom((unsigned int)time(NULL));
|
||||||
# endif /* HAVE_SRANDOMDEV */
|
|
||||||
#else
|
|
||||||
srand((unsigned int)time(NULL));
|
|
||||||
#endif /* HAVE_RANDOM */
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user