/*
 * sys/select.h POSIX - select types
 *
 * =========================================================================
 *
 *                          Open Watcom Project
 *
 * Copyright (c) 2004-2026 The Open Watcom Contributors. All Rights Reserved.
 *
 *    This file is automatically generated. Do not edit directly.
 *
 * =========================================================================
 */
#ifndef _SYS_SELECT_H_INCLUDED
#define _SYS_SELECT_H_INCLUDED

#ifndef _ENABLE_AUTODEPEND
 #pragma read_only_file
#endif

#ifndef __COMDEF_H_INCLUDED
 #include <_comdef.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#pragma pack( __push, 4 )

#ifndef _FDSET_DEFINED
#define _FDSET_DEFINED

/* The fd_set member is required to be an array of longs.  */
typedef long fd_mask;

#define FD_SETSIZE          1024
#define __NFDBITS           (8 * sizeof (fd_mask))
#define __FDELT(__d)        ((__d) / __NFDBITS)
#define __FDMASK(__d)       ((fd_mask) 1 << ((__d) % __NFDBITS))
#define __FDS_BITS(__set)   ((__set)->fds_bits)

/* fd_set for select */
typedef struct {
    fd_mask fds_bits[FD_SETSIZE / __NFDBITS];
} fd_set;

#define FD_ZERO(__set) \
    do { \
        unsigned int __i; \
        fd_set *__arr = (__set); \
        for(__i = 0; __i < sizeof(fd_set) / sizeof(fd_mask); ++__i) \
            __FDS_BITS(__arr)[__i] = 0; \
    } while( 0 )
#define FD_SET(__d,__set)   (__FDS_BITS(__set)[__FDELT(__d)] |= __FDMASK(__d))
#define FD_CLR(__d,__set)   (__FDS_BITS(__set)[__FDELT(__d)] &= ~__FDMASK(__d))
#define FD_ISSET(__d,__set) (__FDS_BITS(__set)[__FDELT(__d)] & __FDMASK(__d))

#endif  /* !_FDSET_DEFINED */

#ifndef _TIMEVAL_DEFINED
#define _TIMEVAL_DEFINED

#ifdef __cplusplus
 #ifndef _STDTIME_T_DEFINED
 #define _STDTIME_T_DEFINED
  namespace std {
    typedef signed long time_t;
  }
  typedef std::time_t __w_time_t;
 #endif
 #ifndef _TIME_T_DEFINED
 #define _TIME_T_DEFINED
  #define _TIME_T_DEFINED_
  using std::time_t;
 #endif
#else  /* __cplusplus not defined */
 #ifndef _TIME_T_DEFINED
 #define _TIME_T_DEFINED
  #define _TIME_T_DEFINED_
  typedef signed long time_t;
  typedef time_t __w_time_t;
 #endif
#endif /* __cplusplus not defined */

typedef long    suseconds_t;

struct timeval {
    time_t      tv_sec;     /* seconds */
    suseconds_t tv_usec;    /* and microseconds */
};

/*
 * Operations on timevals.
 *
 * NB: timercmp does not work for >= or <=.
 */
#define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
#define timercmp(tvp, uvp, cmp) ((tvp)->tv_sec cmp (uvp)->tv_sec) || \
    (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec )
#define timerclear(tvp)         ((tvp)->tv_sec = (tvp)->tv_usec = 0)

#endif /* !_TIMEVAL_DEFINED */

_WCRTLINK extern int select( int __width, fd_set *__readfds, fd_set *__writefds, fd_set *__exceptfds, struct timeval *__timeout );

#pragma pack( __pop )

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* !_SYS_SELECT_H_INCLUDED */
