| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: fd_set.h,v 1.5 2010/07/08 18:56:17 rmind Exp $ */ | | 1 | /* $NetBSD: fd_set.h,v 1.6 2015/11/06 15:41:25 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1992, 1993 | | 4 | * Copyright (c) 1992, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -49,27 +49,29 @@ typedef __uint32_t __fd_mask; | | | @@ -49,27 +49,29 @@ typedef __uint32_t __fd_mask; |
49 | #define __NFDBITS (32) | | 49 | #define __NFDBITS (32) |
50 | #define __NFDSHIFT (5) | | 50 | #define __NFDSHIFT (5) |
51 | #define __NFDMASK (__NFDBITS - 1) | | 51 | #define __NFDMASK (__NFDBITS - 1) |
52 | | | 52 | |
53 | /* | | 53 | /* |
54 | * Select uses bit fields of file descriptors. These macros manipulate | | 54 | * Select uses bit fields of file descriptors. These macros manipulate |
55 | * such bit fields. Note: FD_SETSIZE may be defined by the user. | | 55 | * such bit fields. Note: FD_SETSIZE may be defined by the user. |
56 | */ | | 56 | */ |
57 | | | 57 | |
58 | #ifndef FD_SETSIZE | | 58 | #ifndef FD_SETSIZE |
59 | #define FD_SETSIZE 256 | | 59 | #define FD_SETSIZE 256 |
60 | #endif | | 60 | #endif |
61 | | | 61 | |
62 | #define __NFD_SIZE (((FD_SETSIZE) + (__NFDBITS - 1)) / __NFDBITS) | | 62 | #define __NFD_LEN(a) (((a) + (__NFDBITS - 1)) / __NFDBITS) |
| | | 63 | #define __NFD_SIZE __NFD_LEN(FD_SETSIZE) |
| | | 64 | #define __NFD_BYTES(a) (__NFD_LEN(a) * sizeof(__fd_mask)) |
63 | | | 65 | |
64 | typedef struct fd_set { | | 66 | typedef struct fd_set { |
65 | __fd_mask fds_bits[__NFD_SIZE]; | | 67 | __fd_mask fds_bits[__NFD_SIZE]; |
66 | } fd_set; | | 68 | } fd_set; |
67 | | | 69 | |
68 | #define FD_SET(n, p) \ | | 70 | #define FD_SET(n, p) \ |
69 | ((p)->fds_bits[(unsigned)(n) >> __NFDSHIFT] |= (1 << ((n) & __NFDMASK))) | | 71 | ((p)->fds_bits[(unsigned)(n) >> __NFDSHIFT] |= (1 << ((n) & __NFDMASK))) |
70 | #define FD_CLR(n, p) \ | | 72 | #define FD_CLR(n, p) \ |
71 | ((p)->fds_bits[(unsigned)(n) >> __NFDSHIFT] &= ~(1 << ((n) & __NFDMASK))) | | 73 | ((p)->fds_bits[(unsigned)(n) >> __NFDSHIFT] &= ~(1 << ((n) & __NFDMASK))) |
72 | #define FD_ISSET(n, p) \ | | 74 | #define FD_ISSET(n, p) \ |
73 | ((p)->fds_bits[(unsigned)(n) >> __NFDSHIFT] & (1 << ((n) & __NFDMASK))) | | 75 | ((p)->fds_bits[(unsigned)(n) >> __NFDSHIFT] & (1 << ((n) & __NFDMASK))) |
74 | #if __GNUC_PREREQ__(2, 95) | | 76 | #if __GNUC_PREREQ__(2, 95) |
75 | #define FD_ZERO(p) (void)__builtin_memset((p), 0, sizeof(*(p))) | | 77 | #define FD_ZERO(p) (void)__builtin_memset((p), 0, sizeof(*(p))) |