select.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * select() for uClibc
  4. *
  5. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <sys/syscall.h>
  10. #include <sys/select.h>
  11. #include <cancel.h>
  12. #ifdef __NR__newselect
  13. # undef __NR_select
  14. # define __NR_select __NR__newselect
  15. #endif
  16. #if !defined __NR_select && defined __NR_pselect6
  17. # include <stdint.h>
  18. # define USEC_PER_SEC 1000000L
  19. #endif
  20. int __NC(select)(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
  21. struct timeval *timeout)
  22. {
  23. #ifdef __NR_select
  24. return INLINE_SYSCALL(select, 5, n, readfds, writefds, exceptfds, timeout);
  25. #elif defined __NR_pselect6
  26. struct timespec _ts, *ts = 0;
  27. if (timeout) {
  28. uint32_t usec;
  29. _ts.tv_sec = timeout->tv_sec;
  30. /* GNU extension: allow for timespec values where the sub-sec
  31. * field is equal to or more than 1 second. The kernel will
  32. * reject this on us, so take care of the time shift ourself.
  33. * Some applications (like readline and linphone) do this.
  34. * See 'clarification on select() type calls and invalid timeouts'
  35. * on the POSIX general list for more information.
  36. */
  37. usec = timeout->tv_usec;
  38. if (usec >= USEC_PER_SEC) {
  39. _ts.tv_sec += usec / USEC_PER_SEC;
  40. usec %= USEC_PER_SEC;
  41. }
  42. _ts.tv_nsec = usec * 1000;
  43. ts = &_ts;
  44. }
  45. return INLINE_SYSCALL(pselect6, 6, n, readfds, writefds, exceptfds, ts, 0);
  46. #endif
  47. }
  48. /* we should guard it, but we need it in other files, so let it fail
  49. * if we miss any of the syscalls */
  50. #if 1 /*defined __NR_select || defined __NR_pselect6*/
  51. CANCELLABLE_SYSCALL(int, select, (int n, fd_set *readfds, fd_set *writefds,
  52. fd_set *exceptfds, struct timeval *timeout),
  53. (n, readfds, writefds, exceptfds, timeout))
  54. lt_libc_hidden(select)
  55. #endif