poll2.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Checking macros for poll functions.
  2. Copyright (C) 2012-2016 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _SYS_POLL_H
  16. # error "Never include <bits/poll2.h> directly; use <sys/poll.h> instead."
  17. #endif
  18. __BEGIN_DECLS
  19. extern int __REDIRECT (__poll_alias, (struct pollfd *__fds, nfds_t __nfds,
  20. int __timeout), poll);
  21. extern int __poll_chk (struct pollfd *__fds, nfds_t __nfds, int __timeout,
  22. __SIZE_TYPE__ __fdslen);
  23. extern int __REDIRECT (__poll_chk_warn, (struct pollfd *__fds, nfds_t __nfds,
  24. int __timeout, __SIZE_TYPE__ __fdslen),
  25. __poll_chk)
  26. __warnattr ("poll called with fds buffer too small file nfds entries");
  27. __fortify_function int
  28. poll (struct pollfd *__fds, nfds_t __nfds, int __timeout)
  29. {
  30. if (__bos (__fds) != (__SIZE_TYPE__) -1)
  31. {
  32. if (! __builtin_constant_p (__nfds))
  33. return __poll_chk (__fds, __nfds, __timeout, __bos (__fds));
  34. else if (__bos (__fds) / sizeof (*__fds) < __nfds)
  35. return __poll_chk_warn (__fds, __nfds, __timeout, __bos (__fds));
  36. }
  37. return __poll_alias (__fds, __nfds, __timeout);
  38. }
  39. #ifdef __USE_GNU
  40. extern int __REDIRECT (__ppoll_alias, (struct pollfd *__fds, nfds_t __nfds,
  41. const struct timespec *__timeout,
  42. const __sigset_t *__ss), ppoll);
  43. extern int __ppoll_chk (struct pollfd *__fds, nfds_t __nfds,
  44. const struct timespec *__timeout,
  45. const __sigset_t *__ss, __SIZE_TYPE__ __fdslen);
  46. extern int __REDIRECT (__ppoll_chk_warn, (struct pollfd *__fds, nfds_t __nfds,
  47. const struct timespec *__timeout,
  48. const __sigset_t *__ss,
  49. __SIZE_TYPE__ __fdslen),
  50. __ppoll_chk)
  51. __warnattr ("ppoll called with fds buffer too small file nfds entries");
  52. __fortify_function int
  53. ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout,
  54. const __sigset_t *__ss)
  55. {
  56. if (__bos (__fds) != (__SIZE_TYPE__) -1)
  57. {
  58. if (! __builtin_constant_p (__nfds))
  59. return __ppoll_chk (__fds, __nfds, __timeout, __ss, __bos (__fds));
  60. else if (__bos (__fds) / sizeof (*__fds) < __nfds)
  61. return __ppoll_chk_warn (__fds, __nfds, __timeout, __ss,
  62. __bos (__fds));
  63. }
  64. return __ppoll_alias (__fds, __nfds, __timeout, __ss);
  65. }
  66. #endif
  67. __END_DECLS