4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
43 #include <sys/feature_tests.h>
46 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
47 #include <sys/time_impl.h>
57 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
59 * The sigset_t type is defined in <sys/signal.h> and duplicated
60 * in <sys/ucontext.h> as a result of XPG4v2 requirements. XPG6
61 * now allows the visibility of signal.h in this header, however
62 * an order of inclusion problem occurs as a result of inclusion
63 * of <sys/select.h> in <signal.h> under certain conditions.
64 * Rather than include <sys/signal.h> here, we've duplicated
65 * the sigset_t type instead. This type is required for the XPG6
66 * introduced pselect() function also declared in this header.
70 typedef struct { /* signal set type */
71 unsigned int __sigbits
[4];
73 #endif /* _SIGSET_T */
75 #endif /* #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
78 * Select uses bit masks of file descriptors in longs.
79 * These macros manipulate such bit fields.
80 * FD_SETSIZE may be defined by the user, but the default here
81 * should be >= NOFILE (param.h).
85 #define FD_SETSIZE 65536
87 #define FD_SETSIZE 1024
89 #elif FD_SETSIZE > 1024 && !defined(_LP64)
90 #ifdef __PRAGMA_REDEFINE_EXTNAME
91 #pragma redefine_extname select select_large_fdset
92 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
93 #pragma redefine_extname pselect pselect_large_fdset
95 #else /* __PRAGMA_REDEFINE_EXTNAME */
96 #define select select_large_fdset
97 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
98 #define pselect pselect_large_fdset
100 #endif /* __PRAGMA_REDEFINE_EXTNAME */
101 #endif /* FD_SETSIZE */
103 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
104 typedef long fd_mask
;
106 typedef long fds_mask
;
109 * The value of _NBBY needs to be consistant with the value
110 * of NBBY in <sys/param.h>.
113 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
114 #ifndef NBBY /* number of bits per byte */
117 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
119 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
120 #define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
122 #define FD_NFDBITS (sizeof (fds_mask) * _NBBY) /* bits per mask */
124 #define __howmany(__x, __y) (((__x)+((__y)-1))/(__y))
125 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
127 #define howmany(x, y) (((x)+((y)-1))/(y))
129 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
131 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
132 typedef struct fd_set
{
134 typedef struct __fd_set
{
136 long fds_bits
[__howmany(FD_SETSIZE
, FD_NFDBITS
)];
139 #define FD_SET(__n, __p) ((__p)->fds_bits[(__n)/FD_NFDBITS] |= \
140 (1ul << ((__n) % FD_NFDBITS)))
142 #define FD_CLR(__n, __p) ((__p)->fds_bits[(__n)/FD_NFDBITS] &= \
143 ~(1ul << ((__n) % FD_NFDBITS)))
145 #define FD_ISSET(__n, __p) (((__p)->fds_bits[(__n)/FD_NFDBITS] & \
146 (1ul << ((__n) % FD_NFDBITS))) != 0l)
149 #define FD_ZERO(p) bzero((p), sizeof (*(p)))
151 #define FD_ZERO(__p) (void) memset((__p), 0, sizeof (*(__p)))
156 extern int select(int, fd_set
*_RESTRICT_KYWD
, fd_set
*_RESTRICT_KYWD
,
157 fd_set
*_RESTRICT_KYWD
, struct timeval
*_RESTRICT_KYWD
);
159 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
160 extern int pselect(int, fd_set
*_RESTRICT_KYWD
, fd_set
*_RESTRICT_KYWD
,
161 fd_set
*_RESTRICT_KYWD
, const struct timespec
*_RESTRICT_KYWD
,
162 const sigset_t
*_RESTRICT_KYWD
);
167 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
168 extern int pselect();
170 #endif /* __STDC__ */
177 #endif /* _SYS_SELECT_H */