poll.cpp 751 B

12345678910111213141516171819202122232425262728293031
  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 <poll.h>
  8. #include <sys/time.h>
  9. #include <syscall.h>
  10. extern "C" {
  11. int poll(pollfd* fds, nfds_t nfds, int timeout_ms)
  12. {
  13. timespec timeout;
  14. timespec* timeout_ts = &timeout;
  15. if (timeout_ms < 0)
  16. timeout_ts = nullptr;
  17. else
  18. timeout = { timeout_ms / 1000, (timeout_ms % 1000) * 1'000'000 };
  19. return ppoll(fds, nfds, timeout_ts, nullptr);
  20. }
  21. int ppoll(pollfd* fds, nfds_t nfds, const timespec* timeout, const sigset_t* sigmask)
  22. {
  23. Syscall::SC_poll_params params { fds, nfds, timeout, sigmask };
  24. int rc = syscall(SC_poll, &params);
  25. __RETURN_WITH_ERRNO(rc, rc, -1);
  26. }
  27. }