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