Comparison

util-src/crand.c @ 7934:485b9e66fedf

util.crand: Only include getrandom shiv with glibc older than 2.25
author Kim Alvefur <zash@zash.se>
date Thu, 02 Mar 2017 00:17:34 +0100
parent 7933:c91ec7689424
child 7969:1c6a07606309
comparison
equal deleted inserted replaced
7933:c91ec7689424 7934:485b9e66fedf
26 26
27 #include <string.h> 27 #include <string.h>
28 #include <errno.h> 28 #include <errno.h>
29 29
30 #if defined(WITH_GETRANDOM) 30 #if defined(WITH_GETRANDOM)
31
32 #if ! __GLIBC_PREREQ(2,25)
31 #include <unistd.h> 33 #include <unistd.h>
32 #include <sys/syscall.h> 34 #include <sys/syscall.h>
33 #include <linux/random.h>
34 35
35 #ifndef SYS_getrandom 36 #ifndef SYS_getrandom
36 #error getrandom() requires Linux 3.17 or later 37 #error getrandom() requires Linux 3.17 or later
37 #endif 38 #endif
38 39
40 /* This wasn't present before glibc 2.25 */
39 int getrandom(void *buf, size_t buflen, unsigned int flags) { 41 int getrandom(void *buf, size_t buflen, unsigned int flags) {
40 return syscall(SYS_getrandom, buf, buflen, flags); 42 return syscall(SYS_getrandom, buf, buflen, flags);
41 } 43 }
44 #else
45 #include <sys/random.h>
46 #endif
42 47
43 #elif defined(WITH_ARC4RANDOM) 48 #elif defined(WITH_ARC4RANDOM)
44 #include <stdlib.h> 49 #include <stdlib.h>
45 #elif defined(WITH_OPENSSL) 50 #elif defined(WITH_OPENSSL)
46 #include <openssl/rand.h> 51 #include <openssl/rand.h>