/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident	"$Header: stdio.h 1.12 90/09/14 $@(#)head:stdio.h	2.14"

/*----------------------------------------------------------------------*
 * This file must meet the requirements in volume 2 of the X/Open	*
 * Portability Guide, Issue 3, which should be consulted before any	*
 * changes are made.							*
 *----------------------------------------------------------------------*/

#ifndef	_STDIO_H_

#ifndef NO_XPG3_HDR
#include "sys/types.h"
#endif	/* NO_XPG3_HDR */

/* ____________________________________________________________________*
 * This file forms part of the POSIX requirement described in sections *
 * 8.2 of 1003.1-1988 which should be refered to before making any     *
 * changes.                                                	       *
 *_____________________________________________________________________*/

#define _NFILE	20

#ifndef NO_XPG3_HDR
#define FOPEN_MAX	_NFILE
#endif	/* NO_XPG3_HDR */

#if u370
#define BUFSIZ	4096
#endif
#if vax || u3b || M32 || u3b15 || u3b5 || u3b2 || i386
#define BUFSIZ	1024
#endif
#if pdp11
#define BUFSIZ	512
#endif

/* buffer size for multi-character output to unbuffered files */
#define _SBFSIZ 8

typedef struct {
#if vax || u3b || M32 || u3b15 || u3b5 || u3b2 || i386
	int	_cnt;
	unsigned char	*_ptr;
#else
	unsigned char	*_ptr;
	int	_cnt;
#endif
	unsigned char	*_base;
	unsigned char	*_end;
	short	_flag;
	int	_file;
	unsigned char	_smbuf[_SBFSIZ];
} FILE;

/*
 * _IOLBF means that a file's output will be buffered line by line
 * In addition to being flags, _IONBF, _IOLBF and _IOFBF are possible
 * values for "type" in setvbuf.
 */
#define _IOFBF		0000
#define _IOREAD		0001
#define _IOWRT		0002
#define _IONBF		0004
#define _IOMYBUF	0010
#define _IOEOF		0020
#define _IOERR		0040
#define _IOLBF		0100
#define _IORW		0200
#define _IOSTRG		0400

#ifndef NULL
#define NULL		0
#endif
#ifndef EOF
#define EOF		(-1)
#endif

#define stdin		(&_iob[0])
#define stdout		(&_iob[1])
#define stderr		(&_iob[2])

#define _active(iop)	((iop)->_flag & (_IOREAD|_IOWRT|_IORW))
#define _bufend(p)	((p)->_end)
#define _bufsiz(p)	(_bufend(p) - (p)->_base)

#ifndef NO_XPG3_HDR
#ifndef SEEK_CUR
#define SEEK_SET	0
#define SEEK_CUR	1
#define SEEK_END	2
#endif	/* SEEK_CUR */

#ifndef _SIZE_T
typedef unsigned int size_t;
#define _SIZE_T
#endif	/* _SIZE_T */
#endif	/* NO_XPG3_HDR */

/*
 * The extern declaration for clearerr() is needed in addition to the 
 * #define, and must appear before it, since POSIX P1003.1-1988 requires
 * that this be available as a function in addition to any macro definition.
 */
extern void clearerr();
#define clearerr(p)	((void) ((p)->_flag &= ~(_IOERR | _IOEOF)))

extern void perror();

#ifndef lint
#define getc(p)		(--(p)->_cnt < 0 ? _filbuf(p) : (int) *(p)->_ptr++)
#define putc(x, p)	(--(p)->_cnt < 0 ? \
			_flsbuf((unsigned char) (x), (p)) : \
			(int) (*(p)->_ptr++ = (unsigned char) (x)))
#define getchar()	getc(stdin)
#define putchar(x)	putc((x), stdout)
#define feof(p)		((p)->_flag & _IOEOF)
#define ferror(p)	((p)->_flag & _IOERR)
#define fileno(p)	(p)->_file
#endif

extern FILE	_iob[_NFILE];
extern FILE	*fopen(), *fdopen(), *freopen(), *popen(), *tmpfile();
extern long int	ftell();
extern void	rewind(), setbuf();
extern char	*ctermid(), *cuserid(), *fgets(), *gets(), *tempnam(), *tmpnam();
extern int	fclose(), fflush(), fseek(), fgetc(),
		getw(), pclose(), printf(), fprintf(), sprintf(),
		vprintf(), vfprintf(), vsprintf(), fputc(), putw(),
		puts(), fputs(), scanf(), fscanf(), sscanf(),
		setvbuf(), system(), ungetc();

#ifndef NO_XPG3_HDR
extern size_t	fread(), fwrite();
extern int remove();
extern int rename();
#else
extern int fread(), fwrite();
#endif	/* NO_XPG3_HDR */

#define L_ctermid	9
#define L_cuserid	9
#define P_tmpdir	"/usr/tmp/"
#define L_tmpnam	(sizeof(P_tmpdir) + 15)

/*
 * ANSI C May 13, 1988 Draft, sections 4.9.1 & 4.9.4.4:
 *
 *	TMP_MAX expands to an integral constant expression that is the
 *	minimum number of unique file names that shall be generated by
 *	the tmpnam() function.
 */

#define TMP_MAX 17576		/* min. # of unique names from tmpnam() */

#define	_STDIO_H_
#endif	/*_STDIO_H_*/
