pselect.c 2.4 KB

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