]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/isoinfra/v2_0/include/sys/select.h
Initial revision
[karo-tx-redboot.git] / packages / isoinfra / v2_0 / include / sys / select.h
1 /*========================================================================
2 //
3 //      sys/select.h
4 //
5 //      POSIX definitions for select()
6 //
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
13 //
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.
17 //
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
21 // for more details.
22 //
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.
26 //
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.
33 //
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.
36 //
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####
43 //
44 // Author(s):     jlarmour
45 // Contributors:  
46 // Date:          2001-07-26
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>
52 //
53 //####DESCRIPTIONEND####
54 //
55 //======================================================================
56 */
57
58 /* CONFIGURATION */
59
60 #include <pkgconf/system.h>          
61 #include <pkgconf/isoinfra.h>          /* Configuration header */
62
63 #ifdef CYGPKG_IO_FILEIO
64     #include <pkgconf/io_fileio.h>          
65     #define     FD_SETSIZE CYGNUM_FILEIO_NFD    
66 #endif
67
68 /* ------------------------------------------------------------------- */
69
70 #if !defined(_POSIX_SOURCE)
71
72 #ifdef CYGINT_ISO_SELECT
73 # ifdef CYGBLD_ISO_SELECT_HEADER
74 #  include CYGBLD_ISO_SELECT_HEADER
75 # else
76
77 #   ifndef CYGONCE_ISO_SYS_SELECT_FD_SETS
78 #   define CYGONCE_ISO_SYS_SELECT_FD_SETS
79
80 #define NBBY    8               /* number of bits in a byte */
81
82 /*
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.
87  */
88 #ifndef FD_SETSIZE
89 #define FD_SETSIZE      256
90 #endif
91
92 typedef unsigned int    fd_mask;
93 #define __NFDBITS       (sizeof(fd_mask) * NBBY)        /* bits per mask */
94
95 #ifndef __howmany
96 #define __howmany(__x, __y)     (((__x) + ((__y) - 1)) / (__y))
97 #endif
98
99 typedef struct fd_set {
100         fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];
101 } fd_set;
102
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)))
106
107 #define FD_COPY(__f, __t)                                       \
108 {                                                               \
109     unsigned int _i;                                            \
110     for( _i = 0; _i < __howmany(FD_SETSIZE, __NFDBITS) ; _i++ ) \
111         (__t)->fds_bits[_i] = (__f)->fds_bits[_i];              \
112 }
113
114 #define FD_ZERO(__p)                                            \
115 {                                                               \
116     unsigned int _i;                                            \
117     for( _i = 0; _i < __howmany(FD_SETSIZE, __NFDBITS) ; _i++ ) \
118         (__p)->fds_bits[_i] = 0;                                \
119 }
120
121 #   endif /* CYGONCE_ISO_SYS_SELECT_FD_SETS */
122
123 #  ifndef __NEED_FD_SETS_ONLY
124
125 #   ifndef CYGONCE_ISO_SYS_SELECT_H
126 #   define CYGONCE_ISO_SYS_SELECT_H
127
128 #   ifdef __cplusplus
129 extern "C" {
130 #   endif
131
132 struct timeval;
133 extern int
134 select( int /* nfd */, fd_set * /* in */, fd_set * /* out */,
135         fd_set * /* ex */, struct timeval * /* tv */ );
136
137 #ifdef CYGPKG_POSIX
138 # include <pkgconf/posix.h>
139 # ifdef CYGPKG_POSIX_SIGNALS
140 #  include <signal.h>
141 struct timespec;
142 extern int
143 pselect( int /* nfd */, fd_set * /* in */, fd_set * /* out */,
144         fd_set * /* ex */, const struct timespec * /* ts */,
145         const sigset_t * /* mask */);
146 # endif
147 #endif
148     
149 #   ifdef __cplusplus
150 }   /* extern "C" */
151 #   endif
152
153 #   endif /* CYGONCE_ISO_SYS_SELECT_H multiple inclusion protection */
154
155 #  endif /* __NEED_FD_SETS_ONLY */
156
157 # endif
158 #endif
159
160
161 #endif /* if !defined(_POSIX_SOURCE) */
162 /* ------------------------------------------------------------------- */
163
164 /* EOF sys/select.h */