diff options
author | mike <mike@FreeBSD.org> | 2002-09-23 17:45:51 +0000 |
---|---|---|
committer | mike <mike@FreeBSD.org> | 2002-09-23 17:45:51 +0000 |
commit | e3273ff5b0022b8d058b3f317c0778568a5c5f11 (patch) | |
tree | 3f1529390b129ebee6a87da08c17231bebf3e590 | |
parent | a6b32a877e18330dc811d7f76a14164a331d1cf7 (diff) | |
download | FreeBSD-src-e3273ff5b0022b8d058b3f317c0778568a5c5f11.zip FreeBSD-src-e3273ff5b0022b8d058b3f317c0778568a5c5f11.tar.gz |
o Move select() helper macros from <sys/types.h> to <sys/select.h>.
o Include <sys/select.h> from <sys/types.h> in the __BSD_VISIBLE case,
so applications and base software can be slowly updated.
o Prototype select() in <sys/select.h>. It was previously only
prototyped in <unistd.h>.
o Add some XXX's to <sys/types.h>.
Reviewed by: -standards
-rw-r--r-- | include/unistd.h | 5 | ||||
-rw-r--r-- | sys/sys/select.h | 54 | ||||
-rw-r--r-- | sys/sys/types.h | 31 |
3 files changed, 59 insertions, 31 deletions
diff --git a/include/unistd.h b/include/unistd.h index 9227c63..977e9b1 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 396edae..11aacdd 100644 --- a/sys/sys/select.h +++ b/sys/sys/select.h @@ -43,23 +43,61 @@ #include <sys/timespec.h> /* + * 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 <sys/types.h>, 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* <sys/types.h> - * in the BSD namespace.) */ -#include <sys/types.h> /* 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 <strings.h> 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 6ceb747..bd656de 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 -#if __BSD_VISIBLE -#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. + * The following are all things that really shouldn't exist in this header, + * since its purpose is to provide typedefs, not miscellaneous doodads. */ -#ifndef FD_SETSIZE -#define FD_SETSIZE 1024U -#endif +#if __BSD_VISIBLE -typedef unsigned long fd_mask; -#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ +#include <sys/select.h> +/* XXX should be moved to <sys/param.h>. */ +#define NBBY 8 /* number of bits in a byte */ + +/* XXX should be removed, since <sys/param.h> 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 * <stdio.h> to give broken programs a better chance of working with |