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

Michael Jones via libc-commits libc-commits at lists.llvm.org
Tue Jun 17 10:25:23 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.has_value()) {
+        if (len.error() == ENOSYS)
           break;
         continue;
       }
-      count -= len;
-      buffer += len;
+      count -= len.value();
+      buffer += len.value();
     }
     libc_errno = errno_backup;
----------------
michaelrj-google wrote:

you can delete the `errno_backup` with this change since `getrandom` doesn't set errno anymore.

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


More information about the libc-commits mailing list