home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !unixlib / source / clib / sys / h / select < prev    next >
Encoding:
Text File  |  2004-09-05  |  2.5 KB  |  83 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/sys/select.h,v $
  4.  * $Date: 2004/04/17 10:51:15 $
  5.  * $Revision: 1.6 $
  6.  * $State: Exp $
  7.  * $Author: nick $
  8.  *
  9.  ***************************************************************************/
  10.  
  11. /* POSIX 1003.1g: 6.2 Select from File Descriptor Sets */
  12.  
  13. #ifndef __SYS_SELECT_H
  14. #define __SYS_SELECT_H
  15.  
  16. #ifndef __UNIXLIB_FEATURES_H
  17. #include <unixlib/features.h>
  18. #endif
  19.  
  20. #ifndef __UNIXLIB_TYPES_H
  21. #include <unixlib/types.h>
  22. #endif
  23.  
  24. #define __need_timeval
  25. #include <sys/time.h>
  26.  
  27. #define __need_timespec
  28. #include <time.h>
  29.  
  30. __BEGIN_DECLS
  31.  
  32. /* Number of descriptors that can fit in an `fd_set'.  */
  33. #define    FD_SETSIZE    256
  34.  
  35. /* It's easier to assume 8-bit bytes than to get CHAR_BIT.  */
  36. #define    NFDBITS    (sizeof (unsigned long int) * 8)
  37. #define    FDELT(d)    ((d) / NFDBITS)
  38. #define    FDMASK(d)    (1ul << ((d) % NFDBITS))
  39.  
  40. typedef unsigned long int __fd_mask;
  41.  
  42. typedef struct
  43.   {
  44.     /* Some braindead old software uses this member name.  */
  45.     __fd_mask fds_bits[(FD_SETSIZE + (NFDBITS - 1)) / NFDBITS];
  46.   } __fd_set;
  47.  
  48. #define    FD_ZERO(set) ((void) memset (set, 0, sizeof (*(set))))
  49. #define    FD_SET(d, set)    ((set)->fds_bits[FDELT(d)] |= FDMASK(d))
  50. #define    FD_CLR(d, set)    ((set)->fds_bits[FDELT(d)] &= ~FDMASK(d))
  51. #define    FD_ISSET(d, set)    ((set)->fds_bits[FDELT(d)] & FDMASK(d))
  52.  
  53.  
  54. typedef __fd_mask fd_mask;
  55. typedef __fd_set fd_set;
  56.  
  57. /* This contains the prototype for select */
  58. #define howmany(x, y) (((x)+((y)-1))/(y))
  59.  
  60. /* Check the first NFDS descriptors each in READFDS (if not NULL) for read
  61.    readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
  62.    (if not NULL) for exceptional conditions.  If TIMEOUT is not NULL, time out
  63.    after waiting the interval specified therein.  Returns the number of ready
  64.    descriptors, or -1 for errors.  */
  65.  
  66. int select (int __nfds, __fd_set *__readfds, __fd_set *__writefds,
  67.         __fd_set *__exceptfds, struct timeval *__timeout) __THROW;
  68.  
  69. /* Same as pselect but with higher resolution for the timeout.  */
  70. int pselect (int __nfds, __fd_set *__readfds, __fd_set *__writefds,
  71.          __fd_set *__exceptfds, const struct timespec *__timeout,
  72.          const __sigset_t *__sigmask) __THROW;
  73.  
  74. #ifdef __UNIXLIB_INTERNALS
  75. /* SWI veneer. Do not use directly.  */
  76. int _select (int __nfds, __fd_set *__readfds, __fd_set *__writefds,
  77.          __fd_set *__exceptfds, const struct timeval *__timeout) __THROW;
  78. #endif  /* __UNIXLIB_INTERNALS */
  79.  
  80. __END_DECLS
  81.  
  82. #endif
  83.