#ifndef _SYS_TYPES_H
#define _SYS_TYPES_H

/* The <sys/types.h> header contains important data type definitions.
 * It is considered good programming practice to use these definitions, 
 * instead of the underlying base type.  By convention, all type names end 
 * with _t.
 */

/*  N.B Not all these types are relevant within QDOS, but they are left
 *      in for guidance in case any routines are ported to QDOS.
 */

/* The type size_t holds the result of the size_of operator.  At first glance,
 * it seems obvious that it should be an unsigned int, but this is not always 
 * the case. For example, MINIX-ST (68000) has 32-bit pointers and 16-bit
 * integers. When one asks for the size of a 70K struct or array, the result 
 * requires 17 bits to express, so size_t must be a long type.
 */
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned long size_t;       /* Type returned by sizeof operator */
#endif

#ifndef _TIME_T
#define _TIME_T
typedef long    time_t;             /* time in sec since 1 Jan 1970 0000 GMT */
#endif

#ifndef _CLOCK_T
#define _CLOCK_T
typedef long    clock_t;
#endif

#ifndef _WCHAR_T
#define _WCHAR_T
typedef char            wchar_t;    /* type for wide characters */
#endif /* _WCHAR_T */

typedef unsigned long   dev_t;      /* holds (major|minor) device pair */
typedef unsigned char   gid_t;      /* group id */
typedef unsigned int    ino_t;      /* i-node number */
typedef int             mode_t;     /* mode number within an i-node */
typedef unsigned char   nlkink_t;   /* number-of-links field within an i-node */
typedef long            off_t;      /* offsets within a file */
typedef long            pid_t;      /* type for pids (must be signed) */
typedef unsigned short  uid_t;      /* user id */
typedef long            ptrdiff_t;

/*
 *  The following types are specific to QDOS
 */
typedef long    datareg_t;
typedef char *  addreg_t;
typedef long    jobid_t;
typedef long    chanid_t;
typedef short   timeout_t;
typedef unsigned char colour_t;

/*
 * types used for portability reasons
 */

#ifndef INT16
#define INT16 short
#endif

#ifndef INT32
#define INT32 long
#endif

#if 0
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#endif

/*************************************************************************
 *
 *                          C A U T I O N
 *                          ~~~~~~~~~~~~~
 *
 *  The remainder of this header contains definitions that are internal
 *  to the way that the C68 libraries have been implemented on QDOS/SMS.
 *  These definitions should not be used by any user program as they are
 *  subject to change without notice.
 *
 *************************************************************************/

#ifdef _LIBRARY_SOURCE
#ifndef __LIBRARY__
#define __LIBRARY__
#endif
#endif /* _LIBRARY_SOURCE */

#ifdef __LIBRARY__
/**
 *
 *  The following definitions are used to allow functions definitions
 *  to be written so that they expand to either K&R or ANSI style
 *  according to whether __STDC__ is defined.   This is important when
 *  the functions have parameters of type 'short', 'char' or 'float'
 *  as the parameter promotion rules are different.
 *
**/
#ifdef __STDC__
#define _LIB_F0_(t1) (t1)
#define _LIB_F1_(t1,n1) \
                (t1 n1)
#define _LIB_F2_(t1,n1,t2,n2) \
                (t1 n1, t2 n2)
#define _LIB_F3_(t1,n1,t2,n2,t3,n3) \
                (t1 n1, t2 n2,t3 n3)
#define _LIB_F4_(t1,n1,t2,n2,t3,n3,t4,n4) \
                (t1 n1, t2 n2,t3 n3, t4 n4)
#define _LIB_F5_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5) \
                (t1 n1, t2 n2,t3 n3, t4 n4, t5 n5)
#define _LIB_F6_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,t6,n6) \
                (t1 n1, t2 n2,t3 n3, t4 n4, t5 n5, t6 n6)
#define _LIB_F7_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,t6,n6,t7,n7) \
                (t1 n1, t2 n2,t3 n3, t4 n4, t5 n5, t6 n6, t7 n7)
#define _LIB_F8_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,t6,n6,t7,n7,t8,n8) \
                (t1 n1, t2 n2,t3 n3, t4 n4, t5 n5, t6 n6, t7 n7, t8 n8)
#define _LIB_F9_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,t6,n6,t7,n7,t8,n8,t9,n9) \
                (t1 n1, t2 n2,t3 n3, t4 n4, t5 n5, t6 n6, t7 n7, t8 n8, t9 n9)
#define _LIB_F10_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,t6,n6,t7,n7,t8,n8,t9,n9,t10,n10) \
                (t1 n1, t2 n2,t3 n3, t4 n4, t5 n5, t6 n6, t7 n7, t8 n8, t9 n9, t10 n10)
#else
#define _LIB_F0(t1)  ()
#define _LIB_F1_(t1,n1) \
                (n1) t1 n1;
#define _LIB_F2_(t1,n1,t2,n2) \
                (n1, n2)  t1 n1; t2 n2;
#define _LIB_F3_(t1,n1,t2,n2,t3,n3) \
                (n1, n2, n3)  t1 n1; t2 n2; t3 n3;
#define _LIB_F4_(t1,n1,t2,n2,t3,n3,t4,n4) \
                (n1, n2, n3, n4)  t1 n1; t2 n2; t3 n3; t4 n4;
#define _LIB_F5_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5) \
                (n1, n2, n3, n4, n5)  t1 n1; t2 n2; t3 n3; t4 n4; t5 n5;
#define _LIB_F6_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,t6,n6) \
                (n1, n2, n3, n4, n5, n6) \
                 t1 n1; t2 n2; t3 n3; t4 n4; t5 n5; t6 n6;
#define _LIB_F7_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,t6,n6,t7,n7) \
                (n1, n2, n3, n4, n5, n6, n7) \
                 t1 n1; t2 n2; t3 n3; t4 n4; t5 n5; t6 n6; t7 n7;
#define _LIB_F8_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,t6,n6,t7,n7,t8,n8) \
                (n1, n2, n3, n4, n5,n6, n7,n8) \
                 t1 n1; t2 n2; t3 n3; t4 n4; t5 n5; t6 n6; t7 n7; t8 n8;
#define _LIB_F9_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,t6,n6,t7,n7,t8,n8,t9,n9) \
                (n1, n2, n3, n4, n5,n6, n7,n8,n9) \
                 t1 n1; t2 n2; t3 n3; t4 n4; t5 n5; t6 n6; t7 n7; t8 n8; t9 n9;
#define _LIB_F10_(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,t6,n6,t7,n7,t8,n8,t9,n9,t10,n10) \
                (n1, n2, n3, n4, n5,n6, n7,n8,n9,n10) \
                 t1 n1; t2 n2; t3 n3; t4 n4; t5 n5; t6 n6; t7 n7; t8 n8; t9 n9; t10 n10;
#endif /* __STDC__ */
#endif /* __LIBRARY __ */


#endif /*_SYS_TYPES_H */

