FD_ISSET must return an int. this is the easiest way.
authorRich Felker <dalias@aerifal.cx>
Sat, 24 Sep 2011 02:24:33 +0000 (22:24 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 24 Sep 2011 02:24:33 +0000 (22:24 -0400)
casting to int would not be correct because high bits could be lost.
mapping the high bits down onto low bits would be costlier in the
common case where the result is just used in a conditional. changing
the type of the bit array elements to int would permute the order of
the bit array on 64-bit big endian systems, so that's not an option
either.

include/sys/select.h

index cbe35a4..47d195f 100644 (file)
@@ -25,7 +25,7 @@ typedef struct
 #define FD_ZERO(s) do { int __i; unsigned long *__b=(s)->fds_bits; for(__i=sizeof (fd_set)/sizeof (long); __i; __i--) *__b++=0; } while(0)
 #define FD_SET(d, s)   ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long)))))
 #define FD_CLR(d, s)   ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long)))))
 #define FD_ZERO(s) do { int __i; unsigned long *__b=(s)->fds_bits; for(__i=sizeof (fd_set)/sizeof (long); __i; __i--) *__b++=0; } while(0)
 #define FD_SET(d, s)   ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long)))))
 #define FD_CLR(d, s)   ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long)))))
-#define FD_ISSET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long)))))
+#define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long)))))
 
 int select (int, fd_set *, fd_set *, fd_set *, struct timeval *);
 int pselect (int, fd_set *, fd_set *, fd_set *, const struct timespec *, const sigset_t *);
 
 int select (int, fd_set *, fd_set *, fd_set *, struct timeval *);
 int pselect (int, fd_set *, fd_set *, fd_set *, const struct timespec *, const sigset_t *);