From e62a2fa4a3468821ac0f38e5d0ff9ff5e87729da Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Tue, 23 Mar 2021 17:21:41 +0200
Subject: [PATCH 34/34] randseed.c: Include <sys/random.h>

This fixes OSX build.

See osdn #41838

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 configure.ac                     | 2 ++
 gen_headers/meson_fc_config.h.in | 3 +++
 meson.build                      | 1 +
 utility/randseed.c               | 3 +++
 4 files changed, 9 insertions(+)

diff --git a/configure.ac b/configure.ac
index 50cee8ea82..03803bc834 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1441,6 +1441,8 @@ AC_CHECK_FUNCS([backtrace setenv putenv])
 dnl Possible random sources on Unixen
 AC_CHECK_FUNCS([getentropy clock_gettime])
 
+AC_CHECK_HEADERS([sys/random.h])
+
 dnl TODO: Reimplement this check, in a cross-compiling friendly way
 dnl AC_CHECK_FILES([/dev/urandom])
 
diff --git a/gen_headers/meson_fc_config.h.in b/gen_headers/meson_fc_config.h.in
index 6f1a822402..00d42a36ba 100644
--- a/gen_headers/meson_fc_config.h.in
+++ b/gen_headers/meson_fc_config.h.in
@@ -112,6 +112,9 @@
 /* sys/ioctl.h available */
 #mesondefine HAVE_SYS_IOCTL_H
 
+/* sys/random.h available */
+#mesondefine HAVE_SYS_RANDOM_H
+
 /* sys/signal.h available */
 #mesondefine HAVE_SYS_SIGNAL_H
 
diff --git a/meson.build b/meson.build
index 9096d615fd..6e9aa1241c 100644
--- a/meson.build
+++ b/meson.build
@@ -78,6 +78,7 @@ priv_headers = [
   'string.h',
   'sys/file.h',
   'sys/ioctl.h',
+  'sys/random.h',
   'sys/signal.h',
   'sys/stat.h',
   'sys/termio.h',
diff --git a/utility/randseed.c b/utility/randseed.c
index ddaa889d82..5610b27270 100644
--- a/utility/randseed.c
+++ b/utility/randseed.c
@@ -23,6 +23,9 @@
 #include <fcntl.h>
 #include <stdint.h>
 #include <string.h>
+#ifdef HAVE_SYS_RANDOM_H
+#include <sys/random.h>
+#endif
 #include <sys/stat.h>
 #include <time.h>
 #ifdef HAVE_UNISTD_H
-- 
2.30.2