ggentropy

A string formatting library for C++
Log | Files | Refs | README

commit c1e7427c62082f894c7502ab946da0847152aa87
parent e9f417c6067dfa9f1d7ea59ec6c8a8081fd241df
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu,  9 Jul 2020 13:00:24 +0300

Use getentropy on MacOS

Diffstat:
Mggentropy.cpp | 19++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/ggentropy.cpp b/ggentropy.cpp @@ -18,21 +18,29 @@ #if defined( _WIN32 ) # define PLATFORM_WINDOWS 1 + #elif defined( __linux__ ) # define PLATFORM_LINUX 1 # define PLATFORM_HAS_URANDOM 1 + #elif defined( __APPLE__ ) -# define PLATFORM_HAS_URANDOM 1 +# define PLATFORM_MACOS 1 + #elif defined( __FreeBSD__ ) # define PLATFORM_HAS_ARC4RANDOM 1 + #elif defined( __OpenBSD__ ) # define PLATFORM_HAS_ARC4RANDOM 1 + #elif defined( __NetBSD__ ) # define PLATFORM_HAS_ARC4RANDOM 1 + #elif defined( __sun ) # define PLATFORM_HAS_URANDOM 1 + #else # error new platform + #endif #include <assert.h> @@ -97,6 +105,15 @@ bool ggentropy( void * buf, size_t n ) { return try_urandom( buf, n ); } +#elif PLATFORM_MACOS + +#include <sys/random.h> + +bool ggentropy( void * buf, size_t n ) { + assert( n <= 256 ); + return getentropy( buf, n ) == 0; +} + #elif PLATFORM_HAS_URANDOM bool ggentropy( void * buf, size_t n ) {