• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang -O2 %s -o %t && %run %t
2 // UNSUPPORTED: android, netbsd, darwin, solaris
3 //
4 
5 #include <sys/types.h>
6 #include <errno.h>
7 
8 #if !defined(__GLIBC_PREREQ)
9 #define __GLIBC_PREREQ(a, b) 0
10 #endif
11 
12 #if (defined(__linux__) && __GLIBC_PREREQ(2, 25)) || defined(__FreeBSD__)
13 #define HAS_GETRANDOM
14 #endif
15 
16 #if defined(HAS_GETRANDOM)
17 #include <sys/random.h>
18 #endif
19 
main()20 int main() {
21   char buf[16];
22   ssize_t n = 1;
23 #if defined(HAS_GETRANDOM)
24   n = getrandom(buf, sizeof(buf), 0);
25   if (n == -1 && errno == ENOSYS)
26     n = 1;
27 #endif
28   return (int)(n <= 0);
29 }
30