1 /*========================================================================
5 // POSIX definitions for select()
7 //========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2002 Nick Garnett
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //========================================================================
42 //#####DESCRIPTIONBEGIN####
44 // Author(s): jlarmour
47 // Purpose: This file provides the macros, types and functions
48 // required by POSIX 1003.1.
49 // Description: Much of the real contents of this file get set from the
50 // configuration (set by the implementation)
51 // Usage: #include <sys/select.h>
53 //####DESCRIPTIONEND####
55 //======================================================================
60 #include <pkgconf/system.h>
61 #include <pkgconf/isoinfra.h> /* Configuration header */
63 #ifdef CYGPKG_IO_FILEIO
64 #include <pkgconf/io_fileio.h>
65 #define FD_SETSIZE CYGNUM_FILEIO_NFD
68 /* ------------------------------------------------------------------- */
70 #if !defined(_POSIX_SOURCE)
72 #ifdef CYGINT_ISO_SELECT
73 # ifdef CYGBLD_ISO_SELECT_HEADER
74 # include CYGBLD_ISO_SELECT_HEADER
77 # ifndef CYGONCE_ISO_SYS_SELECT_FD_SETS
78 # define CYGONCE_ISO_SYS_SELECT_FD_SETS
80 #define NBBY 8 /* number of bits in a byte */
83 * Select uses bit masks of file descriptors in longs. These macros
84 * manipulate such bit fields (the filesystem macros use chars).
85 * FD_SETSIZE may be defined by the user, but the default here should
86 * be enough for most uses.
89 #define FD_SETSIZE 256
92 typedef unsigned int fd_mask;
93 #define __NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
96 #define __howmany(__x, __y) (((__x) + ((__y) - 1)) / (__y))
99 typedef struct fd_set {
100 fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];
103 #define FD_SET(__n, __p) ((__p)->fds_bits[(__n)/__NFDBITS] |= (1 << ((__n) % __NFDBITS)))
104 #define FD_CLR(__n, __p) ((__p)->fds_bits[(__n)/__NFDBITS] &= ~(1 << ((__n) % __NFDBITS)))
105 #define FD_ISSET(__n, __p) ((__p)->fds_bits[(__n)/__NFDBITS] & (1 << ((__n) % __NFDBITS)))
107 #define FD_COPY(__f, __t) \
110 for( _i = 0; _i < __howmany(FD_SETSIZE, __NFDBITS) ; _i++ ) \
111 (__t)->fds_bits[_i] = (__f)->fds_bits[_i]; \
114 #define FD_ZERO(__p) \
117 for( _i = 0; _i < __howmany(FD_SETSIZE, __NFDBITS) ; _i++ ) \
118 (__p)->fds_bits[_i] = 0; \
121 # endif /* CYGONCE_ISO_SYS_SELECT_FD_SETS */
123 # ifndef __NEED_FD_SETS_ONLY
125 # ifndef CYGONCE_ISO_SYS_SELECT_H
126 # define CYGONCE_ISO_SYS_SELECT_H
134 select( int /* nfd */, fd_set * /* in */, fd_set * /* out */,
135 fd_set * /* ex */, struct timeval * /* tv */ );
138 # include <pkgconf/posix.h>
139 # ifdef CYGPKG_POSIX_SIGNALS
143 pselect( int /* nfd */, fd_set * /* in */, fd_set * /* out */,
144 fd_set * /* ex */, const struct timespec * /* ts */,
145 const sigset_t * /* mask */);
153 # endif /* CYGONCE_ISO_SYS_SELECT_H multiple inclusion protection */
155 # endif /* __NEED_FD_SETS_ONLY */
161 #endif /* if !defined(_POSIX_SOURCE) */
162 /* ------------------------------------------------------------------- */
164 /* EOF sys/select.h */