Use the BSD arc4random_buf() function which should be non-blocking on
all of these platforms.
Change-Id: Ib43373cad82373dc83995fdb3d01c2a2d43ab683
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
mkdir munmap putenv realpath rmdir socket strchr strcspn strdup \
strncasecmp strndup strnlen strpbrk strrchr strstr strtol strtoul \
strtoull dirfd gethostbyname2 getipnodebyname epoll_create1 \
- sched_getcpu sysconf sync_file_range getrandom posix_fadvise
+ sched_getcpu sysconf sync_file_range getrandom posix_fadvise \
+ arc4random
])
# Check for pthread_setname_np and pthread_getname_np
errno);
}
}
+#elif defined(HAVE_ARC4RANDOM)
+
+#include <stdlib.h>
+
+/*
+ * According to the MacOS / FreeBSD manpage, this function never fails nor blocks.
+ */
+void getrandom_nonblock(char *out_data, std::size_t size)
+{
+ arc4random_buf(out_data, size);
+}
#else /* defined(__linux__) && defined(SYS_getrandom) && defined(HAVE_SYS_RANDOM_H) */
__attribute__((noreturn)) void getrandom_nonblock(char *out_data __attribute__((unused)),
std::size_t size __attribute__((unused)))