diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index 59628110f13f..5ef9059e5deb 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -730,9 +730,9 @@ selscan(p, ibits, obits, nfd) fd_mask **ibits, **obits; int nfd; { - register struct filedesc *fdp = p->p_fd; - register int msk, i, j, fd; - register fd_mask bits; + struct filedesc *fdp = p->p_fd; + int msk, i, fd; + fd_mask bits; struct file *fp; int n = 0; /* Note: backend also returns POLLHUP/POLLERR if appropriate. */ @@ -743,14 +743,16 @@ selscan(p, ibits, obits, nfd) continue; for (i = 0; i < nfd; i += NFDBITS) { bits = ibits[msk][i/NFDBITS]; - while ((j = ffs(bits)) && (fd = i + --j) < nfd) { - bits &= ~(1 << j); + /* ffs(int mask) not portable, fd_mask is long */ + for (fd = i; bits && fd < nfd; fd++, bits >>= 1) { + if (!(bits & 1)) + continue; fp = fdp->fd_ofiles[fd]; if (fp == NULL) return (EBADF); if (fo_poll(fp, flag[msk], fp->f_cred, p)) { obits[msk][(fd)/NFDBITS] |= - (1 << ((fd) % NFDBITS)); + ((fd_mask)1 << ((fd) % NFDBITS)); n++; } } diff --git a/sys/sys/types.h b/sys/sys/types.h index 34a115409de0..fadbb7de09d9 100644 --- a/sys/sys/types.h +++ b/sys/sys/types.h @@ -178,9 +178,10 @@ typedef struct fd_set { fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; } fd_set; -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) +#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)))