]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sysdeps/unix/sysv/linux/poll.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / poll.c
index 337b85005f6bb478544aa14ad9040c3388a6985b..1de2aa3c0f2dd162dd06810b3ab116cc180dc903 100644 (file)
@@ -1,53 +1,46 @@
-/* Poll system call, with emulation if it is not available.
-   Copyright (C) 1997 Free Software Foundation, Inc.
+/* Linux poll implementation.
+   Copyright (C) 2017-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
 #include <sys/poll.h>
 
-extern int __syscall_poll __P ((struct pollfd *fds, unsigned int nfds,
-                               int timeout));
-extern int __emulate_poll __P ((struct pollfd *fds, unsigned long int nfds,
-                               int timeout));
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
 
-/* The real implementation.  */
 int
-poll (fds, nfds, timeout)
-     struct pollfd *fds;
-     unsigned long int nfds;
-     int timeout;
+__poll (struct pollfd *fds, nfds_t nfds, int timeout)
 {
-  static int must_emulate = 0;
+#ifdef __NR_poll
+  return SYSCALL_CANCEL (poll, fds, nfds, timeout);
+#else
+  struct timespec timeout_ts;
+  struct timespec *timeout_ts_p = NULL;
 
-  if (!must_emulate)
+  if (timeout >= 0)
     {
-      int retval = __syscall_poll (fds, nfds, timeout);
-
-      if (retval >= 0 || errno != ENOSYS)
-       return retval;
-
-      must_emulate = 1;
+      timeout_ts.tv_sec = timeout / 1000;
+      timeout_ts.tv_nsec = (timeout % 1000) * 1000000;
+      timeout_ts_p = &timeout_ts;
     }
 
-  return __emulate_poll (fds, nfds, timeout);
+  return SYSCALL_CANCEL (ppoll, fds, nfds, timeout_ts_p, NULL, 0);
+#endif
 }
-
-
-/* Get the emulation code.  */
-#define poll(fds, nfds, timeout) __emulate_poll (fds, nfds, timeout)
-#include <sysdeps/unix/bsd/poll.c>
+libc_hidden_def (__poll)
+weak_alias (__poll, poll)
+strong_alias (__poll, __libc_poll)