The macro was hard-coded to 256 but it's common to see it redefined. Let's support this and make sure we always allocate enough entries for the cases where it wouldn't be multiple of 32.
Showing the changes to tools/include (1 of 1 file). Show all
Unified · Split
| @@ -45,7 +45,9 @@ · 44 unmodified lines | ||
| 45 | 45 | #define DT_SOCK 0xc |
| 46 | 46 | |
| 47 | 47 | /* commonly an fd_set represents 256 FDs */ |
| 48 | +#ifndef FD_SETSIZE | |
| 48 | 49 | #define FD_SETSIZE 256 |
| 50 | +#endif | |
| 49 | 51 | |
| 50 | 52 | /* Special FD used by all the *at functions */ |
| 51 | 53 | #ifndef AT_FDCWD |
| @@ -72,7 +74,7 @@ · 20 unmodified lines | ||
| 72 | 74 | |
| 73 | 75 | /* for select() */ |
| 74 | 76 | typedef struct { |
| 75 | − uint32_t fd32[FD_SETSIZE / 32]; | |
| 77 | + uint32_t fd32[(FD_SETSIZE + 31) / 32]; | |
| 76 | 78 | } fd_set; |
| 77 | 79 | |
| 78 | 80 | #define FD_CLR(fd, set) do { \ |
| @@ -101,7 +103,7 @@ typedef struct { · 22 unmodified lines | ||
| 101 | 103 | #define FD_ZERO(set) do { \ |
| 102 | 104 | fd_set *__set = (set); \ |
| 103 | 105 | int __idx; \ |
| 104 | − for (__idx = 0; __idx < FD_SETSIZE / 32; __idx ++) \ | |
| 106 | + for (__idx = 0; __idx < (FD_SETSIZE+31) / 32; __idx ++) \ | |
| 105 | 107 | __set->fd32[__idx] = 0; \ |
| 106 | 108 | } while (0) |
| 107 | 109 | |