diff --git a/include/unistd.h b/include/unistd.h index 9227c63d0a06..977e9b109d72 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -489,7 +489,12 @@ int rresvport(int *); int rresvport_af(int *, int); int ruserok(const char *, int, const char *, const char *); void *sbrk(intptr_t); +#if __BSD_VISIBLE +#ifndef _SELECT_DECLARED +#define _SELECT_DECLARED int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); +#endif +#endif int setdomainname(const char *, int); int setgroups(int, const gid_t *); void sethostid(long); diff --git a/sys/sys/select.h b/sys/sys/select.h index 396edae81dc6..11aacdd1e513 100644 --- a/sys/sys/select.h +++ b/sys/sys/select.h @@ -43,23 +43,61 @@ #include /* + * XXX * Other things required for this header which we do not presently implement: * * struct timeval (with suseconds_t) - * fd_set - * FD_* macros - * - * Temporarily get all of these things from , which has too - * much pollution to be used here but will do for now. (Eventually, the - * latter two will move to this file and be included *from* - * in the BSD namespace.) */ -#include /* XXX dependency reversed */ + +typedef unsigned long __fd_mask; +#if __BSD_VISIBLE +typedef __fd_mask fd_mask; +#endif + +/* + * Select uses bit masks of file descriptors in longs. These macros + * manipulate such bit fields (the filesystem macros use chars). + * FD_SETSIZE may be defined by the user, but the default here should + * be enough for most uses. + */ +#ifndef FD_SETSIZE +#define FD_SETSIZE 1024U +#endif + +#define _NFDBITS (sizeof(__fd_mask) * 8) /* bits per mask */ +#if __BSD_VISIBLE +#define NFDBITS _NFDBITS +#endif + +#ifndef _howmany +#define _howmany(x, y) (((x) + ((y) - 1)) / (y)) +#endif + +typedef struct fd_set { + __fd_mask fds_bits[_howmany(FD_SETSIZE, _NFDBITS)]; +} fd_set; + +#define __fdset_mask(n) ((fd_mask)1 << ((n) % _NFDBITS)) +#define FD_CLR(n, p) ((p)->fds_bits[(n)/_NFDBITS] &= ~__fdset_mask(n)) +#if __BSD_VISIBLE +/* XXX bcopy() not in scope, so is required; see also FD_ZERO(). */ +#define FD_COPY(f, t) bcopy(f, t, sizeof(*(f))) +#endif +#define FD_ISSET(n, p) ((p)->fds_bits[(n)/_NFDBITS] & __fdset_mask(n)) +#define FD_SET(n, p) ((p)->fds_bits[(n)/_NFDBITS] |= __fdset_mask(n)) +#define FD_ZERO(p) bzero(p, sizeof(*(p))) #ifndef _KERNEL +struct timeval; + __BEGIN_DECLS int pselect(int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict); +#ifndef _SELECT_DECLARED +#define _SELECT_DECLARED +/* XXX missing restrict type-qualifier */ +int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); +#endif __END_DECLS #endif /* !_KERNEL */ diff --git a/sys/sys/types.h b/sys/sys/types.h index 6ceb747d9919..bd656ded073b 100644 --- a/sys/sys/types.h +++ b/sys/sys/types.h @@ -255,37 +255,22 @@ typedef __timer_t timer_t; #define _TIMER_T_DECLARED #endif +/* + * The following are all things that really shouldn't exist in this header, + * since its purpose is to provide typedefs, not miscellaneous doodads. + */ #if __BSD_VISIBLE + +#include + +/* XXX should be moved to . */ #define NBBY 8 /* number of bits in a byte */ -/* - * Select uses bit masks of file descriptors in longs. These macros - * manipulate such bit fields (the filesystem macros use chars). - * FD_SETSIZE may be defined by the user, but the default here should - * be enough for most uses. - */ -#ifndef FD_SETSIZE -#define FD_SETSIZE 1024U -#endif - -typedef unsigned long fd_mask; -#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ - +/* XXX should be removed, since has this. */ #ifndef howmany #define howmany(x, y) (((x) + ((y) - 1U)) / (y)) #endif -typedef struct fd_set { - fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; -} fd_set; - -#define _fdset_mask(n) ((fd_mask)1 << ((n) % NFDBITS)) -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= _fdset_mask(n)) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~_fdset_mask(n)) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & _fdset_mask(n)) -#define FD_COPY(f, t) bcopy(f, t, sizeof(*(f))) -#define FD_ZERO(p) bzero(p, sizeof(*(p))) - /* * These declarations belong elsewhere, but are repeated here and in * to give broken programs a better chance of working with