/* Modified by jbs@eddie.mit.edu for ANSI C compatbility
 * 
 * Copyright (c) 1980 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 *
 *	@(#)stdio.h	5.3 (Berkeley) 3/15/86
 */

#ifndef _STDIO_H_
#define _STDIO_H_

#define _STDIOLIB_NOANSI_ 1	/* Should be defined if the standard */
				/* system library was not compiled with */
				/* ANSI C.  This changes the types of */
				/* some of th functions (char -> int) */
#include <stddef.h>

/* BSD specific */
#ifndef __STDC__
#include "/usr/include/stdio.h"
#else
extern	struct	_iobuf {
	int	_cnt;
	char	*_ptr;		/* should be unsigned char */
	char	*_base;		/* ditto */
	int	_bufsiz;
	short	_flag;
	char	_file;		/* should be short */
} _iob[];

#define	_IOREAD	01
#define	_IOWRT	02
#define	_IONBF	04
#define	_IOMYBUF	010
#define	_IOEOF	020
#define	_IOERR	040
#define	_IOSTRG	0100
#define	_IOLBF	0200
#define	_IORW	0400
#define	FILE	struct _iobuf
#define	EOF	(-1)

#define	stdin	(&_iob[0])
#define	stdout	(&_iob[1])
#define	stderr	(&_iob[2])
#define	fileno(p)	((p)->_file)

FILE	*fdopen(int, const char *);
FILE	*popen(const char *, const char *);
int     pclose(FILE *);

/* ANSI STD */

#define	BUFSIZ	1024
FILE	*fopen(const char *, const char *);
int	fclose(FILE *);
int	fflush(FILE *);
FILE	*freopen(const char *, const char *, FILE *);
void	setbuf(FILE *, char *);

#define _IOFBF 1
#define _IOLBF 0200
#define _IONBF 04

/* does not do full error checking and is totally untested */
#define setvbuf(f, b, t, s) 	((((t) == _IONBF)  ? (setbuf((f),NULL), 0) \
				 : ((((t) == _IOLBF) ? \
				     (setlinebuf((f)))), \
				    (setbuffer((f),(b),(s))))),0)

#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2

int	fseek(FILE *, long int, int);
long int ftell(FILE *);
void	rewind(FILE *);
int	fgetc(FILE *);
extern int _filbuf(FILE *);
#define	getc(p)		(--(p)->_cnt>=0? (int)(*(unsigned char *)(p)->_ptr++):_filbuf(p))
#define	getchar()	getc(stdin)
#ifdef _STDIOLIB_NOANSI_
int	ungetc(int, FILE *);
#else
int	ungetc(char, FILE *);
#endif
char	*fgets(char *, size_t, FILE *);
char	*gets(char *);
int	fscanf(FILE *, const char *, ...);
int	scanf(const char *, ...);
int	sscanf(char *, const char *, ...);
#ifdef _STDIOLIB_NOANSI_
int	fputc(int, FILE *);
#else
int	fputc(char, FILE *);
#endif
extern int _flsbuf(unsigned char, FILE *);
#define putc(x, p)	(--(p)->_cnt >= 0 ?\
	(int)(*(unsigned char *)(p)->_ptr++ = (unsigned char)(x)) :\
	(((p)->_flag & _IOLBF) && -(p)->_cnt < (p)->_bufsiz ?\
		((*(unsigned char *)(p)->_ptr = (unsigned char)(x)) != '\n' ?\
			(int)(*(unsigned char *)(p)->_ptr++) :\
			_flsbuf(*(unsigned char *)(p)->_ptr, p)) :\
		_flsbuf((unsigned char)(x), p)))
#define	putchar(x)	putc(x,stdout)
int	fputs(const char *, FILE *);
int	puts(const char *);
int	fprintf(FILE *, const char *, ...);
int	printf(const char *, ...);
int	sprintf(char *, const char *, ...);
int	fread(void *, size_t, size_t, FILE *);
int	fwrite(void *, size_t, size_t, FILE *);
#define	feof(p)		(((p)->_flag&_IOEOF)!=0)
#define	ferror(p)	(((p)->_flag&_IOERR)!=0)
#define	clearerr(p)	((p)->_flag &= ~(_IOERR|_IOEOF))
#define remove(n)	unlink(n)
int	rename(const char *, const char *);
/* tmpfile(), tmpnam(), L_tmpnam, TMP_MAX not defined */ 

#endif /* __STDC__ */

#ifdef _STDIOLIB_NOANSI_
#undef _STDIOLIB_NOANSI_
#endif

#endif /* _STDIO_H_ */

