/*
 * $Id: stdio.h,v 1.6 2000/09/22 22:05:17 k-abe Exp $
 *
 * This file is part of PTL, Portable Thread Library.
 *
 * Copyright (C) 1997-2000 Kota Abe
 *
 */

#ifndef __PTL_STDIO_H__
#define __PTL_STDIO_H__

#include <sys/pthread-init.h>

/* ---------------------------------------------------------------- */
#ifdef __PTL_RENAMED__
#define __PTL_ALREADY_RENAMED_STDIO_H
#else
#include <sys/pthread-before.h>
#endif

#ifdef __GNUC__
#include <00root-gcc/stdio.h>
#else
#include <00root-system/stdio.h>
#endif

#include <sys/pthread-after.h>
/* ---------------------------------------------------------------- */

#include <sys/pthread-extsym.h>
#include <sys/pthread-cdecl.h>

#ifndef PTL_INTERNAL

#undef getc
#define getc		fgetc
#undef getchar
#define getchar()	fgetc(stdin)
#undef putchar
#define putchar(C)	fputc(C,stdout)
#define vprintf(fm,ap)	vfprintf(stdout,fm,ap)
#undef putc
#define putc		fputc

#ifndef LIBALTSYS_USE_SO
#define fclose		_proof_fclose
#define fdopen		_proof_fdopen
#define fflush		_proof_fflush
#define fgetc		_proof_fgetc
#define fgets		_proof_fgets
#define fopen		_proof_fopen
#define fprintf		_proof_fprintf
#define fputc		_proof_fputc
#define fputs		_proof_fputs
#define fread		_proof_fread
#define freopen		_proof_freopen
#define fseek		_proof_fseek
#define ftell		_proof_ftell
#define fwrite		_proof_fwrite
#define gets		_proof_gets
#define getw		_proof_getw
#define printf		_proof_printf
#define puts		_proof_puts
#define putw		_proof_putw
#define rewind		_proof_rewind
#define setbuf		_proof_setbuf
#define setvbuf		_proof_setvbuf
#define setbuffer	_proof_setbuffer
#define setlinebuf	_proof_setlinebuf
#define ungetc		_proof_ungetc
#define vfprintf	_proof_vfprintf
#endif

/* Following functions are considered to "thread proof" already */
/*#define sprintf	_proof_sprintf*/
/*#define fscanf	_proof_fscanf*/
/*#define scanf		_proof_scanf*/
/*#define sscanf	_proof_sscanf*/

#define ttyname		_proof_ttyname

#include <sys/pthread-stdio.h>

__PTL_BEGIN_DECLS

extern void	flockfile __PTL_P((FILE*));
extern int	ftrylockfile __PTL_P((FILE*));
extern void	funlockfile __PTL_P((FILE*));

extern char	*mktemp __PTL_P((char*));
extern int	mkstemp __PTL_P((char*));
extern char	*tmpnam __PTL_P((char*));
extern char	*tempnam __PTL_P((const char*, const char*));
extern FILE	*tmpfile __PTL_NOARGS;
extern char	*ctermid_r __PTL_P((char*));

#ifndef LIBALTSYS_USE_SO
extern int	_proof_fclose __PTL_P((FILE*));
extern FILE	*_proof_fdopen __PTL_P((int, char*));
extern int	_proof_fflush __PTL_P((FILE*));
extern int	_proof_fgetc __PTL_P((FILE*));
extern char	*_proof_fgets __PTL_P((char*, int, FILE*));
extern FILE	*_proof_fopen __PTL_P((char*, char*));
extern int	_proof_fprintf __PTL_P((FILE*, const char*, ...));
extern int	_proof_fputc __PTL_P((int, FILE*));
extern int	_proof_fputs __PTL_P((const char*, FILE*));
extern int	_proof_fread __PTL_P((char*, int, int, FILE*));
extern FILE	*_proof_freopen __PTL_P((const char*, const char*, FILE*));
extern int	_proof_fseek __PTL_P((FILE*, long, int));
extern long	_proof_ftell __PTL_P((FILE*));
extern int	_proof_fwrite __PTL_P((const char*, int, int, FILE*));
extern int	_proof_gets __PTL_P((char*));
extern int	_proof_getw __PTL_P((FILE*));
extern int	_proof_printf __PTL_P((const char*, ...));
extern int	_proof_puts __PTL_P((const char*));
extern int	_proof_putw __PTL_P((int, FILE*));
extern int	_proof_rewind __PTL_P((FILE*));
extern void	_proof_setbuf __PTL_P((FILE*, char*));
extern int	_proof_setvbuf __PTL_P((FILE*, char*, int, int));
extern void	_proof_setbuffer __PTL_P((FILE*, char*, int));
extern int	_proof_setlinebuf __PTL_P((FILE*));
extern int	_proof_ungetc __PTL_P((int, FILE*));
/*extern int	_proof_vfprintf __PTL_P((FILE*, const char*, va_list));*/
#endif

__PTL_END_DECLS

#undef L_ctermid
#define L_ctermid	9	/* "/dev/tty" */

#ifndef P_tmpdir
#define P_tmpdir	"/var/tmp/"
#endif

#endif /* PTL_INTERNAL */

/* ---------------------------------------------------------------- */
#ifdef __PTL_ALREADY_RENAMED_STDIO_H
#include <sys/pthread-before.h>
#undef __PTL_ALREADY_RENAMED_STDIO_H
#else
#include <sys/pthread-after.h>
#endif
/* ---------------------------------------------------------------- */

#endif /* __PTL_STDIO_H__ */
