Cygwin: access: Fix X_OK behaviour for backup operators and admins
[newlib-cygwin.git] / newlib / libc / include / sys / select.h
blob89269400b0d637fb4e6cb776a66381971b4a4600
1 #ifndef _SYS_SELECT_H
2 #define _SYS_SELECT_H
4 /* We don't define fd_set and friends if we are compiling POSIX
5 source, or if we have included (or may include as indicated
6 by __USE_W32_SOCKETS) the W32api winsock[2].h header which
7 defines Windows versions of them. Note that a program which
8 includes the W32api winsock[2].h header must know what it is doing;
9 it must not call the Cygwin select function.
11 # if !(defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS))
13 #include <sys/cdefs.h>
14 #include <sys/_sigset.h>
15 #include <sys/_timeval.h>
16 #include <sys/timespec.h>
18 #if !defined(_SIGSET_T_DECLARED)
19 #define _SIGSET_T_DECLARED
20 typedef __sigset_t sigset_t;
21 #endif
23 # define _SYS_TYPES_FD_SET
25 * Select uses bit masks of file descriptors in longs.
26 * These macros manipulate such bit fields (the filesystem macros use chars).
27 * FD_SETSIZE may be defined by the user, but the default here
28 * should be enough for most uses.
30 #ifndef FD_SETSIZE
31 # ifdef __CYGWIN__
32 # define FD_SETSIZE 1024
33 # elif defined(__rtems__)
34 # define FD_SETSIZE 256
35 # else
36 # define FD_SETSIZE 64
37 # endif
38 #endif
40 typedef unsigned long __fd_mask;
41 #if __BSD_VISIBLE
42 typedef __fd_mask fd_mask;
43 #endif
45 #define _NFDBITS ((int)sizeof(__fd_mask) * 8) /* bits per mask */
46 #if __BSD_VISIBLE
47 #define NFDBITS _NFDBITS
48 #endif
50 #ifndef _howmany
51 #define _howmany(x,y) (((x) + ((y) - 1)) / (y))
52 #endif
54 typedef struct fd_set {
55 __fd_mask __fds_bits[_howmany(FD_SETSIZE, _NFDBITS)];
56 } fd_set;
57 #if __BSD_VISIBLE
58 #define fds_bits __fds_bits
59 #endif
61 #define __fdset_mask(n) ((__fd_mask)1 << ((n) % _NFDBITS))
62 #define FD_CLR(n, p) ((p)->__fds_bits[(n)/_NFDBITS] &= ~__fdset_mask(n))
63 #if __BSD_VISIBLE
64 #define FD_COPY(f, t) (void)(*(t) = *(f))
65 #endif
66 #define FD_ISSET(n, p) (((p)->__fds_bits[(n)/_NFDBITS] & __fdset_mask(n)) != 0)
67 #define FD_SET(n, p) ((p)->__fds_bits[(n)/_NFDBITS] |= __fdset_mask(n))
68 #define FD_ZERO(p) do { \
69 fd_set *_p; \
70 __size_t _n; \
72 _p = (p); \
73 _n = _howmany(FD_SETSIZE, _NFDBITS); \
74 while (_n > 0) \
75 _p->__fds_bits[--_n] = 0; \
76 } while (0)
78 #if !defined (__INSIDE_CYGWIN_NET__)
80 __BEGIN_DECLS
82 int select __P ((int __n, fd_set *__readfds, fd_set *__writefds,
83 fd_set *__exceptfds, struct timeval *__timeout));
84 #if __POSIX_VISIBLE >= 200112
85 int pselect __P ((int __n, fd_set *__readfds, fd_set *__writefds,
86 fd_set *__exceptfds, const struct timespec *__timeout,
87 const sigset_t *__set));
88 #endif
90 __END_DECLS
92 #endif /* !__INSIDE_CYGWIN_NET__ */
94 #endif /* !(_WINSOCK_H || _WINSOCKAPI_ || __USE_W32_SOCKETS) */
96 #endif /* sys/select.h */