select.cpp 891 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <errno.h>
  7. #include <stdio.h>
  8. #include <sys/select.h>
  9. #include <sys/time.h>
  10. #include <syscall.h>
  11. extern "C" {
  12. int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, timeval* timeout_tv)
  13. {
  14. timespec* timeout_ts = nullptr;
  15. timespec timeout;
  16. if (timeout_tv) {
  17. timeout_ts = &timeout;
  18. TIMEVAL_TO_TIMESPEC(timeout_tv, timeout_ts);
  19. }
  20. return pselect(nfds, readfds, writefds, exceptfds, timeout_ts, nullptr);
  21. }
  22. int pselect(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, const timespec* timeout, const sigset_t* sigmask)
  23. {
  24. Syscall::SC_select_params params { nfds, readfds, writefds, exceptfds, timeout, sigmask };
  25. int rc = syscall(SC_select, &params);
  26. __RETURN_WITH_ERRNO(rc, rc, -1);
  27. }
  28. }