diff --git a/libc/src/sys/random/linux/getrandom.cpp b/libc/src/sys/random/linux/getrandom.cpp --- a/libc/src/sys/random/linux/getrandom.cpp +++ b/libc/src/sys/random/linux/getrandom.cpp @@ -23,7 +23,7 @@ libc_errno = -ret; return -1; } - return 0; + return ret; } } // namespace __llvm_libc diff --git a/libc/test/src/sys/random/linux/getrandom_test.cpp b/libc/test/src/sys/random/linux/getrandom_test.cpp --- a/libc/test/src/sys/random/linux/getrandom_test.cpp +++ b/libc/test/src/sys/random/linux/getrandom_test.cpp @@ -29,6 +29,15 @@ libc_errno = 0; } +TEST(LlvmLibcGetRandomTest, ReturnsSize) { + static constexpr size_t SIZE = 8192; + uint8_t buf[SIZE]; + for (size_t i = 0; i < SIZE; ++i) { + // Without GRND_RANDOM set this should never fail. + ASSERT_EQ(__llvm_libc::getrandom(buf, i, 0), static_cast(i)); + } +} + TEST(LlvmLibcGetRandomTest, PiEstimation) { static constexpr size_t LIMIT = 10000000; static constexpr double PI = 3.14159265358979;