/* Copyright (C) 1981, 1982 by Manx Software Systems */

int errno;
#define FLT_FAULT	0		/* vector for floating-point faults */
#define	MAXVEC		4		/* reserve 4 vectors for now */
int (*Sysvec[MAXVEC])();
/*
 * if MAXCHAN is changed then the initialization of chantab in croot.c
 * should be adjusted so that it initializes EXACTLY MAXCHAN elements of 
 * the array.  If this is not done, the I/O library may exhibit
 * strange behavior.
 * Also change MAXCHAN in io.h
 */
#define MAXCHAN	11	/* maximum number of I/O channels */

/*
 * argument to device routines.
 *		this is a typedef to allow future redeclaration to guarantee 
 *		enough space to store either a pointer or an integer.
 */
typedef char *arg;

/*
 * channel table: relates fd's to devices
 */
struct channel {
	char c_read;
	char c_write;
	char c_ioctl;
	char c_seek;
	int (*c_close)();
	arg c_arg;
} ;
struct channel chantab[MAXCHAN];

#define NULL 0
#define EOF -1
#define BUFSIZ 1024
/*
 * Also change the value of MAXSTREAM in stdio.h.
 */
#define MAXSTREAM 11

#define _BUSY	0x01
#define _ALLBUF	0x02
#define _DIRTY	0x04
#define _EOF	0x08
#define _IOERR	0x10

typedef struct {
	char *_bp;			/* current position in buffer */
	char *_bend;		/* last character in buffer + 1 */
	char *_buff;		/* address of buffer */
	char _flags;		/* open mode, etc. */
	char _unit;			/* token returned by open */
	char _bytbuf;		/* single byte buffer for unbuffer streams */
	int	_buflen;		/* length of buffer */
} FILE;

FILE Cbuffs[MAXSTREAM];
char *Stdbufs;			/* free list of buffers */
long ftell();

#define stdin (&Cbuffs[0])
#define stdout (&Cbuffs[1])
#define stderr (&Cbuffs[2])
#define getchar() agetc(stdin)
#define putchar(c) aputc(c, stdout)
#define feof(fp) (((fp)->_flags&_EOF)!=0)
#define ferror(fp) (((fp)->_flags&_IOERR)!=0)
#define clearerr(fp) ((fp)->_flags &= ~(_IOERR|_EOF))
#define fileno(fp) ((fp)->_unit)

#define O_RDONLY	0
#define O_WRONLY	1
#define O_RDWR		2
#define O_CREAT		0x0100
#define O_TRUNC		0x0200
#define O_EXCL		0x0400
