stdio.h revision 35163
11539Srgrimes/*-
21539Srgrimes * Copyright (c) 1990, 1993
31539Srgrimes *	The Regents of the University of California.  All rights reserved.
41539Srgrimes *
51539Srgrimes * This code is derived from software contributed to Berkeley by
61539Srgrimes * Chris Torek.
71539Srgrimes *
81539Srgrimes * Redistribution and use in source and binary forms, with or without
91539Srgrimes * modification, are permitted provided that the following conditions
101539Srgrimes * are met:
111539Srgrimes * 1. Redistributions of source code must retain the above copyright
121539Srgrimes *    notice, this list of conditions and the following disclaimer.
131539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141539Srgrimes *    notice, this list of conditions and the following disclaimer in the
151539Srgrimes *    documentation and/or other materials provided with the distribution.
161539Srgrimes * 3. All advertising materials mentioning features or use of this software
171539Srgrimes *    must display the following acknowledgement:
181539Srgrimes *	This product includes software developed by the University of
191539Srgrimes *	California, Berkeley and its contributors.
201539Srgrimes * 4. Neither the name of the University nor the names of its contributors
211539Srgrimes *    may be used to endorse or promote products derived from this software
221539Srgrimes *    without specific prior written permission.
231539Srgrimes *
241539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341539Srgrimes * SUCH DAMAGE.
351539Srgrimes *
3623655Speter *	@(#)stdio.h	8.5 (Berkeley) 4/29/95
3735163Sjb *	$Id: stdio.h,v 1.15 1998/04/11 07:33:46 jb Exp $
381539Srgrimes */
391539Srgrimes
401539Srgrimes#ifndef	_STDIO_H_
411539Srgrimes#define	_STDIO_H_
421539Srgrimes
431539Srgrimes#include <sys/cdefs.h>
4424897Sbde#include <machine/ansi.h>
451539Srgrimes
461539Srgrimes#ifdef	_BSD_SIZE_T_
471539Srgrimestypedef	_BSD_SIZE_T_	size_t;
481539Srgrimes#undef	_BSD_SIZE_T_
491539Srgrimes#endif
501539Srgrimes
511539Srgrimes#ifndef NULL
521539Srgrimes#define	NULL	0
531539Srgrimes#endif
541539Srgrimes
551539Srgrimes/*
561539Srgrimes * This is fairly grotesque, but pure ANSI code must not inspect the
571539Srgrimes * innards of an fpos_t anyway.  The library internally uses off_t,
581539Srgrimes * which we assume is exactly as big as eight chars.  (When we switch
591539Srgrimes * to gcc 2.4 we will use __attribute__ here.)
601539Srgrimes *
611539Srgrimes * WARNING: the alignment constraints on an off_t and the struct below
621539Srgrimes * differ on (e.g.) the SPARC.  Hence, the placement of an fpos_t object
631539Srgrimes * in a structure will change if fpos_t's are not aligned on 8-byte
641539Srgrimes * boundaries.  THIS IS A CROCK, but for now there is no way around it.
651539Srgrimes */
661539Srgrimes#if !defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)
6724897Sbdetypedef	_BSD_OFF_T_	fpos_t;
681539Srgrimes#else
691539Srgrimestypedef struct __sfpos {
701539Srgrimes	char	_pos[8];
711539Srgrimes} fpos_t;
721539Srgrimes#endif
731539Srgrimes
741539Srgrimes#define	_FSTDIO			/* Define for new stdio with functions. */
751539Srgrimes
761539Srgrimes/*
771539Srgrimes * NB: to fit things in six character monocase externals, the stdio
781539Srgrimes * code uses the prefix `__s' for stdio objects, typically followed
791539Srgrimes * by a three-character attempt at a mnemonic.
801539Srgrimes */
811539Srgrimes
821539Srgrimes/* stdio buffers */
831539Srgrimesstruct __sbuf {
841539Srgrimes	unsigned char *_base;
851539Srgrimes	int	_size;
861539Srgrimes};
871539Srgrimes
881539Srgrimes/*
891539Srgrimes * stdio state variables.
901539Srgrimes *
911539Srgrimes * The following always hold:
921539Srgrimes *
931539Srgrimes *	if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
941539Srgrimes *		_lbfsize is -_bf._size, else _lbfsize is 0
951539Srgrimes *	if _flags&__SRD, _w is 0
961539Srgrimes *	if _flags&__SWR, _r is 0
971539Srgrimes *
981539Srgrimes * This ensures that the getc and putc macros (or inline functions) never
991539Srgrimes * try to write or read from a file that is in `read' or `write' mode.
1001539Srgrimes * (Moreover, they can, and do, automatically switch from read mode to
1011539Srgrimes * write mode, and back, on "r+" and "w+" files.)
1021539Srgrimes *
1031539Srgrimes * _lbfsize is used only to make the inline line-buffered output stream
1041539Srgrimes * code as compact as possible.
1051539Srgrimes *
1061539Srgrimes * _ub, _up, and _ur are used when ungetc() pushes back more characters
1071539Srgrimes * than fit in the current _bf, or when ungetc() pushes back a character
1081539Srgrimes * that does not match the previous one in _bf.  When this happens,
1091539Srgrimes * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
1101539Srgrimes * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
1111539Srgrimes *
1121539Srgrimes * NB: see WARNING above before changing the layout of this structure!
1131539Srgrimes */
1141539Srgrimestypedef	struct __sFILE {
1151539Srgrimes	unsigned char *_p;	/* current position in (some) buffer */
1161539Srgrimes	int	_r;		/* read space left for getc() */
1171539Srgrimes	int	_w;		/* write space left for putc() */
1181539Srgrimes	short	_flags;		/* flags, below; this FILE is free if 0 */
1191539Srgrimes	short	_file;		/* fileno, if Unix descriptor, else -1 */
1201539Srgrimes	struct	__sbuf _bf;	/* the buffer (at least 1 byte, if !NULL) */
1211539Srgrimes	int	_lbfsize;	/* 0 or -_bf._size, for inline putc */
1221539Srgrimes
1231539Srgrimes	/* operations */
1241539Srgrimes	void	*_cookie;	/* cookie passed to io functions */
1251539Srgrimes	int	(*_close) __P((void *));
1261539Srgrimes	int	(*_read)  __P((void *, char *, int));
1271539Srgrimes	fpos_t	(*_seek)  __P((void *, fpos_t, int));
1281539Srgrimes	int	(*_write) __P((void *, const char *, int));
1291539Srgrimes
1301539Srgrimes	/* separate buffer for long sequences of ungetc() */
1311539Srgrimes	struct	__sbuf _ub;	/* ungetc buffer */
1321539Srgrimes	unsigned char *_up;	/* saved _p when _p is doing ungetc data */
1331539Srgrimes	int	_ur;		/* saved _r when _r is counting ungetc data */
1341539Srgrimes
1351539Srgrimes	/* tricks to meet minimum requirements even when malloc() fails */
1361539Srgrimes	unsigned char _ubuf[3];	/* guarantee an ungetc() buffer */
1371539Srgrimes	unsigned char _nbuf[1];	/* guarantee a getc() buffer */
1381539Srgrimes
1391539Srgrimes	/* separate buffer for fgetln() when line crosses buffer boundary */
1401539Srgrimes	struct	__sbuf _lb;	/* buffer for fgetln() */
1411539Srgrimes
1421539Srgrimes	/* Unix stdio files get aligned to block boundaries on fseek() */
1431539Srgrimes	int	_blksize;	/* stat.st_blksize (may be != _bf._size) */
1441539Srgrimes	fpos_t	_offset;	/* current lseek offset (see WARNING) */
1451539Srgrimes} FILE;
1461539Srgrimes
1471539Srgrimes__BEGIN_DECLS
1481539Srgrimesextern FILE __sF[];
1491539Srgrimes__END_DECLS
1501539Srgrimes
1511539Srgrimes#define	__SLBF	0x0001		/* line buffered */
1521539Srgrimes#define	__SNBF	0x0002		/* unbuffered */
1531539Srgrimes#define	__SRD	0x0004		/* OK to read */
1541539Srgrimes#define	__SWR	0x0008		/* OK to write */
1551539Srgrimes	/* RD and WR are never simultaneously asserted */
1561539Srgrimes#define	__SRW	0x0010		/* open for reading & writing */
1571539Srgrimes#define	__SEOF	0x0020		/* found EOF */
1581539Srgrimes#define	__SERR	0x0040		/* found error */
1591539Srgrimes#define	__SMBF	0x0080		/* _buf is from malloc */
1601539Srgrimes#define	__SAPP	0x0100		/* fdopen()ed in append mode */
1611539Srgrimes#define	__SSTR	0x0200		/* this is an sprintf/snprintf string */
16213771Smpp#define	__SOPT	0x0400		/* do fseek() optimization */
16313771Smpp#define	__SNPT	0x0800		/* do not do fseek() optimization */
1641539Srgrimes#define	__SOFF	0x1000		/* set iff _offset is in fact correct */
1651539Srgrimes#define	__SMOD	0x2000		/* true => fgetln modified _p text */
1661539Srgrimes
1671539Srgrimes/*
1681539Srgrimes * The following three definitions are for ANSI C, which took them
1691539Srgrimes * from System V, which brilliantly took internal interface macros and
1701539Srgrimes * made them official arguments to setvbuf(), without renaming them.
1711539Srgrimes * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
1721539Srgrimes *
1731539Srgrimes * Although numbered as their counterparts above, the implementation
1741539Srgrimes * does not rely on this.
1751539Srgrimes */
1761539Srgrimes#define	_IOFBF	0		/* setvbuf should set fully buffered */
1771539Srgrimes#define	_IOLBF	1		/* setvbuf should set line buffered */
1781539Srgrimes#define	_IONBF	2		/* setvbuf should set unbuffered */
1791539Srgrimes
1801539Srgrimes#define	BUFSIZ	1024		/* size of buffer used by setbuf */
1811539Srgrimes#define	EOF	(-1)
1821539Srgrimes
1831539Srgrimes/*
1841539Srgrimes * FOPEN_MAX is a minimum maximum, and is the number of streams that
1851539Srgrimes * stdio can provide without attempting to allocate further resources
1861539Srgrimes * (which could fail).  Do not use this for anything.
1871539Srgrimes */
1881539Srgrimes				/* must be == _POSIX_STREAM_MAX <limits.h> */
1891539Srgrimes#define	FOPEN_MAX	20	/* must be <= OPEN_MAX <sys/syslimits.h> */
1901539Srgrimes#define	FILENAME_MAX	1024	/* must be <= PATH_MAX <sys/syslimits.h> */
1911539Srgrimes
1921539Srgrimes/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
1931539Srgrimes#ifndef _ANSI_SOURCE
1941539Srgrimes#define	P_tmpdir	"/var/tmp/"
1951539Srgrimes#endif
1961539Srgrimes#define	L_tmpnam	1024	/* XXX must be == PATH_MAX */
1971539Srgrimes#define	TMP_MAX		308915776
1981539Srgrimes
1991539Srgrimes#ifndef SEEK_SET
2001539Srgrimes#define	SEEK_SET	0	/* set file offset to offset */
2011539Srgrimes#endif
2021539Srgrimes#ifndef SEEK_CUR
2031539Srgrimes#define	SEEK_CUR	1	/* set file offset to current plus offset */
2041539Srgrimes#endif
2051539Srgrimes#ifndef SEEK_END
2061539Srgrimes#define	SEEK_END	2	/* set file offset to EOF plus offset */
2071539Srgrimes#endif
2081539Srgrimes
2091539Srgrimes#define	stdin	(&__sF[0])
2101539Srgrimes#define	stdout	(&__sF[1])
2111539Srgrimes#define	stderr	(&__sF[2])
2121539Srgrimes
2131539Srgrimes/*
2141539Srgrimes * Functions defined in ANSI C standard.
2151539Srgrimes */
2161539Srgrimes__BEGIN_DECLS
2171539Srgrimesvoid	 clearerr __P((FILE *));
2181539Srgrimesint	 fclose __P((FILE *));
2191539Srgrimesint	 feof __P((FILE *));
2201539Srgrimesint	 ferror __P((FILE *));
2211539Srgrimesint	 fflush __P((FILE *));
2221539Srgrimesint	 fgetc __P((FILE *));
2231539Srgrimesint	 fgetpos __P((FILE *, fpos_t *));
22414791Spaulchar	*fgets __P((char *, int, FILE *));
2251539SrgrimesFILE	*fopen __P((const char *, const char *));
2261539Srgrimesint	 fprintf __P((FILE *, const char *, ...));
2271539Srgrimesint	 fputc __P((int, FILE *));
2281539Srgrimesint	 fputs __P((const char *, FILE *));
2291539Srgrimessize_t	 fread __P((void *, size_t, size_t, FILE *));
2301539SrgrimesFILE	*freopen __P((const char *, const char *, FILE *));
2311539Srgrimesint	 fscanf __P((FILE *, const char *, ...));
2321539Srgrimesint	 fseek __P((FILE *, long, int));
2331539Srgrimesint	 fsetpos __P((FILE *, const fpos_t *));
23414791Spaullong	 ftell __P((FILE *));
2351539Srgrimessize_t	 fwrite __P((const void *, size_t, size_t, FILE *));
2361539Srgrimesint	 getc __P((FILE *));
2371539Srgrimesint	 getchar __P((void));
2381539Srgrimeschar	*gets __P((char *));
2391539Srgrimes#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
2406895Sphkextern __const int sys_nerr;		/* perror(3) external variables */
2411539Srgrimesextern __const char *__const sys_errlist[];
2421539Srgrimes#endif
2431539Srgrimesvoid	 perror __P((const char *));
2441539Srgrimesint	 printf __P((const char *, ...));
2451539Srgrimesint	 putc __P((int, FILE *));
2461539Srgrimesint	 putchar __P((int));
2471539Srgrimesint	 puts __P((const char *));
2481539Srgrimesint	 remove __P((const char *));
2491539Srgrimesint	 rename  __P((const char *, const char *));
2501539Srgrimesvoid	 rewind __P((FILE *));
2511539Srgrimesint	 scanf __P((const char *, ...));
2521539Srgrimesvoid	 setbuf __P((FILE *, char *));
2531539Srgrimesint	 setvbuf __P((FILE *, char *, int, size_t));
2541539Srgrimesint	 sprintf __P((char *, const char *, ...));
2551539Srgrimesint	 sscanf __P((const char *, const char *, ...));
2561539SrgrimesFILE	*tmpfile __P((void));
2571539Srgrimeschar	*tmpnam __P((char *));
2581539Srgrimesint	 ungetc __P((int, FILE *));
2591539Srgrimesint	 vfprintf __P((FILE *, const char *, _BSD_VA_LIST_));
2601539Srgrimesint	 vprintf __P((const char *, _BSD_VA_LIST_));
2611539Srgrimesint	 vsprintf __P((char *, const char *, _BSD_VA_LIST_));
2621539Srgrimes__END_DECLS
2631539Srgrimes
2641539Srgrimes/*
2651539Srgrimes * Functions defined in POSIX 1003.1.
2661539Srgrimes */
2671539Srgrimes#ifndef _ANSI_SOURCE
26819211Swosch/* size for cuserid(3); UT_NAMESIZE + 1, see <utmp.h> */
26923260Sache#define	L_cuserid	17
2701539Srgrimes
27119211Swosch#define	L_ctermid	1024	/* size for ctermid(3); PATH_MAX */
27219211Swosch
2731539Srgrimes__BEGIN_DECLS
2741539Srgrimeschar	*ctermid __P((char *));
2751539SrgrimesFILE	*fdopen __P((int, const char *));
2761539Srgrimesint	 fileno __P((FILE *));
27735163Sjbint	 ftrylockfile __P((FILE *));
27835163Sjbvoid	 flockfile __P((FILE *));
27935163Sjbvoid	 funlockfile __P((FILE *));
2801539Srgrimes__END_DECLS
2811539Srgrimes#endif /* not ANSI */
2821539Srgrimes
2831539Srgrimes/*
28424897Sbde * Portability hacks.  See <sys/types.h>.
28524897Sbde */
28624897Sbde#if !defined (_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
28724897Sbde__BEGIN_DECLS
28824897Sbde#ifndef _FTRUNCATE_DECLARED
28924897Sbde#define	_FTRUNCATE_DECLARED
29024897Sbdeint	 ftruncate __P((int, _BSD_OFF_T_));
29124897Sbde#endif
29224897Sbde#ifndef _LSEEK_DECLARED
29324897Sbde#define	_LSEEK_DECLARED
29424897Sbde_BSD_OFF_T_ lseek __P((int, _BSD_OFF_T_, int));
29524897Sbde#endif
29624897Sbde#ifndef _MMAP_DECLARED
29724897Sbde#define	_MMAP_DECLARED
29832166Salexchar	*mmap __P((void *, size_t, int, int, int, _BSD_OFF_T_));
29924897Sbde#endif
30024897Sbde#ifndef _TRUNCATE_DECLARED
30124897Sbde#define	_TRUNCATE_DECLARED
30224897Sbdeint	 truncate __P((const char *, _BSD_OFF_T_));
30324897Sbde#endif
30424897Sbde__END_DECLS
30524897Sbde#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
30624897Sbde
30724897Sbde/*
3081539Srgrimes * Routines that are purely local.
3091539Srgrimes */
3101539Srgrimes#if !defined (_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
3111539Srgrimes__BEGIN_DECLS
31215931Speterint	 asprintf __P((char **, const char *, ...));
3131539Srgrimeschar	*fgetln __P((FILE *, size_t *));
3141539Srgrimesint	 fpurge __P((FILE *));
3151539Srgrimesint	 getw __P((FILE *));
3161539Srgrimesint	 pclose __P((FILE *));
3171539SrgrimesFILE	*popen __P((const char *, const char *));
3181539Srgrimesint	 putw __P((int, FILE *));
3191539Srgrimesvoid	 setbuffer __P((FILE *, char *, int));
3201539Srgrimesint	 setlinebuf __P((FILE *));
3211539Srgrimeschar	*tempnam __P((const char *, const char *));
3221539Srgrimesint	 snprintf __P((char *, size_t, const char *, ...));
32315931Speterint	 vasprintf __P((char **, const char *, _BSD_VA_LIST_));
3241539Srgrimesint	 vsnprintf __P((char *, size_t, const char *, _BSD_VA_LIST_));
3251539Srgrimesint	 vscanf __P((const char *, _BSD_VA_LIST_));
3261539Srgrimesint	 vsscanf __P((const char *, const char *, _BSD_VA_LIST_));
3271539Srgrimes__END_DECLS
3281539Srgrimes
3291539Srgrimes/*
3301539Srgrimes * This is a #define because the function is used internally and
3311539Srgrimes * (unlike vfscanf) the name __svfscanf is guaranteed not to collide
3321539Srgrimes * with a user function when _ANSI_SOURCE or _POSIX_SOURCE is defined.
3331539Srgrimes */
3341539Srgrimes#define	 vfscanf	__svfscanf
3351539Srgrimes
3361539Srgrimes/*
3371539Srgrimes * Stdio function-access interface.
3381539Srgrimes */
3391539Srgrimes__BEGIN_DECLS
3401539SrgrimesFILE	*funopen __P((const void *,
3411539Srgrimes		int (*)(void *, char *, int),
3421539Srgrimes		int (*)(void *, const char *, int),
3431539Srgrimes		fpos_t (*)(void *, fpos_t, int),
3441539Srgrimes		int (*)(void *)));
3451539Srgrimes__END_DECLS
3461539Srgrimes#define	fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
3471539Srgrimes#define	fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
3481539Srgrimes#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
3491539Srgrimes
3501539Srgrimes/*
3511539Srgrimes * Functions internal to the implementation.
3521539Srgrimes */
3531539Srgrimes__BEGIN_DECLS
3541539Srgrimesint	__srget __P((FILE *));
3551539Srgrimesint	__svfscanf __P((FILE *, const char *, _BSD_VA_LIST_));
3561539Srgrimesint	__swbuf __P((int, FILE *));
3571539Srgrimes__END_DECLS
3581539Srgrimes
3591539Srgrimes/*
3608858Srgrimes * The __sfoo macros are here so that we can
3611539Srgrimes * define function versions in the C library.
3621539Srgrimes */
3631539Srgrimes#define	__sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
3641539Srgrimes#if defined(__GNUC__) && defined(__STDC__)
3651539Srgrimesstatic __inline int __sputc(int _c, FILE *_p) {
3661539Srgrimes	if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
3671539Srgrimes		return (*_p->_p++ = _c);
3681539Srgrimes	else
3691539Srgrimes		return (__swbuf(_c, _p));
3701539Srgrimes}
3711539Srgrimes#else
3721539Srgrimes/*
3731539Srgrimes * This has been tuned to generate reasonable code on the vax using pcc.
3741539Srgrimes */
3751539Srgrimes#define	__sputc(c, p) \
3761539Srgrimes	(--(p)->_w < 0 ? \
3771539Srgrimes		(p)->_w >= (p)->_lbfsize ? \
3781539Srgrimes			(*(p)->_p = (c)), *(p)->_p != '\n' ? \
3791539Srgrimes				(int)*(p)->_p++ : \
3801539Srgrimes				__swbuf('\n', p) : \
3811539Srgrimes			__swbuf((int)(c), p) : \
3821539Srgrimes		(*(p)->_p = (c), (int)*(p)->_p++))
3831539Srgrimes#endif
3841539Srgrimes
3851539Srgrimes#define	__sfeof(p)	(((p)->_flags & __SEOF) != 0)
3861539Srgrimes#define	__sferror(p)	(((p)->_flags & __SERR) != 0)
3871539Srgrimes#define	__sclearerr(p)	((void)((p)->_flags &= ~(__SERR|__SEOF)))
3881539Srgrimes#define	__sfileno(p)	((p)->_file)
3891539Srgrimes
39035127Sjb/*
39135127Sjb * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12
39235127Sjb * B.8.2.7 for the rationale behind the *_unlocked() macros.
39335127Sjb */
39435127Sjb#define	feof_unlocked(p)	__sfeof(p)
39535127Sjb#define	ferror_unlocked(p)	__sferror(p)
39635127Sjb#define	clearerr_unlocked(p)	__sclearerr(p)
3971539Srgrimes
3981539Srgrimes#ifndef _ANSI_SOURCE
39935127Sjb#define	fileno_unlocked(p)	__sfileno(p)
4001539Srgrimes#endif
4011539Srgrimes
40235127Sjb#ifndef  _THREAD_SAFE
40335127Sjb#define	feof(p)		feof_unlocked(p)
40435127Sjb#define	ferror(p)	ferror_unlocked(p)
40535127Sjb#define	clearerr(p)	clearerr_unlocked(p)
40635127Sjb
40735127Sjb#ifndef _ANSI_SOURCE
40835127Sjb#define	fileno(p)	fileno_unlocked(p)
40935127Sjb#endif
41035127Sjb#endif
41135127Sjb
4121539Srgrimes#ifndef lint
41335127Sjb#define	getc_unlocked(fp)	__sgetc(fp)
41435127Sjb#define putc_unlocked(x, fp)	__sputc(x, fp)
41535127Sjb#ifdef	_THREAD_SAFE
41635127Sjbvoid	_flockfile __P((FILE *));
41735127Sjbvoid	_flockfile_debug __P((FILE *, char *, int));
41835127Sjbvoid	_funlockfile __P((FILE *));
41935127Sjb#ifdef	_FLOCK_DEBUG
42035127Sjb#define _FLOCKFILE(x)	_flockfile_debug(x, __FILE__, __LINE__)
42135127Sjb#else
42235127Sjb#define _FLOCKFILE(x)	_flockfile(x)
42335127Sjb#endif
42435163Sjbstatic __inline int			\
42535163Sjb__getc_locked(FILE *_fp)		\
42635163Sjb{					\
42735163Sjb	extern int __isthreaded;	\
42835163Sjb	int _ret;			\
42935163Sjb	if (__isthreaded)		\
43035163Sjb		_FLOCKFILE(_fp);	\
43135163Sjb	_ret = getc_unlocked(_fp);	\
43235163Sjb	if (__isthreaded)		\
43335163Sjb		_funlockfile(_fp);	\
43435163Sjb	return (_ret);			\
43535127Sjb}
43635163Sjbstatic __inline int			\
43735163Sjb__putc_locked(int _x, FILE *_fp)	\
43835163Sjb{					\
43935163Sjb	extern int __isthreaded;	\
44035163Sjb	int _ret;			\
44135163Sjb	if (__isthreaded)		\
44235163Sjb		_FLOCKFILE(_fp);	\
44335163Sjb	_ret = putc_unlocked(_x, _fp);	\
44435163Sjb	if (__isthreaded)		\
44535163Sjb		_funlockfile(_fp);	\
44635163Sjb	return (_ret);			\
44735127Sjb}
44835127Sjb#define	getc(fp)	__getc_locked(fp)
44935127Sjb#define	putc(x, fp)	__putc_locked(x, fp)
45035127Sjb#else
45135127Sjb#define	getc(fp)	getc_unlocked(fp)
45235127Sjb#define putc(x, fp)	putc_unlocked(x, fp)
45335127Sjb#endif
4541539Srgrimes#endif /* lint */
4551539Srgrimes
45635127Sjb#define	getchar()		getc(stdin)
45735127Sjb#define	getchar_unlocked()	getc_unlocked(stdin)
45835127Sjb#define	putchar(x)		putc(x, stdout)
45935127Sjb#define	putchar_unlocked(x)	putc_unlocked(x, stdout)
46024897Sbde
46124897Sbde#endif /* !_STDIO_H_ */
462