[libc-commits] [libc] [libc][NFC] Cleanup code for poll (PR #141802)
via libc-commits
libc-commits at lists.llvm.org
Wed May 28 09:42:47 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Michael Jones (michaelrj-google)
<details>
<summary>Changes</summary>
Ensure everything is defined inside the namespace, reduce number of
ifdefs.
---
Full diff: https://github.com/llvm/llvm-project/pull/141802.diff
1 Files Affected:
- (modified) libc/src/poll/linux/poll.cpp (+12-15)
``````````diff
diff --git a/libc/src/poll/linux/poll.cpp b/libc/src/poll/linux/poll.cpp
index 2579ec04c1200..f82fcbcc6577c 100644
--- a/libc/src/poll/linux/poll.cpp
+++ b/libc/src/poll/linux/poll.cpp
@@ -18,24 +18,14 @@
#include <sys/syscall.h> // SYS_poll, SYS_ppoll
-#ifdef SYS_poll
-constexpr auto POLL_SYSCALL_ID = SYS_poll;
-#elif defined(SYS_ppoll)
-constexpr auto POLL_SYSCALL_ID = SYS_ppoll;
-#elif defined(SYS_ppoll_time64)
-constexpr auto POLL_SYSCALL_ID = SYS_ppoll_time64;
-#else
-#error "poll, ppoll, ppoll_time64 syscalls not available."
-#endif
-
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, poll, (pollfd * fds, nfds_t nfds, int timeout)) {
int ret = 0;
-#ifdef SYS_poll
- ret = LIBC_NAMESPACE::syscall_impl<int>(POLL_SYSCALL_ID, fds, nfds, timeout);
-#elif defined(SYS_ppoll) || defined(SYS_ppoll_time64)
+#if defined(SYS_poll)
+ ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_poll, fds, nfds, timeout);
+#else // no SYS_poll
timespec ts, *tsp;
if (timeout >= 0) {
ts.tv_sec = timeout / 1000;
@@ -44,9 +34,16 @@ LLVM_LIBC_FUNCTION(int, poll, (pollfd * fds, nfds_t nfds, int timeout)) {
} else {
tsp = nullptr;
}
- ret = LIBC_NAMESPACE::syscall_impl<int>(POLL_SYSCALL_ID, fds, nfds, tsp,
+#if defined(SYS_ppoll)
+ ret =
+ LIBC_NAMESPACE::syscall_impl<int>(SYS_ppoll, fds, nfds, tsp, nullptr, 0);
+#elif defined(SYS_ppoll_time64)
+ ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ppoll_time64, fds, nfds, tsp,
nullptr, 0);
-#endif
+#else
+#error "poll, ppoll, ppoll_time64 syscalls not available."
+#endif // defined(SYS_ppoll) || defined(SYS_ppoll_time64)
+#endif // defined(SYS_poll)
if (ret < 0) {
libc_errno = -ret;
``````````
</details>
https://github.com/llvm/llvm-project/pull/141802
More information about the libc-commits
mailing list