pselect.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (C) 2006-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2006.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <signal.h>
  17. #include <time.h>
  18. #include <sys/poll.h>
  19. #include <kernel-features.h>
  20. #include <sysdep-cancel.h>
  21. #ifdef __NR_pselect6
  22. # ifndef __ASSUME_PSELECT
  23. static int __generic_pselect (int nfds, fd_set *readfds, fd_set *writefds,
  24. fd_set *exceptfds,
  25. const struct timespec *timeout,
  26. const sigset_t *sigmask);
  27. # endif
  28. int
  29. __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
  30. const struct timespec *timeout, const sigset_t *sigmask)
  31. {
  32. /* The Linux kernel can in some situations update the timeout value.
  33. We do not want that so use a local variable. */
  34. struct timespec tval;
  35. if (timeout != NULL)
  36. {
  37. tval = *timeout;
  38. timeout = &tval;
  39. }
  40. /* Note: the system call expects 7 values but on most architectures
  41. we can only pass in 6 directly. If there is an architecture with
  42. support for more parameters a new version of this file needs to
  43. be created. */
  44. struct
  45. {
  46. __syscall_ulong_t ss;
  47. __syscall_ulong_t ss_len;
  48. } data;
  49. data.ss = (__syscall_ulong_t) (uintptr_t) sigmask;
  50. data.ss_len = _NSIG / 8;
  51. int result;
  52. #ifndef CALL_PSELECT6
  53. # define CALL_PSELECT6(nfds, readfds, writefds, exceptfds, timeout, data) \
  54. SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds, timeout, data)
  55. #endif
  56. result = CALL_PSELECT6 (nfds, readfds, writefds, exceptfds, timeout,
  57. &data);
  58. # ifndef __ASSUME_PSELECT
  59. if (result == -1 && errno == ENOSYS)
  60. result = __generic_pselect (nfds, readfds, writefds, exceptfds, timeout,
  61. sigmask);
  62. # endif
  63. return result;
  64. }
  65. weak_alias (__pselect, pselect)
  66. # ifndef __ASSUME_PSELECT
  67. # define __pselect static __generic_pselect
  68. # endif
  69. #endif
  70. #ifndef __ASSUME_PSELECT
  71. # include <misc/pselect.c>
  72. #endif