stdio.h revision 178782
11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1990, 1993 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * This code is derived from software contributed to Berkeley by 61556Srgrimes * Chris Torek. 71556Srgrimes * 81556Srgrimes * Redistribution and use in source and binary forms, with or without 91556Srgrimes * modification, are permitted provided that the following conditions 101556Srgrimes * are met: 111556Srgrimes * 1. Redistributions of source code must retain the above copyright 121556Srgrimes * notice, this list of conditions and the following disclaimer. 131556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141556Srgrimes * notice, this list of conditions and the following disclaimer in the 151556Srgrimes * documentation and/or other materials provided with the distribution. 161556Srgrimes * 3. All advertising materials mentioning features or use of this software 171556Srgrimes * must display the following acknowledgement: 181556Srgrimes * This product includes software developed by the University of 191556Srgrimes * California, Berkeley and its contributors. 201556Srgrimes * 4. Neither the name of the University nor the names of its contributors 211556Srgrimes * may be used to endorse or promote products derived from this software 221556Srgrimes * without specific prior written permission. 231556Srgrimes * 241556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341556Srgrimes * SUCH DAMAGE. 351556Srgrimes * 361556Srgrimes * @(#)stdio.h 8.5 (Berkeley) 4/29/95 371556Srgrimes * $FreeBSD: head/include/stdio.h 178782 2008-05-05 16:14:02Z jhb $ 381556Srgrimes */ 3936049Scharnier 4036049Scharnier#ifndef _STDIO_H_ 4136049Scharnier#define _STDIO_H_ 4236049Scharnier 4350471Speter#include <sys/cdefs.h> 441556Srgrimes#include <sys/_null.h> 451556Srgrimes#include <sys/_types.h> 461556Srgrimes 471556Srgrimestypedef __off_t fpos_t; 481556Srgrimes 491556Srgrimes#ifndef _SIZE_T_DECLARED 501556Srgrimestypedef __size_t size_t; 511556Srgrimes#define _SIZE_T_DECLARED 521556Srgrimes#endif 531556Srgrimes 541556Srgrimes#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE 551556Srgrimes#ifndef _VA_LIST_DECLARED 561556Srgrimestypedef __va_list va_list; 571556Srgrimes#define _VA_LIST_DECLARED 581556Srgrimes#endif 591556Srgrimes#endif 601556Srgrimes 611556Srgrimes#define _FSTDIO /* Define for new stdio with functions. */ 621556Srgrimes 631556Srgrimes/* 641556Srgrimes * NB: to fit things in six character monocase externals, the stdio 651556Srgrimes * code uses the prefix `__s' for stdio objects, typically followed 661556Srgrimes * by a three-character attempt at a mnemonic. 671556Srgrimes */ 681556Srgrimes 691556Srgrimes/* stdio buffers */ 701556Srgrimesstruct __sbuf { 711556Srgrimes unsigned char *_base; 721556Srgrimes int _size; 731556Srgrimes}; 741556Srgrimes 751556Srgrimes/* 761556Srgrimes * stdio state variables. 771556Srgrimes * 781556Srgrimes * The following always hold: 791556Srgrimes * 801556Srgrimes * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), 8176017Skris * _lbfsize is -_bf._size, else _lbfsize is 0 821556Srgrimes * if _flags&__SRD, _w is 0 831556Srgrimes * if _flags&__SWR, _r is 0 841556Srgrimes * 851556Srgrimes * This ensures that the getc and putc macros (or inline functions) never 861556Srgrimes * try to write or read from a file that is in `read' or `write' mode. 871556Srgrimes * (Moreover, they can, and do, automatically switch from read mode to 881556Srgrimes * write mode, and back, on "r+" and "w+" files.) 891556Srgrimes * 901556Srgrimes * _lbfsize is used only to make the inline line-buffered output stream 911556Srgrimes * code as compact as possible. 921556Srgrimes * 931556Srgrimes * _ub, _up, and _ur are used when ungetc() pushes back more characters 941556Srgrimes * than fit in the current _bf, or when ungetc() pushes back a character 951556Srgrimes * that does not match the previous one in _bf. When this happens, 961556Srgrimes * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff 971556Srgrimes * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. 981556Srgrimes * 9976017Skris * Certain members of __sFILE are accessed directly via macros or 1001556Srgrimes * inline functions. To preserve ABI compat, these members must not 1011556Srgrimes * be disturbed. These members are marked below with (*). 1021556Srgrimes */ 1031556Srgrimestypedef struct __sFILE { 1041556Srgrimes unsigned char *_p; /* (*) current position in (some) buffer */ 1051556Srgrimes int _r; /* (*) read space left for getc() */ 1061556Srgrimes int _w; /* (*) write space left for putc() */ 1071556Srgrimes short _flags; /* (*) flags, below; this FILE is free if 0 */ 1081556Srgrimes short _file; /* (*) fileno, if Unix descriptor, else -1 */ 1091556Srgrimes struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ 1101556Srgrimes int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */ 1111556Srgrimes 1121556Srgrimes /* operations */ 1131556Srgrimes void *_cookie; /* (*) cookie passed to io functions */ 1141556Srgrimes int (*_close)(void *); 1151556Srgrimes int (*_read)(void *, char *, int); 1161556Srgrimes fpos_t (*_seek)(void *, fpos_t, int); 1171556Srgrimes int (*_write)(void *, const char *, int); 1181556Srgrimes 1191556Srgrimes /* separate buffer for long sequences of ungetc() */ 1201556Srgrimes struct __sbuf _ub; /* ungetc buffer */ 12176017Skris unsigned char *_up; /* saved _p when _p is doing ungetc data */ 1221556Srgrimes int _ur; /* saved _r when _r is counting ungetc data */ 1231556Srgrimes 1241556Srgrimes /* tricks to meet minimum requirements even when malloc() fails */ 1251556Srgrimes unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ 1261556Srgrimes unsigned char _nbuf[1]; /* guarantee a getc() buffer */ 1271556Srgrimes 1281556Srgrimes /* separate buffer for fgetln() when line crosses buffer boundary */ 1291556Srgrimes struct __sbuf _lb; /* buffer for fgetln() */ 1301556Srgrimes 1311556Srgrimes /* Unix stdio files get aligned to block boundaries on fseek() */ 1321556Srgrimes int _blksize; /* stat.st_blksize (may be != _bf._size) */ 1331556Srgrimes fpos_t _offset; /* current lseek offset */ 1341556Srgrimes 1351556Srgrimes struct pthread_mutex *_fl_mutex; /* used for MT-safety */ 1361556Srgrimes struct pthread *_fl_owner; /* current owner */ 1371556Srgrimes int _fl_count; /* recursive lock count */ 1381556Srgrimes int _orientation; /* orientation for fwide() */ 1391556Srgrimes __mbstate_t _mbstate; /* multibyte conversion state */ 1401556Srgrimes} FILE; 1411556Srgrimes 1421556Srgrimes#ifndef _STDSTREAM_DECLARED 1431556Srgrimes__BEGIN_DECLS 1441556Srgrimesextern FILE *__stdinp; 1451556Srgrimesextern FILE *__stdoutp; 1461556Srgrimesextern FILE *__stderrp; 1471556Srgrimes__END_DECLS 1481556Srgrimes#define _STDSTREAM_DECLARED 1491556Srgrimes#endif 1501556Srgrimes 1511556Srgrimes#define __SLBF 0x0001 /* line buffered */ 1521556Srgrimes#define __SNBF 0x0002 /* unbuffered */ 1531556Srgrimes#define __SRD 0x0004 /* OK to read */ 1541556Srgrimes#define __SWR 0x0008 /* OK to write */ 1551556Srgrimes /* RD and WR are never simultaneously asserted */ 1561556Srgrimes#define __SRW 0x0010 /* open for reading & writing */ 1571556Srgrimes#define __SEOF 0x0020 /* found EOF */ 1581556Srgrimes#define __SERR 0x0040 /* found error */ 1591556Srgrimes#define __SMBF 0x0080 /* _buf is from malloc */ 1601556Srgrimes#define __SAPP 0x0100 /* fdopen()ed in append mode */ 1611556Srgrimes#define __SSTR 0x0200 /* this is an sprintf/snprintf string */ 1621556Srgrimes#define __SOPT 0x0400 /* do fseek() optimization */ 1631556Srgrimes#define __SNPT 0x0800 /* do not do fseek() optimization */ 1641556Srgrimes#define __SOFF 0x1000 /* set iff _offset is in fact correct */ 1651556Srgrimes#define __SMOD 0x2000 /* true => fgetln modified _p text */ 1661556Srgrimes#define __SALC 0x4000 /* allocate string space dynamically */ 1671556Srgrimes#define __SIGN 0x8000 /* ignore this file in _fwalk */ 1681556Srgrimes 1691556Srgrimes/* 1701556Srgrimes * The following three definitions are for ANSI C, which took them 1711556Srgrimes * from System V, which brilliantly took internal interface macros and 17276017Skris * made them official arguments to setvbuf(), without renaming them. 1731556Srgrimes * Hence, these ugly _IOxxx names are *supposed* to appear in user code. 1741556Srgrimes * 1751556Srgrimes * Although numbered as their counterparts above, the implementation 1761556Srgrimes * does not rely on this. 1771556Srgrimes */ 1781556Srgrimes#define _IOFBF 0 /* setvbuf should set fully buffered */ 1791556Srgrimes#define _IOLBF 1 /* setvbuf should set line buffered */ 1801556Srgrimes#define _IONBF 2 /* setvbuf should set unbuffered */ 1811556Srgrimes 1821556Srgrimes#define BUFSIZ 1024 /* size of buffer used by setbuf */ 1831556Srgrimes#define EOF (-1) 1841556Srgrimes 1858855Srgrimes/* 1861556Srgrimes * FOPEN_MAX is a minimum maximum, and is the number of streams that 1871556Srgrimes * stdio can provide without attempting to allocate further resources 1881556Srgrimes * (which could fail). Do not use this for anything. 1891556Srgrimes */ 1901556Srgrimes /* must be == _POSIX_STREAM_MAX <limits.h> */ 1911556Srgrimes#ifndef FOPEN_MAX 1921556Srgrimes#define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ 1931556Srgrimes#endif 1941556Srgrimes#define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ 1951556Srgrimes 1961556Srgrimes/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ 1971556Srgrimes#if __XSI_VISIBLE 1981556Srgrimes#define P_tmpdir "/var/tmp/" 1991556Srgrimes#endif 2001556Srgrimes#define L_tmpnam 1024 /* XXX must be == PATH_MAX */ 2011556Srgrimes#define TMP_MAX 308915776 2021556Srgrimes 2031556Srgrimes#ifndef SEEK_SET 2041556Srgrimes#define SEEK_SET 0 /* set file offset to offset */ 2051556Srgrimes#endif 2061556Srgrimes#ifndef SEEK_CUR 2071556Srgrimes#define SEEK_CUR 1 /* set file offset to current plus offset */ 2081556Srgrimes#endif 2091556Srgrimes#ifndef SEEK_END 2101556Srgrimes#define SEEK_END 2 /* set file offset to EOF plus offset */ 2111556Srgrimes#endif 2121556Srgrimes 2131556Srgrimes#define stdin __stdinp 2141556Srgrimes#define stdout __stdoutp 2151556Srgrimes#define stderr __stderrp 2161556Srgrimes 2171556Srgrimes__BEGIN_DECLS 2181556Srgrimes/* 2191556Srgrimes * Functions defined in ANSI C standard. 2201556Srgrimes */ 2211556Srgrimesvoid clearerr(FILE *); 2221556Srgrimesint fclose(FILE *); 2231556Srgrimesint feof(FILE *); 2241556Srgrimesint ferror(FILE *); 2251556Srgrimesint fflush(FILE *); 2261556Srgrimesint fgetc(FILE *); 2271556Srgrimesint fgetpos(FILE * __restrict, fpos_t * __restrict); 2281556Srgrimeschar *fgets(char * __restrict, int, FILE * __restrict); 2291556SrgrimesFILE *fopen(const char * __restrict, const char * __restrict); 2301556Srgrimesint fprintf(FILE * __restrict, const char * __restrict, ...); 2311556Srgrimesint fputc(int, FILE *); 2321556Srgrimesint fputs(const char * __restrict, FILE * __restrict); 2331556Srgrimessize_t fread(void * __restrict, size_t, size_t, FILE * __restrict); 2341556SrgrimesFILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict); 2351556Srgrimesint fscanf(FILE * __restrict, const char * __restrict, ...); 23676017Skrisint fseek(FILE *, long, int); 2371556Srgrimesint fsetpos(FILE *, const fpos_t *); 2381556Srgrimeslong ftell(FILE *); 2391556Srgrimessize_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); 2401556Srgrimesint getc(FILE *); 2411556Srgrimesint getchar(void); 2421556Srgrimeschar *gets(char *); 2431556Srgrimesvoid perror(const char *); 2441556Srgrimesint printf(const char * __restrict, ...); 2451556Srgrimesint putc(int, FILE *); 2461556Srgrimesint putchar(int); 2471556Srgrimesint puts(const char *); 2481556Srgrimesint remove(const char *); 2498855Srgrimesint rename(const char *, const char *); 2501556Srgrimesvoid rewind(FILE *); 2511556Srgrimesint scanf(const char * __restrict, ...); 2521556Srgrimesvoid setbuf(FILE * __restrict, char * __restrict); 2531556Srgrimesint setvbuf(FILE * __restrict, char * __restrict, int, size_t); 2541556Srgrimesint sprintf(char * __restrict, const char * __restrict, ...); 2551556Srgrimesint sscanf(const char * __restrict, const char * __restrict, ...); 2561556SrgrimesFILE *tmpfile(void); 2571556Srgrimeschar *tmpnam(char *); 2581556Srgrimesint ungetc(int, FILE *); 2591556Srgrimesint vfprintf(FILE * __restrict, const char * __restrict, 2601556Srgrimes __va_list); 2611556Srgrimesint vprintf(const char * __restrict, __va_list); 2621556Srgrimesint vsprintf(char * __restrict, const char * __restrict, 2631556Srgrimes __va_list); 2641556Srgrimes 2651556Srgrimes#if __ISO_C_VISIBLE >= 1999 2661556Srgrimesint snprintf(char * __restrict, size_t, const char * __restrict, 2671556Srgrimes ...) __printflike(3, 4); 2681556Srgrimesint vfscanf(FILE * __restrict, const char * __restrict, __va_list) 2691556Srgrimes __scanflike(2, 0); 2701556Srgrimesint vscanf(const char * __restrict, __va_list) __scanflike(1, 0); 2711556Srgrimesint vsnprintf(char * __restrict, size_t, const char * __restrict, 2721556Srgrimes __va_list) __printflike(3, 0); 2731556Srgrimesint vsscanf(const char * __restrict, const char * __restrict, __va_list) 2741556Srgrimes __scanflike(2, 0); 2751556Srgrimes#endif 2761556Srgrimes 2771556Srgrimes/* 2781556Srgrimes * Functions defined in all versions of POSIX 1003.1. 2791556Srgrimes */ 2801556Srgrimes#if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506 2811556Srgrimes/* size for cuserid(3); UT_NAMESIZE + 1, see <utmp.h> */ 2821556Srgrimes#define L_cuserid 17 /* legacy */ 2831556Srgrimes#endif 2841556Srgrimes 2851556Srgrimes#if __POSIX_VISIBLE 2861556Srgrimes#define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */ 2871556Srgrimes 2881556Srgrimeschar *ctermid(char *); 2891556SrgrimesFILE *fdopen(int, const char *); 2901556Srgrimesint fileno(FILE *); 2911556Srgrimes#endif /* __POSIX_VISIBLE */ 29246684Skris 2931556Srgrimes#if __POSIX_VISIBLE >= 199209 2941556Srgrimesint pclose(FILE *); 2951556SrgrimesFILE *popen(const char *, const char *); 2961556Srgrimes#endif 2971556Srgrimes 2981556Srgrimes#if __POSIX_VISIBLE >= 199506 29976017Skrisint ftrylockfile(FILE *); 3001556Srgrimesvoid flockfile(FILE *); 3011556Srgrimesvoid funlockfile(FILE *); 3021556Srgrimes 3031556Srgrimes/* 3041556Srgrimes * These are normally used through macros as defined below, but POSIX 3051556Srgrimes * requires functions as well. 3061556Srgrimes */ 3071556Srgrimesint getc_unlocked(FILE *); 3081556Srgrimesint getchar_unlocked(void); 3091556Srgrimesint putc_unlocked(int, FILE *); 3101556Srgrimesint putchar_unlocked(int); 31146684Skris#endif 3121556Srgrimes#if __BSD_VISIBLE 3131556Srgrimesvoid clearerr_unlocked(FILE *); 3141556Srgrimesint feof_unlocked(FILE *); 3151556Srgrimesint ferror_unlocked(FILE *); 3161556Srgrimesint fileno_unlocked(FILE *); 3171556Srgrimes#endif 3188855Srgrimes 3198855Srgrimes#if __POSIX_VISIBLE >= 200112 3201556Srgrimesint fseeko(FILE *, __off_t, int); 3211556Srgrimes__off_t ftello(FILE *); 3221556Srgrimes#endif 3231556Srgrimes 3241556Srgrimes#if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 3251556Srgrimesint getw(FILE *); 3261556Srgrimesint putw(int, FILE *); 3271556Srgrimes#endif /* BSD or X/Open before issue 6 */ 3281556Srgrimes 3291556Srgrimes#if __XSI_VISIBLE 3308855Srgrimeschar *tempnam(const char *, const char *); 3311556Srgrimes#endif 3321556Srgrimes 3331556Srgrimes/* 3341556Srgrimes * Routines that are purely local. 3351556Srgrimes */ 3361556Srgrimes#if __BSD_VISIBLE 3371556Srgrimesint asprintf(char **, const char *, ...) __printflike(2, 3); 3381556Srgrimeschar *ctermid_r(char *); 3391556Srgrimesvoid fcloseall(void); 3401556Srgrimeschar *fgetln(FILE *, size_t *); 3411556Srgrimes__const char *fmtcheck(const char *, const char *) __format_arg(2); 3421556Srgrimesint fpurge(FILE *); 3431556Srgrimesint renameat(int, const char *, int, const char *); 3441556Srgrimesvoid setbuffer(FILE *, char *, int); 3451556Srgrimesint setlinebuf(FILE *); 3461556Srgrimesint vasprintf(char **, const char *, __va_list) 34776017Skris __printflike(2, 0); 3481556Srgrimes 3491556Srgrimes/* 3501556Srgrimes * The system error table contains messages for the first sys_nerr 3511556Srgrimes * positive errno values. Use strerror() or strerror_r() from <string.h> 3521556Srgrimes * instead. 3531556Srgrimes */ 3541556Srgrimesextern __const int sys_nerr; 3551556Srgrimesextern __const char *__const sys_errlist[]; 3561556Srgrimes 3571556Srgrimes/* 3581556Srgrimes * Stdio function-access interface. 3591556Srgrimes */ 3601556SrgrimesFILE *funopen(const void *, 3611556Srgrimes int (*)(void *, char *, int), 3621556Srgrimes int (*)(void *, const char *, int), 3631556Srgrimes fpos_t (*)(void *, fpos_t, int), 3641556Srgrimes int (*)(void *)); 3651556Srgrimes#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) 3661556Srgrimes#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) 3671556Srgrimes 3681556Srgrimes/* 3691556Srgrimes * Portability hacks. See <sys/types.h>. 3701556Srgrimes */ 3711556Srgrimes#ifndef _FTRUNCATE_DECLARED 3721556Srgrimes#define _FTRUNCATE_DECLARED 3731556Srgrimesint ftruncate(int, __off_t); 3741556Srgrimes#endif 3751556Srgrimes#ifndef _LSEEK_DECLARED 3761556Srgrimes#define _LSEEK_DECLARED 3771556Srgrimes__off_t lseek(int, __off_t, int); 3781556Srgrimes#endif 3791556Srgrimes#ifndef _MMAP_DECLARED 3801556Srgrimes#define _MMAP_DECLARED 3811556Srgrimesvoid *mmap(void *, size_t, int, int, int, __off_t); 3821556Srgrimes#endif 3831556Srgrimes#ifndef _TRUNCATE_DECLARED 3841556Srgrimes#define _TRUNCATE_DECLARED 3851556Srgrimesint truncate(const char *, __off_t); 3861556Srgrimes#endif 3871556Srgrimes#endif /* __BSD_VISIBLE */ 38876017Skris 3891556Srgrimes/* 3901556Srgrimes * Functions internal to the implementation. 3911556Srgrimes */ 3921556Srgrimesint __srget(FILE *); 3931556Srgrimesint __swbuf(int, FILE *); 3941556Srgrimes 3951556Srgrimes/* 3961556Srgrimes * The __sfoo macros are here so that we can 3971556Srgrimes * define function versions in the C library. 3981556Srgrimes */ 3991556Srgrimes#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) 4001556Srgrimes#if defined(__GNUC__) && defined(__STDC__) 40176017Skrisstatic __inline int __sputc(int _c, FILE *_p) { 4021556Srgrimes if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) 40376017Skris return (*_p->_p++ = _c); 4041556Srgrimes else 4051556Srgrimes return (__swbuf(_c, _p)); 4061556Srgrimes} 4071556Srgrimes#else 4081556Srgrimes/* 4091556Srgrimes * This has been tuned to generate reasonable code on the vax using pcc. 4101556Srgrimes */ 4111556Srgrimes#define __sputc(c, p) \ 41276017Skris (--(p)->_w < 0 ? \ 4131556Srgrimes (p)->_w >= (p)->_lbfsize ? \ 4141556Srgrimes (*(p)->_p = (c)), *(p)->_p != '\n' ? \ 4151556Srgrimes (int)*(p)->_p++ : \ 4161556Srgrimes __swbuf('\n', p) : \ 4171556Srgrimes __swbuf((int)(c), p) : \ 4181556Srgrimes (*(p)->_p = (c), (int)*(p)->_p++)) 4191556Srgrimes#endif 4201556Srgrimes 4211556Srgrimes#define __sfeof(p) (((p)->_flags & __SEOF) != 0) 4221556Srgrimes#define __sferror(p) (((p)->_flags & __SERR) != 0) 4231556Srgrimes#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) 4241556Srgrimes#define __sfileno(p) ((p)->_file) 4251556Srgrimes 4261556Srgrimesextern int __isthreaded; 4271556Srgrimes 4281556Srgrimes#define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p)) 4291556Srgrimes#define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p)) 43076017Skris#define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p)) 4311556Srgrimes 4321556Srgrimes#if __POSIX_VISIBLE 4331556Srgrimes#define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p)) 4341556Srgrimes#endif 4351556Srgrimes 4361556Srgrimes#define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp)) 4371556Srgrimes#define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp)) 4381556Srgrimes 4391556Srgrimes#define getchar() getc(stdin) 4401556Srgrimes#define putchar(x) putc(x, stdout) 4411556Srgrimes 4421556Srgrimes#if __BSD_VISIBLE 4431556Srgrimes/* 4441556Srgrimes * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12 4451556Srgrimes * B.8.2.7 for the rationale behind the *_unlocked() macros. 4461556Srgrimes */ 4471556Srgrimes#define feof_unlocked(p) __sfeof(p) 4481556Srgrimes#define ferror_unlocked(p) __sferror(p) 4491556Srgrimes#define clearerr_unlocked(p) __sclearerr(p) 4501556Srgrimes#define fileno_unlocked(p) __sfileno(p) 4511556Srgrimes#endif 4521556Srgrimes#if __POSIX_VISIBLE >= 199506 4531556Srgrimes#define getc_unlocked(fp) __sgetc(fp) 4541556Srgrimes#define putc_unlocked(x, fp) __sputc(x, fp) 4551556Srgrimes 4561556Srgrimes#define getchar_unlocked() getc_unlocked(stdin) 4571556Srgrimes#define putchar_unlocked(x) putc_unlocked(x, stdout) 4581556Srgrimes#endif 4591556Srgrimes 4601556Srgrimes__END_DECLS 4611556Srgrimes#endif /* !_STDIO_H_ */ 4621556Srgrimes