]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
random: use arc4random where available
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 4 May 2022 14:05:28 +0000 (16:05 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 20 Oct 2022 11:42:52 +0000 (13:42 +0200)
configure.ac
src/random-int.c

index 58a02cceb264674b3f29d46e37f1f10b2954d6c6..a7289af32ba4bd3b21ed98d37dfb8f6cbe91147b 100644 (file)
@@ -44,6 +44,7 @@ AM_CONDITIONAL(WANT_RECEIVESTRIP, test x"$enable_receive_strip" = xyes)
 AC_FUNC_MALLOC
 AC_CHECK_FUNCS([ftruncate memset socket strerror strncasecmp snprintf fcntl])
 AC_CHECK_FUNCS([nanosleep time strftime syslog regcomp regexec])
+AC_CHECK_FUNCS([arc4random_uniform])
 
 AC_CONFIG_FILES([Makefile])
 AC_CONFIG_FILES([src/Makefile])
index de143816a60e3d10cca6978da4324c92039295d4..a0d0770fba22f9a914aee36fef87e34db49876c9 100644 (file)
@@ -30,6 +30,7 @@
 
 int random_int()
 {
+#ifndef HAVE_ARC4RANDOM_UNIFORM
        static int init = 0;
        unsigned int seed;
        int devrandom;
@@ -59,6 +60,9 @@ int random_int()
        init = 1;
 
        return rand();
+#else
+       return arc4random_uniform(INT_MAX);
+#endif
 }
 #if 0
 int main(int argc, char **argv)