1 /* `fd_set' type and related macros, and `select'/`pselect' declarations.
2 Copyright (C) 1996-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 /* POSIX 1003.1g: 6.2 Select from File Descriptor Sets <sys/select.h> */
22 #define _SYS_SELECT_H 1
26 /* Get definition of needed basic types. */
27 #include <bits/types.h>
29 /* Get __FD_* definitions. */
30 #include <bits/select.h>
33 #include <bits/types/sigset_t.h>
35 /* Get definition of timer specification structures. */
36 #include <bits/types/time_t.h>
37 #include <bits/types/struct_timeval.h>
39 # include <bits/types/struct_timespec.h>
42 #ifndef __suseconds_t_defined
43 typedef __suseconds_t suseconds_t
;
44 # define __suseconds_t_defined
48 /* The fd_set member is required to be an array of longs. */
49 typedef long int __fd_mask
;
51 /* Some versions of <linux/posix_types.h> define this macros. */
53 /* It's easier to assume 8-bit bytes than to get CHAR_BIT. */
54 #define __NFDBITS (8 * (int) sizeof (__fd_mask))
55 #define __FD_ELT(d) ((d) / __NFDBITS)
56 #define __FD_MASK(d) ((__fd_mask) (1UL << ((d) % __NFDBITS)))
58 /* fd_set for select and pselect. */
61 /* XPG4.2 requires this member name. Otherwise avoid the name
62 from the global namespace. */
64 __fd_mask fds_bits
[__FD_SETSIZE
/ __NFDBITS
];
65 # define __FDS_BITS(set) ((set)->fds_bits)
67 __fd_mask __fds_bits
[__FD_SETSIZE
/ __NFDBITS
];
68 # define __FDS_BITS(set) ((set)->__fds_bits)
72 /* Maximum number of file descriptors in `fd_set'. */
73 #define FD_SETSIZE __FD_SETSIZE
76 /* Sometimes the fd_set member is assumed to have this type. */
77 typedef __fd_mask fd_mask
;
79 /* Number of bits per word of `fd_set' (some code assumes this is 32). */
80 # define NFDBITS __NFDBITS
84 /* Access macros for `fd_set'. */
85 #define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
86 #define FD_CLR(fd, fdsetp) __FD_CLR (fd, fdsetp)
87 #define FD_ISSET(fd, fdsetp) __FD_ISSET (fd, fdsetp)
88 #define FD_ZERO(fdsetp) __FD_ZERO (fdsetp)
93 /* Check the first NFDS descriptors each in READFDS (if not NULL) for read
94 readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
95 (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out
96 after waiting the interval specified therein. Returns the number of ready
97 descriptors, or -1 for errors.
99 This function is a cancellation point and therefore not marked with
101 #ifndef __USE_TIME64_REDIRECTS
102 extern int select (int __nfds
, fd_set
*__restrict __readfds
,
103 fd_set
*__restrict __writefds
,
104 fd_set
*__restrict __exceptfds
,
105 struct timeval
*__restrict __timeout
);
108 extern int __REDIRECT (select
,
109 (int __nfds
, fd_set
*__restrict __readfds
,
110 fd_set
*__restrict __writefds
,
111 fd_set
*__restrict __exceptfds
,
112 struct timeval
*__restrict __timeout
),
115 # define select __select64
120 /* Same as above only that the TIMEOUT value is given with higher
121 resolution and a sigmask which is been set temporarily. This version
124 This function is a cancellation point and therefore not marked with
126 # ifndef __USE_TIME64_REDIRECTS
127 extern int pselect (int __nfds
, fd_set
*__restrict __readfds
,
128 fd_set
*__restrict __writefds
,
129 fd_set
*__restrict __exceptfds
,
130 const struct timespec
*__restrict __timeout
,
131 const __sigset_t
*__restrict __sigmask
);
134 extern int __REDIRECT (pselect
,
135 (int __nfds
, fd_set
*__restrict __readfds
,
136 fd_set
*__restrict __writefds
,
137 fd_set
*__restrict __exceptfds
,
138 const struct timespec
*__restrict __timeout
,
139 const __sigset_t
*__restrict __sigmask
),
142 # define pselect __pselect64
148 /* Define some inlines helping to catch common problems. */
149 #if __USE_FORTIFY_LEVEL > 0 && defined __GNUC__
150 # include <bits/select2.h>
155 #endif /* sys/select.h */