xref: /onnv-gate/usr/src/uts/common/sys/select.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*0Sstevel@tonic-gate /*	  All Rights Reserved	*/
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate /*
31*0Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*0Sstevel@tonic-gate  * The Regents of the University of California
33*0Sstevel@tonic-gate  * All Rights Reserved
34*0Sstevel@tonic-gate  *
35*0Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*0Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*0Sstevel@tonic-gate  * contributors.
38*0Sstevel@tonic-gate  */
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #ifndef _SYS_SELECT_H
41*0Sstevel@tonic-gate #define	_SYS_SELECT_H
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate #include <sys/feature_tests.h>
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate #ifndef _KERNEL
48*0Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
49*0Sstevel@tonic-gate #include <sys/time_impl.h>
50*0Sstevel@tonic-gate #endif
51*0Sstevel@tonic-gate #include <sys/time.h>
52*0Sstevel@tonic-gate #endif /* _KERNEL */
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate #ifdef	__cplusplus
55*0Sstevel@tonic-gate extern "C" {
56*0Sstevel@tonic-gate #endif
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
60*0Sstevel@tonic-gate /*
61*0Sstevel@tonic-gate  * The sigset_t type is defined in <sys/signal.h> and duplicated
62*0Sstevel@tonic-gate  * in <sys/ucontext.h> as a result of XPG4v2 requirements. XPG6
63*0Sstevel@tonic-gate  * now allows the visibility of signal.h in this header, however
64*0Sstevel@tonic-gate  * an order of inclusion problem occurs as a result of inclusion
65*0Sstevel@tonic-gate  * of <sys/select.h> in <signal.h> under certain conditions.
66*0Sstevel@tonic-gate  * Rather than include <sys/signal.h> here, we've duplicated
67*0Sstevel@tonic-gate  * the sigset_t type instead. This type is required for the XPG6
68*0Sstevel@tonic-gate  * introduced pselect() function also declared in this header.
69*0Sstevel@tonic-gate  */
70*0Sstevel@tonic-gate #ifndef	_SIGSET_T
71*0Sstevel@tonic-gate #define	_SIGSET_T
72*0Sstevel@tonic-gate typedef struct {		/* signal set type */
73*0Sstevel@tonic-gate 	unsigned int	__sigbits[4];
74*0Sstevel@tonic-gate } sigset_t;
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate #if defined(_SYSCALL32)
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate /* Kernel view of the ILP32 user sigset_t structure */
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate typedef struct {
81*0Sstevel@tonic-gate 	uint32_t	__sigbits[4];
82*0Sstevel@tonic-gate } sigset32_t;
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate #endif  /* _SYSCALL32 */
85*0Sstevel@tonic-gate #endif  /* _SIGSET_T */
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate #endif /* #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate /*
90*0Sstevel@tonic-gate  * Select uses bit masks of file descriptors in longs.
91*0Sstevel@tonic-gate  * These macros manipulate such bit fields.
92*0Sstevel@tonic-gate  * FD_SETSIZE may be defined by the user, but the default here
93*0Sstevel@tonic-gate  * should be >= NOFILE (param.h).
94*0Sstevel@tonic-gate  */
95*0Sstevel@tonic-gate #ifndef	FD_SETSIZE
96*0Sstevel@tonic-gate #ifdef _LP64
97*0Sstevel@tonic-gate #define	FD_SETSIZE	65536
98*0Sstevel@tonic-gate #else
99*0Sstevel@tonic-gate #define	FD_SETSIZE	1024
100*0Sstevel@tonic-gate #endif	/* _LP64 */
101*0Sstevel@tonic-gate #elif FD_SETSIZE > 1024 && !defined(_LP64)
102*0Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
103*0Sstevel@tonic-gate #pragma	redefine_extname	select	select_large_fdset
104*0Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
105*0Sstevel@tonic-gate #pragma	redefine_extname	pselect	pselect_large_fdset
106*0Sstevel@tonic-gate #endif
107*0Sstevel@tonic-gate #else	/* __PRAGMA_REDEFINE_EXTNAME */
108*0Sstevel@tonic-gate #define	select	select_large_fdset
109*0Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
110*0Sstevel@tonic-gate #define	pselect	pselect_large_fdset
111*0Sstevel@tonic-gate #endif
112*0Sstevel@tonic-gate #endif	/* __PRAGMA_REDEFINE_EXTNAME */
113*0Sstevel@tonic-gate #endif	/* FD_SETSIZE */
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
116*0Sstevel@tonic-gate typedef	long	fd_mask;
117*0Sstevel@tonic-gate #endif
118*0Sstevel@tonic-gate typedef	long	fds_mask;
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate /*
121*0Sstevel@tonic-gate  *  The value of _NBBY needs to be consistant with the value
122*0Sstevel@tonic-gate  *  of NBBY in <sys/param.h>.
123*0Sstevel@tonic-gate  */
124*0Sstevel@tonic-gate #define	_NBBY 8
125*0Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
126*0Sstevel@tonic-gate #ifndef NBBY		/* number of bits per byte */
127*0Sstevel@tonic-gate #define	NBBY _NBBY
128*0Sstevel@tonic-gate #endif
129*0Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
132*0Sstevel@tonic-gate #define	NFDBITS		(sizeof (fd_mask) * NBBY)	/* bits per mask */
133*0Sstevel@tonic-gate #endif
134*0Sstevel@tonic-gate #define	FD_NFDBITS	(sizeof (fds_mask) * _NBBY)	/* bits per mask */
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate #define	__howmany(__x, __y)	(((__x)+((__y)-1))/(__y))
137*0Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
138*0Sstevel@tonic-gate #ifndef	howmany
139*0Sstevel@tonic-gate #define	howmany(x, y)	(((x)+((y)-1))/(y))
140*0Sstevel@tonic-gate #endif
141*0Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
144*0Sstevel@tonic-gate typedef	struct fd_set {
145*0Sstevel@tonic-gate #else
146*0Sstevel@tonic-gate typedef	struct __fd_set {
147*0Sstevel@tonic-gate #endif
148*0Sstevel@tonic-gate 	long	fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)];
149*0Sstevel@tonic-gate } fd_set;
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate #define	FD_SET(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] |= \
152*0Sstevel@tonic-gate 				    (1ul << ((__n) % FD_NFDBITS)))
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate #define	FD_CLR(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] &= \
155*0Sstevel@tonic-gate 				    ~(1ul << ((__n) % FD_NFDBITS)))
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate #define	FD_ISSET(__n, __p)	(((__p)->fds_bits[(__n)/FD_NFDBITS] & \
158*0Sstevel@tonic-gate 				    (1ul << ((__n) % FD_NFDBITS))) != 0l)
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate #ifdef _KERNEL
161*0Sstevel@tonic-gate #define	FD_ZERO(p)	bzero((p), sizeof (*(p)))
162*0Sstevel@tonic-gate #else
163*0Sstevel@tonic-gate #define	FD_ZERO(__p)    (void) memset((__p), 0, sizeof (*(__p)))
164*0Sstevel@tonic-gate #endif /* _KERNEL */
165*0Sstevel@tonic-gate 
166*0Sstevel@tonic-gate #ifndef	_KERNEL
167*0Sstevel@tonic-gate #ifdef	__STDC__
168*0Sstevel@tonic-gate extern int select(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
169*0Sstevel@tonic-gate 	fd_set *_RESTRICT_KYWD, struct timeval *_RESTRICT_KYWD);
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
172*0Sstevel@tonic-gate extern int pselect(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
173*0Sstevel@tonic-gate 	fd_set *_RESTRICT_KYWD, const struct timespec *_RESTRICT_KYWD,
174*0Sstevel@tonic-gate 	const sigset_t *_RESTRICT_KYWD);
175*0Sstevel@tonic-gate #endif
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate #else
178*0Sstevel@tonic-gate extern int select();
179*0Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
180*0Sstevel@tonic-gate extern int pselect();
181*0Sstevel@tonic-gate #endif
182*0Sstevel@tonic-gate #endif	/* __STDC__ */
183*0Sstevel@tonic-gate #endif	/* _KERNEL */
184*0Sstevel@tonic-gate 
185*0Sstevel@tonic-gate #ifdef	__cplusplus
186*0Sstevel@tonic-gate }
187*0Sstevel@tonic-gate #endif
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate #endif	/* _SYS_SELECT_H */
190