stdio.h revision 178829
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
3750473Speter * $FreeBSD: head/include/stdio.h 178829 2008-05-07 15:12:45Z jhb $
381539Srgrimes */
391539Srgrimes
401539Srgrimes#ifndef	_STDIO_H_
411539Srgrimes#define	_STDIO_H_
421539Srgrimes
431539Srgrimes#include <sys/cdefs.h>
44123257Smarcel#include <sys/_null.h>
45102227Smike#include <sys/_types.h>
461539Srgrimes
47104585Smiketypedef	__off_t		fpos_t;
48104585Smike
49102227Smike#ifndef _SIZE_T_DECLARED
50102227Smiketypedef	__size_t	size_t;
51102227Smike#define	_SIZE_T_DECLARED
521539Srgrimes#endif
531539Srgrimes
54104585Smike#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
55104585Smike#ifndef _VA_LIST_DECLARED
56104585Smiketypedef	__va_list	va_list;
57104585Smike#define	_VA_LIST_DECLARED
58104585Smike#endif
59104585Smike#endif
60104585Smike
611539Srgrimes#define	_FSTDIO			/* Define for new stdio with functions. */
621539Srgrimes
63178778Sjhb/*
64178778Sjhb * NB: to fit things in six character monocase externals, the stdio
65178778Sjhb * code uses the prefix `__s' for stdio objects, typically followed
66178778Sjhb * by a three-character attempt at a mnemonic.
67178778Sjhb */
681539Srgrimes
69178778Sjhb/* stdio buffers */
70178778Sjhbstruct __sbuf {
71178778Sjhb	unsigned char *_base;
72178778Sjhb	int	_size;
73178778Sjhb};
74178778Sjhb
75178778Sjhb/*
76178778Sjhb * stdio state variables.
77178778Sjhb *
78178778Sjhb * The following always hold:
79178778Sjhb *
80178778Sjhb *	if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
81178778Sjhb *		_lbfsize is -_bf._size, else _lbfsize is 0
82178778Sjhb *	if _flags&__SRD, _w is 0
83178778Sjhb *	if _flags&__SWR, _r is 0
84178778Sjhb *
85178778Sjhb * This ensures that the getc and putc macros (or inline functions) never
86178778Sjhb * try to write or read from a file that is in `read' or `write' mode.
87178778Sjhb * (Moreover, they can, and do, automatically switch from read mode to
88178778Sjhb * write mode, and back, on "r+" and "w+" files.)
89178778Sjhb *
90178778Sjhb * _lbfsize is used only to make the inline line-buffered output stream
91178778Sjhb * code as compact as possible.
92178778Sjhb *
93178778Sjhb * _ub, _up, and _ur are used when ungetc() pushes back more characters
94178778Sjhb * than fit in the current _bf, or when ungetc() pushes back a character
95178778Sjhb * that does not match the previous one in _bf.  When this happens,
96178778Sjhb * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
97178778Sjhb * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
98178778Sjhb *
99178778Sjhb * Certain members of __sFILE are accessed directly via macros or
100178778Sjhb * inline functions.  To preserve ABI compat, these members must not
101178778Sjhb * be disturbed.  These members are marked below with (*).
102178778Sjhb */
103178778Sjhbtypedef	struct __sFILE {
104178778Sjhb	unsigned char *_p;	/* (*) current position in (some) buffer */
105178778Sjhb	int	_r;		/* (*) read space left for getc() */
106178778Sjhb	int	_w;		/* (*) write space left for putc() */
107178778Sjhb	short	_flags;		/* (*) flags, below; this FILE is free if 0 */
108178778Sjhb	short	_file;		/* (*) fileno, if Unix descriptor, else -1 */
109178829Sjhb	struct	__sbuf _bf;	/* (*) the buffer (at least 1 byte, if !NULL) */
110178778Sjhb	int	_lbfsize;	/* (*) 0 or -_bf._size, for inline putc */
111178778Sjhb
112178778Sjhb	/* operations */
113178779Sjhb	void	*_cookie;	/* (*) cookie passed to io functions */
114178778Sjhb	int	(*_close)(void *);
115178778Sjhb	int	(*_read)(void *, char *, int);
116178778Sjhb	fpos_t	(*_seek)(void *, fpos_t, int);
117178778Sjhb	int	(*_write)(void *, const char *, int);
118178778Sjhb
119178778Sjhb	/* separate buffer for long sequences of ungetc() */
120178778Sjhb	struct	__sbuf _ub;	/* ungetc buffer */
121178778Sjhb	unsigned char	*_up;	/* saved _p when _p is doing ungetc data */
122178778Sjhb	int	_ur;		/* saved _r when _r is counting ungetc data */
123178778Sjhb
124178778Sjhb	/* tricks to meet minimum requirements even when malloc() fails */
125178778Sjhb	unsigned char _ubuf[3];	/* guarantee an ungetc() buffer */
126178778Sjhb	unsigned char _nbuf[1];	/* guarantee a getc() buffer */
127178778Sjhb
128178778Sjhb	/* separate buffer for fgetln() when line crosses buffer boundary */
129178778Sjhb	struct	__sbuf _lb;	/* buffer for fgetln() */
130178778Sjhb
131178778Sjhb	/* Unix stdio files get aligned to block boundaries on fseek() */
132178778Sjhb	int	_blksize;	/* stat.st_blksize (may be != _bf._size) */
133178778Sjhb	fpos_t	_offset;	/* current lseek offset */
134178778Sjhb
135178778Sjhb	struct pthread_mutex *_fl_mutex;	/* used for MT-safety */
136178778Sjhb	struct pthread *_fl_owner;	/* current owner */
137178778Sjhb	int	_fl_count;	/* recursive lock count */
138178778Sjhb	int	_orientation;	/* orientation for fwide() */
139178778Sjhb	__mbstate_t _mbstate;	/* multibyte conversion state */
140178778Sjhb} FILE;
141178778Sjhb
142129774Stjr#ifndef _STDSTREAM_DECLARED
1431539Srgrimes__BEGIN_DECLS
14481600Speterextern FILE *__stdinp;
14581600Speterextern FILE *__stdoutp;
14681600Speterextern FILE *__stderrp;
1471539Srgrimes__END_DECLS
148129774Stjr#define	_STDSTREAM_DECLARED
149129774Stjr#endif
1501539Srgrimes
151178778Sjhb#define	__SLBF	0x0001		/* line buffered */
152178778Sjhb#define	__SNBF	0x0002		/* unbuffered */
153178778Sjhb#define	__SRD	0x0004		/* OK to read */
154178778Sjhb#define	__SWR	0x0008		/* OK to write */
155178778Sjhb	/* RD and WR are never simultaneously asserted */
156178778Sjhb#define	__SRW	0x0010		/* open for reading & writing */
157178778Sjhb#define	__SEOF	0x0020		/* found EOF */
158178778Sjhb#define	__SERR	0x0040		/* found error */
159178778Sjhb#define	__SMBF	0x0080		/* _buf is from malloc */
160178778Sjhb#define	__SAPP	0x0100		/* fdopen()ed in append mode */
161178778Sjhb#define	__SSTR	0x0200		/* this is an sprintf/snprintf string */
162178778Sjhb#define	__SOPT	0x0400		/* do fseek() optimization */
163178778Sjhb#define	__SNPT	0x0800		/* do not do fseek() optimization */
164178778Sjhb#define	__SOFF	0x1000		/* set iff _offset is in fact correct */
165178778Sjhb#define	__SMOD	0x2000		/* true => fgetln modified _p text */
166178778Sjhb#define	__SALC	0x4000		/* allocate string space dynamically */
167178778Sjhb#define	__SIGN	0x8000		/* ignore this file in _fwalk */
168178778Sjhb
1691539Srgrimes/*
1701539Srgrimes * The following three definitions are for ANSI C, which took them
1711539Srgrimes * from System V, which brilliantly took internal interface macros and
1721539Srgrimes * made them official arguments to setvbuf(), without renaming them.
1731539Srgrimes * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
174178778Sjhb *
175178778Sjhb * Although numbered as their counterparts above, the implementation
176178778Sjhb * does not rely on this.
1771539Srgrimes */
1781539Srgrimes#define	_IOFBF	0		/* setvbuf should set fully buffered */
1791539Srgrimes#define	_IOLBF	1		/* setvbuf should set line buffered */
1801539Srgrimes#define	_IONBF	2		/* setvbuf should set unbuffered */
1811539Srgrimes
1821539Srgrimes#define	BUFSIZ	1024		/* size of buffer used by setbuf */
1831539Srgrimes#define	EOF	(-1)
1841539Srgrimes
1851539Srgrimes/*
1861539Srgrimes * FOPEN_MAX is a minimum maximum, and is the number of streams that
1871539Srgrimes * stdio can provide without attempting to allocate further resources
1881539Srgrimes * (which could fail).  Do not use this for anything.
1891539Srgrimes */
1901539Srgrimes				/* must be == _POSIX_STREAM_MAX <limits.h> */
191177653Sjb#ifndef FOPEN_MAX
1921539Srgrimes#define	FOPEN_MAX	20	/* must be <= OPEN_MAX <sys/syslimits.h> */
193177653Sjb#endif
1941539Srgrimes#define	FILENAME_MAX	1024	/* must be <= PATH_MAX <sys/syslimits.h> */
1951539Srgrimes
1961539Srgrimes/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
197100133Swollman#if __XSI_VISIBLE
1981539Srgrimes#define	P_tmpdir	"/var/tmp/"
1991539Srgrimes#endif
2001539Srgrimes#define	L_tmpnam	1024	/* XXX must be == PATH_MAX */
2011539Srgrimes#define	TMP_MAX		308915776
2021539Srgrimes
2031539Srgrimes#ifndef SEEK_SET
2041539Srgrimes#define	SEEK_SET	0	/* set file offset to offset */
2051539Srgrimes#endif
2061539Srgrimes#ifndef SEEK_CUR
2071539Srgrimes#define	SEEK_CUR	1	/* set file offset to current plus offset */
2081539Srgrimes#endif
2091539Srgrimes#ifndef SEEK_END
2101539Srgrimes#define	SEEK_END	2	/* set file offset to EOF plus offset */
2111539Srgrimes#endif
2121539Srgrimes
21381600Speter#define	stdin	__stdinp
21481600Speter#define	stdout	__stdoutp
21581600Speter#define	stderr	__stderrp
2161539Srgrimes
217100133Swollman__BEGIN_DECLS
2181539Srgrimes/*
2191539Srgrimes * Functions defined in ANSI C standard.
2201539Srgrimes */
22193032Simpvoid	 clearerr(FILE *);
22293032Simpint	 fclose(FILE *);
22393032Simpint	 feof(FILE *);
22493032Simpint	 ferror(FILE *);
22593032Simpint	 fflush(FILE *);
22693032Simpint	 fgetc(FILE *);
227104989Smikeint	 fgetpos(FILE * __restrict, fpos_t * __restrict);
228104989Smikechar	*fgets(char * __restrict, int, FILE * __restrict);
229104989SmikeFILE	*fopen(const char * __restrict, const char * __restrict);
230103012Stjrint	 fprintf(FILE * __restrict, const char * __restrict, ...);
23193032Simpint	 fputc(int, FILE *);
232104989Smikeint	 fputs(const char * __restrict, FILE * __restrict);
233104989Smikesize_t	 fread(void * __restrict, size_t, size_t, FILE * __restrict);
234104989SmikeFILE	*freopen(const char * __restrict, const char * __restrict, FILE * __restrict);
235104989Smikeint	 fscanf(FILE * __restrict, const char * __restrict, ...);
23693032Simpint	 fseek(FILE *, long, int);
23793032Simpint	 fsetpos(FILE *, const fpos_t *);
23893032Simplong	 ftell(FILE *);
239104989Smikesize_t	 fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
24093032Simpint	 getc(FILE *);
24193032Simpint	 getchar(void);
24293032Simpchar	*gets(char *);
24393032Simpvoid	 perror(const char *);
244103012Stjrint	 printf(const char * __restrict, ...);
24593032Simpint	 putc(int, FILE *);
24693032Simpint	 putchar(int);
24793032Simpint	 puts(const char *);
24893032Simpint	 remove(const char *);
24993032Simpint	 rename(const char *, const char *);
25093032Simpvoid	 rewind(FILE *);
251104989Smikeint	 scanf(const char * __restrict, ...);
252103012Stjrvoid	 setbuf(FILE * __restrict, char * __restrict);
253103012Stjrint	 setvbuf(FILE * __restrict, char * __restrict, int, size_t);
254103012Stjrint	 sprintf(char * __restrict, const char * __restrict, ...);
255104989Smikeint	 sscanf(const char * __restrict, const char * __restrict, ...);
25693032SimpFILE	*tmpfile(void);
25793032Simpchar	*tmpnam(char *);
25893032Simpint	 ungetc(int, FILE *);
259103012Stjrint	 vfprintf(FILE * __restrict, const char * __restrict,
260102227Smike	    __va_list);
261103012Stjrint	 vprintf(const char * __restrict, __va_list);
262103012Stjrint	 vsprintf(char * __restrict, const char * __restrict,
263102227Smike	    __va_list);
2641539Srgrimes
265100133Swollman#if __ISO_C_VISIBLE >= 1999
266103012Stjrint	 snprintf(char * __restrict, size_t, const char * __restrict,
267101914Srobert	    ...) __printflike(3, 4);
268105098Stjrint	 vfscanf(FILE * __restrict, const char * __restrict, __va_list)
269105098Stjr	    __scanflike(2, 0);
270104989Smikeint	 vscanf(const char * __restrict, __va_list) __scanflike(1, 0);
271103012Stjrint	 vsnprintf(char * __restrict, size_t, const char * __restrict,
272102227Smike	    __va_list) __printflike(3, 0);
273104989Smikeint	 vsscanf(const char * __restrict, const char * __restrict, __va_list)
274104585Smike	    __scanflike(2, 0);
275100133Swollman#endif
276100133Swollman
2771539Srgrimes/*
278100133Swollman * Functions defined in all versions of POSIX 1003.1.
2791539Srgrimes */
280104585Smike#if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506
28119211Swosch/* size for cuserid(3); UT_NAMESIZE + 1, see <utmp.h> */
282104585Smike#define	L_cuserid	17	/* legacy */
283104585Smike#endif
2841539Srgrimes
285104585Smike#if __POSIX_VISIBLE
28619211Swosch#define	L_ctermid	1024	/* size for ctermid(3); PATH_MAX */
28719211Swosch
28893032Simpchar	*ctermid(char *);
28993032SimpFILE	*fdopen(int, const char *);
29093032Simpint	 fileno(FILE *);
291100133Swollman#endif /* __POSIX_VISIBLE */
292100133Swollman
293100133Swollman#if __POSIX_VISIBLE >= 199209
294100133Swollmanint	 pclose(FILE *);
295100133SwollmanFILE	*popen(const char *, const char *);
296100133Swollman#endif
297100133Swollman
298100133Swollman#if __POSIX_VISIBLE >= 199506
29993032Simpint	 ftrylockfile(FILE *);
30093032Simpvoid	 flockfile(FILE *);
30193032Simpvoid	 funlockfile(FILE *);
3021539Srgrimes
3031539Srgrimes/*
304178778Sjhb * These are normally used through macros as defined below, but POSIX
305178778Sjhb * requires functions as well.
30624897Sbde */
307100133Swollmanint	 getc_unlocked(FILE *);
308100133Swollmanint	 getchar_unlocked(void);
309100133Swollmanint	 putc_unlocked(int, FILE *);
310100133Swollmanint	 putchar_unlocked(int);
31124897Sbde#endif
312109168Stjr#if __BSD_VISIBLE
313178722Sjhbvoid	 clearerr_unlocked(FILE *);
314178722Sjhbint	 feof_unlocked(FILE *);
315178722Sjhbint	 ferror_unlocked(FILE *);
316178722Sjhbint	 fileno_unlocked(FILE *);
317109168Stjr#endif
318100133Swollman
319100133Swollman#if __POSIX_VISIBLE >= 200112
320102227Smikeint	 fseeko(FILE *, __off_t, int);
321102227Smike__off_t	 ftello(FILE *);
32224897Sbde#endif
323100133Swollman
324100133Swollman#if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600
325100133Swollmanint	 getw(FILE *);
326100133Swollmanint	 putw(int, FILE *);
327100133Swollman#endif /* BSD or X/Open before issue 6 */
328100133Swollman
329100133Swollman#if __XSI_VISIBLE
330100133Swollmanchar	*tempnam(const char *, const char *);
33124897Sbde#endif
33224897Sbde
33324897Sbde/*
3341539Srgrimes * Routines that are purely local.
3351539Srgrimes */
336100133Swollman#if __BSD_VISIBLE
33793032Simpint	 asprintf(char **, const char *, ...) __printflike(2, 3);
33893032Simpchar	*ctermid_r(char *);
339178722Sjhbvoid	 fcloseall(void);
34093032Simpchar	*fgetln(FILE *, size_t *);
341154867Sstefanf__const char *fmtcheck(const char *, const char *) __format_arg(2);
34293032Simpint	 fpurge(FILE *);
343178722Sjhbint	 renameat(int, const char *, int, const char *);
34493032Simpvoid	 setbuffer(FILE *, char *, int);
34593032Simpint	 setlinebuf(FILE *);
346102227Smikeint	 vasprintf(char **, const char *, __va_list)
34737614Sbde	    __printflike(2, 0);
3481539Srgrimes
3491539Srgrimes/*
350100133Swollman * The system error table contains messages for the first sys_nerr
351100133Swollman * positive errno values.  Use strerror() or strerror_r() from <string.h>
352100133Swollman * instead.
353100133Swollman */
354100133Swollmanextern __const int sys_nerr;
355100133Swollmanextern __const char *__const sys_errlist[];
356100133Swollman
357100133Swollman/*
3581539Srgrimes * Stdio function-access interface.
3591539Srgrimes */
36093032SimpFILE	*funopen(const void *,
36175818Sobrien	    int (*)(void *, char *, int),
36275818Sobrien	    int (*)(void *, const char *, int),
36375818Sobrien	    fpos_t (*)(void *, fpos_t, int),
36493032Simp	    int (*)(void *));
3651539Srgrimes#define	fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
3661539Srgrimes#define	fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
3671539Srgrimes
3681539Srgrimes/*
369100133Swollman * Portability hacks.  See <sys/types.h>.
370100133Swollman */
371100133Swollman#ifndef _FTRUNCATE_DECLARED
372100133Swollman#define	_FTRUNCATE_DECLARED
373102227Smikeint	 ftruncate(int, __off_t);
374100133Swollman#endif
375100133Swollman#ifndef _LSEEK_DECLARED
376100133Swollman#define	_LSEEK_DECLARED
377102227Smike__off_t	 lseek(int, __off_t, int);
378100133Swollman#endif
379100133Swollman#ifndef _MMAP_DECLARED
380100133Swollman#define	_MMAP_DECLARED
381102227Smikevoid	*mmap(void *, size_t, int, int, int, __off_t);
382100133Swollman#endif
383100133Swollman#ifndef _TRUNCATE_DECLARED
384100133Swollman#define	_TRUNCATE_DECLARED
385102227Smikeint	 truncate(const char *, __off_t);
386100133Swollman#endif
387100133Swollman#endif /* __BSD_VISIBLE */
388100133Swollman
389178778Sjhb/*
390178778Sjhb * Functions internal to the implementation.
391178778Sjhb */
392178778Sjhbint	__srget(FILE *);
393178778Sjhbint	__swbuf(int, FILE *);
394178778Sjhb
395178778Sjhb/*
396178778Sjhb * The __sfoo macros are here so that we can
397178778Sjhb * define function versions in the C library.
398178778Sjhb */
399178778Sjhb#define	__sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
400178778Sjhb#if defined(__GNUC__) && defined(__STDC__)
401178778Sjhbstatic __inline int __sputc(int _c, FILE *_p) {
402178778Sjhb	if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
403178778Sjhb		return (*_p->_p++ = _c);
404178778Sjhb	else
405178778Sjhb		return (__swbuf(_c, _p));
406178778Sjhb}
407178778Sjhb#else
408178778Sjhb/*
409178778Sjhb * This has been tuned to generate reasonable code on the vax using pcc.
410178778Sjhb */
411178778Sjhb#define	__sputc(c, p) \
412178778Sjhb	(--(p)->_w < 0 ? \
413178778Sjhb		(p)->_w >= (p)->_lbfsize ? \
414178778Sjhb			(*(p)->_p = (c)), *(p)->_p != '\n' ? \
415178778Sjhb				(int)*(p)->_p++ : \
416178778Sjhb				__swbuf('\n', p) : \
417178778Sjhb			__swbuf((int)(c), p) : \
418178778Sjhb		(*(p)->_p = (c), (int)*(p)->_p++))
419178778Sjhb#endif
420178778Sjhb
421178778Sjhb#define	__sfeof(p)	(((p)->_flags & __SEOF) != 0)
422178778Sjhb#define	__sferror(p)	(((p)->_flags & __SERR) != 0)
423178778Sjhb#define	__sclearerr(p)	((void)((p)->_flags &= ~(__SERR|__SEOF)))
424178778Sjhb#define	__sfileno(p)	((p)->_file)
425178778Sjhb
426178778Sjhbextern int __isthreaded;
427178778Sjhb
428178778Sjhb#define	feof(p)		(!__isthreaded ? __sfeof(p) : (feof)(p))
429178778Sjhb#define	ferror(p)	(!__isthreaded ? __sferror(p) : (ferror)(p))
430178778Sjhb#define	clearerr(p)	(!__isthreaded ? __sclearerr(p) : (clearerr)(p))
431178778Sjhb
432178778Sjhb#if __POSIX_VISIBLE
433178778Sjhb#define	fileno(p)	(!__isthreaded ? __sfileno(p) : (fileno)(p))
434178778Sjhb#endif
435178778Sjhb
436178778Sjhb#define	getc(fp)	(!__isthreaded ? __sgetc(fp) : (getc)(fp))
437178778Sjhb#define	putc(x, fp)	(!__isthreaded ? __sputc(x, fp) : (putc)(x, fp))
438178778Sjhb
439178778Sjhb#define	getchar()	getc(stdin)
440178778Sjhb#define	putchar(x)	putc(x, stdout)
441178778Sjhb
442178778Sjhb#if __BSD_VISIBLE
443178778Sjhb/*
444178778Sjhb * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12
445178778Sjhb * B.8.2.7 for the rationale behind the *_unlocked() macros.
446178778Sjhb */
447178778Sjhb#define	feof_unlocked(p)	__sfeof(p)
448178778Sjhb#define	ferror_unlocked(p)	__sferror(p)
449178778Sjhb#define	clearerr_unlocked(p)	__sclearerr(p)
450178778Sjhb#define	fileno_unlocked(p)	__sfileno(p)
451178778Sjhb#endif
452178778Sjhb#if __POSIX_VISIBLE >= 199506
453178778Sjhb#define	getc_unlocked(fp)	__sgetc(fp)
454178778Sjhb#define	putc_unlocked(x, fp)	__sputc(x, fp)
455178778Sjhb
456178778Sjhb#define	getchar_unlocked()	getc_unlocked(stdin)
457178778Sjhb#define	putchar_unlocked(x)	putc_unlocked(x, stdout)
458178778Sjhb#endif
459178778Sjhb
460100133Swollman__END_DECLS
46124897Sbde#endif /* !_STDIO_H_ */
462