[libc-commits] [libc] [libc] Simplify getrandom syscall error handling (PR #242602)
via libc-commits
libc-commits at lists.llvm.org
Fri Nov 13 22:57:53 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Connector Switch (c8ef)
<details>
<summary>Changes</summary>
Use syscall_checked<ssize_t> in the getrandom wrapper instead of converting syscall errors by hand. This keeps the same byte counts and errors and does not add retries or change the syscall arguments.
All five existing getrandom tests pass.
---
Full diff: https://github.com/llvm/llvm-project/pull/242602.diff
1 Files Affected:
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/getrandom.h (+2-5)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/242602
More information about the libc-commits
mailing list