/**************************************************************************
*   Copyright 2000 Compaq Computer Corporation
*
*   COMPAQ Registered in U.S. Patent and Trademark Office.
*
*   Confidential computer software. Valid license from Compaq or authorized
*   sublicensor required for possession, use or copying. Consistent with
*   FAR 12.211 and 12.212, Commercial Computer Software, Computer Software
*   Documentation, and Technical Data for Commercial Items are licensed to
*   the U.S. Government under vendor's standard commercial license.
**************************************************************************/

#if !defined(_STDIO_H_) && !defined(_STDIO_H)
#if defined(__linux__)
#define _STDIO_H
#else
#define _STDIO_H_
#endif  /* __linux__  */

#if defined(__linux__) && defined(__DECCXX_LIBCXX_RH70) && !defined(_STDIO_MBSTATE_AND_FPOS_T)
#define _STDIO_MBSTATE_AND_FPOS_T
/* include <wchar.h> */
#ifndef _MBSTATE_T
#define _MBSTATE_T
typedef struct
{
  int __count;
  union
  {
    /* std::wint_t */ unsigned int __wch;
    char __wchb[4];
  } __value;		/* Value so far.  */
} __mbstate_t;
#endif _MBSTATE_T

/* include <_G_config.h> */
 typedef struct
{
  /* __off_t */ signed long int pos;
  __mbstate_t __state;
} _G_fpos_t;
#endif /* defined(__linux__) && defined(__DECCXX_LIBCXX_RH70) */

extern "C" {
namespace std {

typedef unsigned long   size_t;

#if defined(__linux__) && defined(__DECCXX_LIBCXX_RH70)
typedef _G_fpos_t fpos_t;
#else
typedef long    fpos_t;
#endif

}   /* namespace std */
}   /* extern "C"  */

#if defined(__linux__)
#define NULL            0
#define TMP_MAX         238328
#define FOPEN_MAX 	256
#define FILENAME_MAX    4095 
#define L_tmpnam        20
#else
#define NULL            0L
#define TMP_MAX         16384
#define FOPEN_MAX 	64
#define FILENAME_MAX 	255
#define _P_tmpdir       "/tmp/"
#define L_tmpnam	(sizeof(_P_tmpdir) + 15)
#endif   /*  __linux__ */

#define BUFSIZ		8192

/*
 * _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.
 */
#if defined(__linux__)
#define _IOFBF         0
#define _IOLBF         1
#define _IONBF         2
#else
#define _IOFBF		0000
#define _IOLBF		0200
#define _IONBF		0004
#endif

#define EOF		(-1)

// #include <sys/seek.h>

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

extern "C" {

#ifndef __STDIO_FILE_
#define __STDIO_FILE_
#if defined(__linux__)

struct _IO_marker {
  struct _IO_marker *_next;
  struct _IO_FILE *_sbuf;
  int _pos;
};

struct _IO_FILE {
  int    _flags; 
  char  *_IO_read_ptr;
  char  *_IO_read_end;
  char  *_IO_read_base;
  char  *_IO_write_base;
  char  *_IO_write_ptr;
  char  *_IO_write_end;
  char  *_IO_buf_base;
  char  *_IO_buf_end;
  char  *_IO_save_base;
  char  *_IO_backup_base;
  char  *_IO_save_end;
  struct _IO_marker *_markers;
  struct _IO_FILE *_chain;
  int    _fileno;
  int    _blksize;
  signed long int _old_offset;
#define __HAVE_COLUMN /* temporary */
  unsigned short _cur_column;
  signed char _vtable_offset;
  char _shortbuf[1];
  void *_lock;
#if defined _G_IO_IO_FILE_VERSION && _G_IO_IO_FILE_VERSION == 0x20001
  signed long int _offset;
  int _unused2[16];
#endif
};

namespace std {
typedef _IO_FILE FILE;
}   /* namespace std */
#else
namespace std {
typedef struct {
	int	_cnt;
	unsigned int	_flag2;
	unsigned char	*_ptr;
	unsigned char	*_base;
	int	_bufsiz;
	short	_flag;
	short	_file;

#ifndef	__alpha
	void	*_unused;
#endif	/* __alpha */
	char	*__newbase;
	void	*_lock;			/* lock for thread safe library (or unused2) */
	unsigned char	*_bufendp;
} FILE;
}   /* namespace std */
#endif   /*  __linux__ */
#endif   /*  __STDIO_FILE_  */


#if defined(__linux__)
extern std::FILE *stdin;
extern std::FILE *stdout;
extern std::FILE *stderr;
#define stdin stdin
#define stdout stdout
#define stderr stderr
#else
extern std::FILE	_iob[];
#define stdin           (&_iob[0])
#define stdout          (&_iob[1])
#define stderr          (&_iob[2])
#endif  /*  __linux__  */

}   /* extern "C"  */


extern "C" {
namespace std {

extern size_t	fread (void *, size_t, size_t, FILE *);
extern size_t	fwrite (const void *, size_t, size_t, FILE *);

extern int 	ferror (FILE *);
extern int 	feof (FILE *);
extern void 	clearerr (FILE *);
extern int 	putchar (int);
extern int 	getchar (void);
extern int 	putc (int, FILE *);
extern int 	getc (FILE *);
extern int	remove (const char *);
extern int	rename (const char *, const char *);
extern FILE 	*tmpfile (void);
extern char 	*tmpnam (char *);
extern int 	fclose (FILE *);
extern int 	fflush (FILE *);
extern FILE	*fopen (const char *, const char *);
extern FILE 	*freopen (const char *, const char *, FILE *);
extern void 	setbuf (FILE *, char *);
extern int 	setvbuf (FILE *, char *, int, size_t);
extern int	fprintf (FILE *, const char *, ...);
extern int	fscanf (FILE *, const char *, ...);
extern int	printf (const char *, ...);
extern int	scanf (const char *, ...);
extern int	sprintf (char *, const char *, ...);
extern int	sscanf (const char *, const char *, ...);

#if defined(_CSTDARG_) || defined(_STDARG_H)
#define __STDIO_CNAME_
extern int  vfprintf (FILE *, const char *, va_list);
extern int  vprintf (const char *, va_list);
extern int  vsprintf (char *, const char *, va_list);
#endif  /* _CSTDARG_ || _STDARG_H */

extern int 	fgetc (FILE *);
extern char 	*fgets (char *, int, FILE *);
extern int 	fputc (int, FILE *);
extern int 	fputs (const char *, FILE *);
extern char 	*gets (char *);
extern int 	puts (const char *);
extern int	ungetc (int, FILE *);
extern int	fgetpos (FILE *, fpos_t *);
extern int 	fseek (FILE *, long, int);
extern int	fsetpos (FILE *, const fpos_t *);
extern long	ftell (FILE *);
extern void	rewind (FILE *);
extern void 	perror (const char *);

}  /* namespace std */
}  /* extern "C" */

#endif /* _STDIO_H_ */
