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

via libc-commits libc-commits at lists.llvm.org
Wed May 28 14:08:50 PDT 2025


Author: Michael Jones
Date: 2025-05-28T14:08:47-07:00
New Revision: 3a0205ae0680b0a8c601cc3059a4698a835150e9

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

LOG: [libc][NFC] Cleanup code for poll (#141802)

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

Added: 
    

Modified: 
    libc/src/poll/linux/poll.cpp

Removed: 
    


################################################################################
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