select.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * include/bits/select.h -- fd_set operations
  3. *
  4. * Copyright (C) 2003 John Williams <jwilliams@itee.uq.edu.au>
  5. * Copyright (C) 2001 NEC Corporation
  6. * Copyright (C) 2001 Miles Bader <miles@gnu.org>
  7. * Copyright (C) 1997, 1998 Free Software Foundation, Inc.
  8. *
  9. * This file is subject to the terms and conditions of the GNU Lesser
  10. * General Public License. See the file COPYING.LIB in the main
  11. * directory of this archive for more details.
  12. */
  13. #ifndef _SYS_SELECT_H
  14. # error "Never use <bits/select.h> directly; include <sys/select.h> instead."
  15. #endif
  16. #ifdef __GNUC__
  17. /* We don't use `memset' because this would require a prototype and
  18. the array isn't too big. */
  19. #define __FD_ZERO(s) \
  20. do { \
  21. unsigned int __i; \
  22. fd_set *__arr = (s); \
  23. for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \
  24. __FDS_BITS (__arr)[__i] = 0; \
  25. } while (0)
  26. #define __FD_SET(fd, s) \
  27. do { \
  28. int __fd = (fd); \
  29. unsigned int *__addr = (unsigned int *)&__FDS_BITS (s); \
  30. *__addr |= (1 << __fd); \
  31. } while (0)
  32. #define __FD_CLR(fd, s) \
  33. do { \
  34. int __fd = (fd); \
  35. unsigned int *__addr = (unsigned int *)&__FDS_BITS (s); \
  36. *__addr &= ~(1 << __fd); \
  37. } while (0)
  38. #define __FD_ISSET(fd, s) \
  39. ({ \
  40. int __fd = (fd); \
  41. unsigned int *__addr = (unsigned int *)&__FDS_BITS (s); \
  42. int res; \
  43. res = (*__addr & (1 << fd)) ? 1 : 0; \
  44. })
  45. #else /* !__GNUC__ */
  46. #define __FD_SET(d, s) (__FDS_BITS (s)[__FDELT(d)] |= __FDMASK(d))
  47. #define __FD_CLR(d, s) (__FDS_BITS (s)[__FDELT(d)] &= ~__FDMASK(d))
  48. #define __FD_ISSET(d, s) ((__FDS_BITS (s)[__FDELT(d)] & __FDMASK(d)) != 0)
  49. #endif /* __GNUC__ */