1 | // RUN: %clang -O2 %s -o %t && %run %t |
2 | // UNSUPPORTED: android, darwin, target={{.*(netbsd|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 | (defined(__sun) && defined(__svr4__)) |
14 | #define HAS_GETRANDOM |
15 | #endif |
16 | |
17 | #if defined(HAS_GETRANDOM) |
18 | #include <sys/random.h> |
19 | #endif |
20 | |
21 | int main() { |
22 | char buf[16]; |
23 | ssize_t n = 1; |
24 | #if defined(HAS_GETRANDOM) |
25 | n = getrandom(buffer: buf, length: sizeof(buf), flags: 0); |
26 | if (n == -1 && errno == ENOSYS) |
27 | n = 1; |
28 | #endif |
29 | return (int)(n <= 0); |
30 | } |
31 | |