/* portable.h */
/* Definitions for portable I/O

The contents of this file are hereby released to the public domain.

                           -- Rahul Dhesi 1986/11/14

Definitions are:

OPEN        binary open
CREATE      binary create
OPEN_T      text open
CREATE_T    text create

Plus flags for fopen().
*/

/* 
Microsoft C.  The only difference between I/O flags for standard UNIX I/O
and Microsoft C is that Microsoft C requires the "O_BINARY" flag in open() 
and the "rb" string instead of "r" in fopen().  These are needed to prevent
the library from doing LF <--> CR LF translation.
*/

#ifdef   MSC
#define  P_RDWR         S_IWRITE | S_IREAD
#define  F_WRITE        O_WRONLY
#define  F_READ         O_RDONLY
#define  F_RDWR         O_RDWR
#define  FRDSTR         "rb"     /* readonly string for fopen() */
#define  FRWSTR         "r+b"    /* read/write string for fopen() */
#define  CREATE(x,y)    open (x, y|O_CREAT|O_TRUNC|O_BINARY, P_RDWR)
#define  OPEN(x,y)      open (x, y|O_BINARY)
#define  CREATE_T(x,y)  open (x, y|O_CREAT|O_TRUNC, P_RDWR)
#define  OPEN_T(x,y)    open (x, y)
#define  MKDIR(x)       mkdir(x)
#endif

#ifdef GENERIC
/* UNIX I/O, but MKDIR() is a no-operation */
#define  NIX_IO      /* standard UNIX I/O */
#define  MKDIR(x)
#endif

/* UNIX System V release 2.1 */
#ifdef   SYS_V
#define  NIX_IO      /* standard UNIX I/O */
#define  MKDIR(x)       mkdir(x) /* define this in sysv.c */
#endif

/* Xenix  release 3.0 */
#ifdef   XENIX
#define  NIX_IO      /* standard UNIX I/O */
#endif

/* 4.3BSD */
#ifdef BSD4_3
#define NIX_IO       /* standard UNIX I/O */
#define  MKDIR(x)       mkdir(x, 0777)
#endif

/* Amiga */
#ifdef MCH_AMIGA
/* Need to define a macro to make a new directory */
#define MKDIR(x)        {}
#define NIX_IO
#endif

/* Standard UNIX I/O definitions */
#ifdef   NIX_IO
/* #define  P_RDWR         S_IWRITE | S_IREAD */
#define  P_RDWR         0644
#define  F_WRITE        O_WRONLY
#define  F_READ         O_RDONLY
#define  F_RDWR         O_RDWR
#define  FRDSTR         "r"      /* readonly string for fopen() */
#define  FRWSTR         "r+"     /* read/write string for fopen() */
#define  CREATE(x,y)    open (x, y|O_CREAT|O_TRUNC, P_RDWR)
#define  OPEN(x,y)      open (x, y)
#define  CREATE_T(x,y)  open (x, y|O_CREAT|O_TRUNC, P_RDWR)
#define  OPEN_T(x,y)    open (x, y)
#endif   /* NIX_IO */

/* VAX/VMS version 4.3.  Not yet tested.  */
#ifdef   VMS
#define  P_RDWR         0        /* use user's default protection */
#define  F_WRITE        O_RDWR   /* VAX/VMS random write requires O_RDWR */
#define  F_READ         O_RDONLY
#define  F_RDWR         O_RDWR
#define  FRDSTR         "r"      /* readonly string for fopen() */
#define  FRWSTR         "r+"     /* read/write string for fopen() */
#define  CREATE(x,y)    open (x, y|O_CREAT|O_TRUNC, P_RDWR)
#define  OPEN(x,y)      open (x, y)
#define  CREATE_T(x,y)  open (x, y|O_CREAT|O_TRUNC, P_RDWR)
#define  OPEN_T(x,y)    open (x, y)
#endif

/* MIX C compiler for MS-DOS.  Follows K&R closely. Not yet tested. */
#ifdef   MIX
#define  P_RDWR         0
#define  F_WRITE        1
#define  F_READ         0
#define  F_RDWR         2
#define  FRDSTR         "r"
#define  FRWSTR         "r+"
#define  CREATE(x,y)    creat (x,y)
#define  OPEN(x,y)      open (x,y)
#define  CREATE_T(x,y)  creat (x,y)
#define  OPEN_T(x,y)    open (x,y)
#endif

