[libc-commits] [libc] [libc] Internal getrandom implementation (PR #144427)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Tue Jun 17 09:39:34 PDT 2025


================
@@ -39,14 +39,14 @@ LIBC_INLINE uint64_t next_random_seed() {
     size_t count = sizeof(entropy);
     uint8_t *buffer = reinterpret_cast<uint8_t *>(entropy);
     while (count > 0) {
-      ssize_t len = getrandom(buffer, count, 0);
-      if (len == -1) {
-        if (libc_errno == ENOSYS)
+      auto len = internal::getrandom(buffer, count, 0);
+      if (len.error()) {
----------------
michaelrj-google wrote:

Because of the way `ErrorOr` is implemented, `len.error()` returns a value even if it doesn't have an error. You have to explicitly check if it has a value before you read the error.
```suggestion
      if (!len.has_value()) {
```

https://github.com/llvm/llvm-project/pull/144427


More information about the libc-commits mailing list