select.c 1.7 KB

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