[libc-commits] [libc] b75c806 - [libc] Simplify getrandom syscall error handling (#242602)

via libc-commits libc-commits at lists.llvm.org
Sat Nov 14 17:54:12 PST 2026


Author: Connector Switch
Date: 2026-11-15T09:54:07+08:00
New Revision: b75c806265497d0d01a317400ab73f07bc38ad63

URL: https://github.com/llvm/llvm-project/commit/b75c806265497d0d01a317400ab73f07bc38ad63
DIFF: https://github.com/llvm/llvm-project/commit/b75c806265497d0d01a317400ab73f07bc38ad63.diff

LOG: [libc] Simplify getrandom syscall error handling (#242602)

Use syscall_checked<ssize_t> in the getrandom wrapper instead of
converting syscall errors by hand.

Added: 
    

Modified: 
    libc/src/__support/OSUtil/linux/syscall_wrappers/getrandom.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/getrandom.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/getrandom.h
index b5ef6201a2dc5e..63d365ac7806dd 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/getrandom.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/getrandom.h
@@ -10,7 +10,7 @@
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETRANDOM_H
 
 #include "hdr/types/ssize_t.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -21,10 +21,7 @@ namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<ssize_t> getrandom(void *buf, size_t buflen,
                                        unsigned int flags) {
-  ssize_t ret = syscall_impl<ssize_t>(SYS_getrandom, buf, buflen, flags);
-  if (ret < 0)
-    return Error(-static_cast<int>(ret));
-  return ret;
+  return syscall_checked<ssize_t>(SYS_getrandom, buf, buflen, flags);
 }
 
 } // namespace linux_syscalls


        


More information about the libc-commits mailing list