[libc-commits] [libc] [libc][NFC] Cleanup code for poll (PR #141802)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Wed May 28 09:42:11 PDT 2025


https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/141802

Ensure everything is defined inside the namespace, reduce number of
ifdefs.


>From b535b89b478ad6824db8c8b3fb0f68871fe0993e Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Wed, 28 May 2025 09:39:48 -0700
Subject: [PATCH] [libc][NFC] Cleanup code for poll

Ensure everything is defined inside the namespace, reduce number of
ifdefs.
---
 libc/src/poll/linux/poll.cpp | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

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;



More information about the libc-commits mailing list