build: check for getrandom and sys/random.h

Fixes #833
This commit is contained in:
Wim Taymans 2021-03-04 10:57:48 +01:00
parent 3af768f124
commit a4b0b9afe5
3 changed files with 27 additions and 5 deletions

View file

@ -22,20 +22,34 @@
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include <unistd.h>
#include <errno.h>
#ifndef ENODATA
#define ENODATA 9919
#endif
#if HAVE_SYS_RANDOM_H
#include <sys/random.h>
#endif
#ifdef __FreeBSD__
#include <sys/param.h>
#include <fcntl.h>
#undef GETRANDOM_FALLBACK
#ifndef HAVE_GETRANDOM
# ifdef __FreeBSD__
# include <sys/param.h>
# include <fcntl.h>
// FreeBSD versions < 12 do not have getrandom() syscall
// Give a poor-man implementation here
// Can be removed after September 30, 2021
#if __FreeBSD_version < 1200000
# if __FreeBSD_version < 1200000
# define GETRANDOM_FALLBACK 1
# endif
# else
# define GETRANDOM_FALLBACK 1
# endif
#endif
#ifdef GETRANDOM_FALLBACK
ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
int fd = open("/dev/random", O_CLOEXEC);
if (fd < 0)
@ -45,7 +59,6 @@ ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
return bytes;
}
#endif
#endif
#include <spa/debug/types.h>