#ifndef SYS_TYPES_H
#define SYS_TYPES_H

/*
**       $VER: sys/types.h 1.4 (07.08.99)
**            Includes Release 45.00
**
**     Copyright © 1996/99 by CyberdyneSystems
**
**            written by Matthias Henze
**               All Rights Reserved
*/

#ifndef STORMAMIGA_H
  #include <stormamiga.h>
#endif
#ifndef  _INCLUDE_STRING_H
  #include <string.h>
#endif

typedef ulong   vm_offset_t;
typedef ulong   vm_size_t;

typedef int     ssize_t;

/* Basic integral types. */
#define __BIT_TYPES_DEFINED__
typedef schar     int8_t;
typedef uchar     u_int8_t;
typedef short     int16_t;
typedef ushort    u_int16_t;
typedef int       int32_t;
typedef uint      u_int32_t;
typedef llong     int64_t;
typedef ullong    u_int64_t;
typedef int       register_t;

#ifndef _POSIX_SOURCE
  typedef uchar   u_char;
  typedef ushort  u_short;
  typedef uint    u_int;
  typedef ulong   u_long;
#endif

typedef ullong    u_quad_t;   /* quads */
typedef llong     quad_t;
typedef quad_t *  qaddr_t;

typedef char *    caddr_t;    /* core address */
typedef int       daddr_t;    /* disk address */
typedef short     dev_t;      /* device number */
typedef uint      fixpt_t;    /* fixed point number */
typedef ushort    gid_t;      /* group id */
typedef uint      ino_t;      /* inode number */
typedef long      key_t;      /* IPC key (for Sys V IPC) */
typedef ushort    mode_t;     /* permissions */
typedef ushort    nlink_t;    /* link count */
typedef int       off_t;      /* file offset */
typedef int       pid_t;      /* process id */
typedef int       rlim_t;     /* resource limit */
typedef int       segsz_t;    /* segment size */
typedef int       swblk_t;    /* swap offset */
typedef ushort    uid_t;      /* user id */

#ifndef _POSIX_SOURCE
/* Major, minor numbers, dev_t's. */
#define major(x)        ((int)(((uint)(x) >> 8) & 0xff))
#define minor(x)        ((int)((x) & 0xff))
#define makedev(x,y)    ((dev_t)(((x) << 8) | (y)))
#endif

#define NBBY    8             /* number of bits in a byte */

/*
 * Select uses bit masks of file descriptors in longs.  These macros
 * manipulate such bit fields (the filesystem macros use chars).
 * FD_SETSIZE may be defined by the user, but the default here should
 * be enough for most uses.
 */
#ifndef FD_SETSIZE
 #define FD_SETSIZE      256
#endif

typedef int fd_mask;
#define NFDBITS (sizeof(fd_mask) * NBBY)  /* bits per mask */

#ifndef howmany
  #define howmany(x, y)   (((x) + ((y) - 1)) / (y))
#endif

typedef struct fd_set
{
  fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
} fd_set;

#define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
#define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
#define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
#define FD_COPY(f, t)   bcopy(f, t, sizeof(*(f)))
#define FD_ZERO(p)      bzero(p, sizeof(*(p)))
#endif /* _POSIX_SOURCE */

#endif /* SYS_TYPES_H */

