Date: Sun, 22 Sep 2002 23:59:43 -0400 From: Mike Barcroft <mike@FreeBSD.org> To: standards@FreeBSD.org Cc: Josef Karthauser <joe@tao.org.uk> Subject: select.diff for review Message-ID: <20020922235943.G91924@espresso.q9media.com>
index | next in thread | raw e-mail
[-- Attachment #1 --]
Attached is a patch which makes <sys/select.h> much more conformant by
bringing over components from <sys/types.h>. Comments appreciated.
Best regards,
Mike Barcroft
[-- Attachment #2 --]
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>.
Index: include/unistd.h
===================================================================
RCS file: /work/repo/src/include/unistd.h,v
retrieving revision 1.58
diff -u -r1.58 unistd.h
--- include/unistd.h 21 Sep 2002 02:08:32 -0000 1.58
+++ include/unistd.h 23 Sep 2002 00:32:15 -0000
@@ -489,7 +489,12 @@
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);
Index: sys/sys/select.h
===================================================================
RCS file: /work/repo/src/sys/sys/select.h,v
retrieving revision 1.13
diff -u -r1.13 select.h
--- sys/sys/select.h 16 Jun 2002 18:40:16 -0000 1.13
+++ sys/sys/select.h 23 Sep 2002 03:49:52 -0000
@@ -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) - 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_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 */
Index: sys/sys/types.h
===================================================================
RCS file: /work/repo/src/sys/sys/types.h,v
retrieving revision 1.70
diff -u -r1.70 types.h
--- sys/sys/types.h 17 Sep 2002 05:05:14 -0000 1.70
+++ sys/sys/types.h 23 Sep 2002 00:33:48 -0000
@@ -255,41 +255,28 @@
#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
* 64-bit off_t's.
+ *
+ * XXX is this still needed?
*/
#ifndef _KERNEL
__BEGIN_DECLS
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020922235943.G91924>
