select.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* `fd_set' type and related macros, and `select'/`pselect' declarations.
  17. Copyright (C) 1996-2026 Free Software Foundation, Inc.
  18. This file is part of the GNU C Library.
  19. The GNU C Library is free software; you can redistribute it and/or
  20. modify it under the terms of the GNU Lesser General Public
  21. License as published by the Free Software Foundation; either
  22. version 2.1 of the License, or (at your option) any later version.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library; if not, see
  29. <https://www.gnu.org/licenses/>. */
  30. /* POSIX 1003.1g: 6.2 Select from File Descriptor Sets <sys/select.h> */
  31. #ifndef _SYS_SELECT_H
  32. #define _SYS_SELECT_H 1
  33. #include <features.h>
  34. /* Get definition of needed basic types. */
  35. #include <bits/types.h>
  36. /* Get __FD_* definitions. */
  37. #include <bits/select.h>
  38. /* Get sigset_t. */
  39. #include <bits/types/sigset_t.h>
  40. /* Get definition of timer specification structures. */
  41. #include <bits/types/time_t.h>
  42. #include <bits/types/struct_timeval.h>
  43. #ifdef __USE_XOPEN2K
  44. # include <bits/types/struct_timespec.h>
  45. #endif
  46. #ifndef __suseconds_t_defined
  47. typedef __suseconds_t suseconds_t;
  48. # define __suseconds_t_defined
  49. #endif
  50. /* The fd_set member is required to be an array of longs. */
  51. typedef long int __fd_mask;
  52. /* Some versions of <linux/posix_types.h> define this macros. */
  53. #undef __NFDBITS
  54. /* It's easier to assume 8-bit bytes than to get CHAR_BIT. */
  55. #define __NFDBITS (8 * (int) sizeof (__fd_mask))
  56. #define __FD_ELT(d) ((d) / __NFDBITS)
  57. #define __FD_MASK(d) ((__fd_mask) (1UL << ((d) % __NFDBITS)))
  58. /* fd_set for select and pselect. */
  59. typedef struct
  60. {
  61. /* XPG4.2 requires this member name. Otherwise avoid the name
  62. from the global namespace. */
  63. #ifdef __USE_XOPEN
  64. __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
  65. # define __FDS_BITS(set) ((set)->fds_bits)
  66. #else
  67. __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS];
  68. # define __FDS_BITS(set) ((set)->__fds_bits)
  69. #endif
  70. } fd_set;
  71. /* Maximum number of file descriptors in `fd_set'. */
  72. #define FD_SETSIZE __FD_SETSIZE
  73. #ifdef __USE_MISC
  74. /* Sometimes the fd_set member is assumed to have this type. */
  75. typedef __fd_mask fd_mask;
  76. /* Number of bits per word of `fd_set' (some code assumes this is 32). */
  77. # define NFDBITS __NFDBITS
  78. #endif
  79. /* Access macros for `fd_set'. */
  80. #define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
  81. #define FD_CLR(fd, fdsetp) __FD_CLR (fd, fdsetp)
  82. #define FD_ISSET(fd, fdsetp) __FD_ISSET (fd, fdsetp)
  83. #define FD_ZERO(fdsetp) __FD_ZERO (fdsetp)
  84. __BEGIN_DECLS
  85. /* Check the first NFDS descriptors each in READFDS (if not NULL) for read
  86. readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
  87. (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out
  88. after waiting the interval specified therein. Returns the number of ready
  89. descriptors, or -1 for errors.
  90. This function is a cancellation point and therefore not marked with
  91. __THROW. */
  92. #ifndef __USE_TIME64_REDIRECTS
  93. extern int select (int __nfds, fd_set *__restrict __readfds,
  94. fd_set *__restrict __writefds,
  95. fd_set *__restrict __exceptfds,
  96. struct timeval *__restrict __timeout);
  97. #else
  98. # ifdef __REDIRECT
  99. extern int __REDIRECT (select,
  100. (int __nfds, fd_set *__restrict __readfds,
  101. fd_set *__restrict __writefds,
  102. fd_set *__restrict __exceptfds,
  103. struct timeval *__restrict __timeout),
  104. __select64);
  105. # else
  106. # define select __select64
  107. # endif
  108. #endif
  109. #ifdef __USE_XOPEN2K
  110. /* Same as above only that the TIMEOUT value is given with higher
  111. resolution and a sigmask which is been set temporarily. This version
  112. should be used.
  113. This function is a cancellation point and therefore not marked with
  114. __THROW. */
  115. # ifndef __USE_TIME64_REDIRECTS
  116. extern int pselect (int __nfds, fd_set *__restrict __readfds,
  117. fd_set *__restrict __writefds,
  118. fd_set *__restrict __exceptfds,
  119. const struct timespec *__restrict __timeout,
  120. const __sigset_t *__restrict __sigmask);
  121. # else
  122. # ifdef __REDIRECT
  123. extern int __REDIRECT (pselect,
  124. (int __nfds, fd_set *__restrict __readfds,
  125. fd_set *__restrict __writefds,
  126. fd_set *__restrict __exceptfds,
  127. const struct timespec *__restrict __timeout,
  128. const __sigset_t *__restrict __sigmask),
  129. __pselect64);
  130. # else
  131. # define pselect __pselect64
  132. # endif
  133. # endif
  134. #endif
  135. /* Define some inlines helping to catch common problems. */
  136. #if __USE_FORTIFY_LEVEL > 0 && defined __GNUC__
  137. # include <bits/select2.h>
  138. #endif
  139. __END_DECLS
  140. #endif /* sys/select.h */