#ifndef __stdio_h
#define __stdio_h
#pragma once

/*
 * Libraries and headers for PDC release 3.3 (C) 1989 Lionel Hummel.
 * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
 * PDC I/O Library (C) 1987 by J.A. Lydiatt.
 *
 * This code is freely redistributable upon the conditions that this
 * notice remains intact and that modified versions of this file not
 * be included as part of the PDC Software Distribution without the
 * express consent of the copyright holders.  No warrantee of any
 * kind is provided with this code.  For further information, contact:
 *
 *  PDC Software Distribution    Internet:                     BIX:
 *  P.O. Box 4006             or hummel@cs.uiuc.edu            lhummel
 *  Urbana, IL  61801-8801       petersen@uicsrd.csrd.uiuc.edu
 */

/*  stdio.h */

/* modified - ryb */

#ifndef __sys_stdtypes_h
#include <sys/stdtypes.h>
#endif

#ifndef NULL
#define NULL 0
#endif

#define BUFSIZ		1024
#define MAX_READ_SIZE	1024

#define EOF		-1

#define FOPEN_MAX	1024
#define FILENAME_MAX	1024

#define L_tmpnam	16
#define TMP_MAX		4095

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

#define _IOFBF		0
#define _IOLBF		1
#define _IONBF		2

#define _FILEACTIVE	0x0001
#define _FILEISDIRTY	0x0002
#define _FILEATEOF	0x0004
#define _FILEBAD	0x0008
#define _FILEISDYNA	0x0010
#define _FILEISTTY	0x0020

#define _IOREAD		0x0001
#define _IOWRT		0x0002
#define _IOEOF		0x0010
#define _IOERR		0x0020
#define _IORW		0x0100

#ifndef _DF_SIZE_T
#define _DF_SIZE_T
typedef _TD_SIZE_T size_t;
#endif

typedef int fpos_t;

struct _iobuf {
  struct _iobuf *next;		/* Link to next buffer in chain		*/
  int		 _fileunit;	/* File descriptor			*/
  char		*_filecpos;	/* Current position in buffer		*/
  char		*_fileend;	/* Last position in buffer		*/
  long		 _filelen;	/* Buffer size				*/
  char		*_filebufp;	/* za buffer				*/
  char		 _filebyte;	/* Instant one-byte buffer		*/
  char		 _padbyte;
  unsigned short _fileflag;	/* Condition flags			*/
  char		*_tempname;	/* Name of this temp file or NULL	*/
};

typedef struct _iobuf FILE;

extern FILE	_fdevtab[];

extern FILE	*stdin;
extern FILE	*stdout;
extern FILE	*stderr;

int	 remove (const char *);
int	 rename (const char *, const char *);
FILE	*tmpfile (void);
char	*tmpnam (char *);
int	 fclose (FILE *stream);
int	 fflush (FILE *stream);
FILE	*fopen (const char *, const char *);
FILE	*freopen (const char *, const char *, FILE *);
void	 setbuf (FILE *, char *);
int	 setvbuf (FILE *, char *, int, size_t);
int	 fprintf (FILE *, const char *, ...);
int	 fscanf (FILE *, const char *, ...);
int	 printf (const char *, ...);
int	 scanf (const char *, ...);
int	 sprintf (char *, const char *, ...);
int	 sscanf (const char *, const char *, ...);
int	 vfprintf (FILE *, const char *, _TD_VA_LIST);
int	 vprintf (const char *, _TD_VA_LIST);
int	 vsprintf (char *, const char *, _TD_VA_LIST);
int	 fgetc (FILE *);
char	*fgets (char *, int, FILE *);
int	 fputc (int, FILE *);
int	 fputs (const char *, FILE *);
int	 getc (FILE *);
int	 getchar (void);
char	*gets (char *);
int	 putc (int, FILE *);
int	 putchar (int);
int	 puts (const char *);
int	 ungetc (int, FILE *);
size_t	 fread (void *, size_t, size_t, FILE *);
size_t	 fwrite (const void *, size_t, size_t, FILE *);
int	 fgetpos (FILE *, fpos_t *);
int	 fseek (FILE *, long, int);
int	 fsetpos (FILE *, const fpos_t *);
long	 ftell (FILE *);
void	 rewind (FILE *);
void	 clearerr (FILE *);
int	 feof (FILE *);
int	 ferror (FILE *);
void	 perror (const char *);

FILE	*fdopen (int, char *);

#define feof(p)         (((p)->_fileflag & _FILEATEOF) != 0)
#define ferror(p)       (((p)->_fileflag & _FILEBAD) != 0)
#define clearerr(p)     ((p)->_fileflag &= ~(_FILEBAD | _FILEATEOF))
#define getc(c)         fgetc (c)
#define getchar()       fgetc (stdin)
#define putc(c,s)       fputc ((c), (s))
#define putchar(c)      fputc ((c), stdout)

#define fileno(p)       ((p)->_fileunit)

#endif /* __stdio_h */
