From d693d4a0086f84daaea6b091e7be80d4a08eb413 Mon Sep 17 00:00:00 2001 From: xanimo Date: Fri, 19 May 2023 10:14:35 +0100 Subject: [PATCH] random: getentropy on macOS does not need unistd.h change sys/random.h to random.h in AC_MSG_CHECK remove definitions that are applicable to macos which include unistd.h additionally change comparator argument from NULL to nullptr when evaluating &getentropy Inspired by: c13c97dbf846cf0e6a5581ac414ef96a215b0dc6 --- configure.ac | 4 ++-- src/random.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index fe7a63c00..dab2cecb4 100644 --- a/configure.ac +++ b/configure.ac @@ -655,8 +655,8 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [ AC_MSG_RESULT(no)] ) -AC_MSG_CHECKING(for getentropy via random.h) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include +AC_MSG_CHECKING([for getentropy via sys/random.h]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include ]], [[ getentropy(nullptr, 32) ]])], [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GETENTROPY_RAND, 1,[Define this symbol if the BSD getentropy system call is available with sys/random.h]) ], diff --git a/src/random.cpp b/src/random.cpp index 766934d0b..0243511ff 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -25,7 +25,7 @@ #include #include #endif -#if defined(HAVE_GETENTROPY) || (defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)) +#if defined(HAVE_GETENTROPY) #include #endif #if defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) @@ -169,7 +169,7 @@ void GetOSRand(unsigned char *ent32) } #elif defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) // We need a fallback for OSX < 10.12 - if (&getentropy != NULL) { + if (&getentropy != nullptr) { if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) { RandFailure(); }