pselect.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
  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 <features.h>
  16. #ifdef __USE_XOPEN2K
  17. #include <sys/syscall.h>
  18. #include <sys/select.h>
  19. #include <sys/time.h>
  20. #include <signal.h>
  21. #include <cancel.h>
  22. static int __NC(pselect)(int nfds, fd_set *readfds, fd_set *writefds,
  23. fd_set *exceptfds, const struct timespec *timeout,
  24. const sigset_t *sigmask)
  25. {
  26. struct timeval tval;
  27. int retval;
  28. sigset_t savemask;
  29. /* Change nanosecond number to microseconds. This might mean losing
  30. precision and therefore the `pselect` should be available. But
  31. for now it is hardly found. */
  32. if (timeout != NULL)
  33. TIMESPEC_TO_TIMEVAL (&tval, timeout);
  34. /* The setting and restoring of the signal mask and the select call
  35. should be an atomic operation. This can't be done without kernel
  36. help. */
  37. if (sigmask != NULL)
  38. sigprocmask (SIG_SETMASK, sigmask, &savemask);
  39. /* The comment below does not apply on uClibc, since we use __select_nocancel */
  40. /* Note the pselect() is a cancellation point. But since we call
  41. select() which itself is a cancellation point we do not have
  42. to do anything here. */
  43. retval = __NC(select)(nfds, readfds, writefds, exceptfds,
  44. timeout != NULL ? &tval : NULL);
  45. if (sigmask != NULL)
  46. sigprocmask (SIG_SETMASK, &savemask, NULL);
  47. return retval;
  48. }
  49. CANCELLABLE_SYSCALL(int, pselect, (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
  50. const struct timespec *timeout, const sigset_t *sigmask),
  51. (nfds, readfds, writefds, exceptfds, timeout, sigmask))
  52. #endif