poll.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
  2. /*
  3. * poll definitions for NOLIBC
  4. * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
  5. */
  6. /* make sure to include all global symbols */
  7. #include "nolibc.h"
  8. #ifndef _NOLIBC_POLL_H
  9. #define _NOLIBC_POLL_H
  10. #include "arch.h"
  11. #include "sys.h"
  12. #include <linux/poll.h>
  13. #include <linux/time.h>
  14. /*
  15. * int poll(struct pollfd *fds, int nfds, int timeout);
  16. */
  17. static __attribute__((unused))
  18. int sys_poll(struct pollfd *fds, int nfds, int timeout)
  19. {
  20. #if defined(__NR_ppoll_time64)
  21. struct __kernel_timespec t;
  22. if (timeout >= 0) {
  23. t.tv_sec = timeout / 1000;
  24. t.tv_nsec = (timeout % 1000) * 1000000;
  25. }
  26. return my_syscall5(__NR_ppoll_time64, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0);
  27. #else
  28. struct __kernel_old_timespec t;
  29. if (timeout >= 0) {
  30. t.tv_sec = timeout / 1000;
  31. t.tv_nsec = (timeout % 1000) * 1000000;
  32. }
  33. return my_syscall5(__NR_ppoll, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0);
  34. #endif
  35. }
  36. static __attribute__((unused))
  37. int poll(struct pollfd *fds, int nfds, int timeout)
  38. {
  39. return __sysret(sys_poll(fds, nfds, timeout));
  40. }
  41. #endif /* _NOLIBC_POLL_H */