pselect.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <errno.h>
  17. #include <signal.h>
  18. #include <stddef.h> /* For NULL. */
  19. #include <sys/time.h>
  20. #include <sys/select.h>
  21. extern __typeof(pselect) __libc_pselect;
  22. /* libc_hidden_proto(sigprocmask) */
  23. /* libc_hidden_proto(select) */
  24. /* Check the first NFDS descriptors each in READFDS (if not NULL) for read
  25. readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
  26. (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out
  27. after waiting the interval specified therein. Additionally set the sigmask
  28. SIGMASK for this call. Returns the number of ready descriptors, or -1 for
  29. errors. */
  30. int
  31. __libc_pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
  32. const struct timespec *timeout, const sigset_t *sigmask)
  33. {
  34. struct timeval tval;
  35. int retval;
  36. sigset_t savemask;
  37. /* Change nanosecond number to microseconds. This might mean losing
  38. precision and therefore the `pselect` should be available. But
  39. for now it is hardly found. */
  40. if (timeout != NULL)
  41. TIMESPEC_TO_TIMEVAL (&tval, timeout);
  42. /* The setting and restoring of the signal mask and the select call
  43. should be an atomic operation. This can't be done without kernel
  44. help. */
  45. if (sigmask != NULL)
  46. sigprocmask (SIG_SETMASK, sigmask, &savemask);
  47. /* Note the pselect() is a cancellation point. But since we call
  48. select() which itself is a cancellation point we do not have
  49. to do anything here. */
  50. retval = select (nfds, readfds, writefds, exceptfds,
  51. timeout != NULL ? &tval : NULL);
  52. if (sigmask != NULL)
  53. sigprocmask (SIG_SETMASK, &savemask, NULL);
  54. return retval;
  55. }
  56. weak_alias(__libc_pselect,pselect)