select.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_pselect6) || defined(__NR_pselect6_time64)
  16. # include <stdint.h>
  17. # define USEC_PER_SEC 1000000L
  18. #endif
  19. #if defined(__UCLIBC_USE_TIME64__)
  20. #include "internal/time64_helpers.h"
  21. #endif
  22. int __NC(select)(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
  23. struct timeval *timeout)
  24. {
  25. #if defined(__NR_pselect6) || defined(__NR_pselect6_time64)
  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. #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_pselect6_time64)
  46. return INLINE_SYSCALL(pselect6_time64, 6, n, readfds, writefds, exceptfds, TO_TS64_P(ts), 0);
  47. #else
  48. return INLINE_SYSCALL(pselect6, 6, n, readfds, writefds, exceptfds, ts, 0);
  49. #endif
  50. #elif defined(__NR_select)
  51. return INLINE_SYSCALL(select, 5, n, readfds, writefds, exceptfds, ts);
  52. #endif
  53. }
  54. /* we should guard it, but we need it in other files, so let it fail
  55. * if we miss any of the syscalls */
  56. #if 1 /*defined __NR_select || defined __NR_pselect6*/
  57. CANCELLABLE_SYSCALL(int, select, (int n, fd_set *readfds, fd_set *writefds,
  58. fd_set *exceptfds, struct timeval *timeout),
  59. (n, readfds, writefds, exceptfds, timeout))
  60. lt_libc_hidden(select)
  61. #endif