Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / Posix / getrandom.c
blobabd4c82919c347849e3d59b81342e693a58207ab
1 // RUN: %clang -O2 %s -o %t && %run %t
2 // UNSUPPORTED: android, darwin, target={{.*(netbsd|solaris).*}}
3 //
5 #include <sys/types.h>
6 #include <errno.h>
8 #if !defined(__GLIBC_PREREQ)
9 #define __GLIBC_PREREQ(a, b) 0
10 #endif
12 #if (defined(__linux__) && __GLIBC_PREREQ(2, 25)) || defined(__FreeBSD__) || \
13 (defined(__sun) && defined(__svr4__))
14 #define HAS_GETRANDOM
15 #endif
17 #if defined(HAS_GETRANDOM)
18 #include <sys/random.h>
19 #endif
21 int main() {
22 char buf[16];
23 ssize_t n = 1;
24 #if defined(HAS_GETRANDOM)
25 n = getrandom(buf, sizeof(buf), 0);
26 if (n == -1 && errno == ENOSYS)
27 n = 1;
28 #endif
29 return (int)(n <= 0);