diff options
Diffstat (limited to 'test/sanitizer_common/TestCases/Posix')
-rw-r--r-- | test/sanitizer_common/TestCases/Posix/getrandom.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/sanitizer_common/TestCases/Posix/getrandom.c b/test/sanitizer_common/TestCases/Posix/getrandom.c new file mode 100644 index 000000000..fdc08bc4e --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/getrandom.c @@ -0,0 +1,26 @@ +// RUN: %clang -O2 %s -o %t && %run %t +// UNSUPPORTED: android netbsd darwin solaris +// + +#include <sys/types.h> + +#if !defined(__GLIBC_PREREQ) +#define __GLIBC_PREREQ(a, b) 0 +#endif + +#if (defined(__linux__) && __GLIBC_PREREQ(2, 25)) || defined(__FreeBSD__) +#define HAS_GETRANDOM +#endif + +#if defined(HAS_GETRANDOM) +#include <sys/random.h> +#endif + +int main() { + char buf[16]; + ssize_t n = 1; +#if defined(HAS_GETRANDOM) + n = getrandom(buf, sizeof(buf), 0); +#endif + return (int)(n <= 0); +} |