stdio.h revision 189356
1180740Sdes/*- 2255670Sdes * Copyright (c) 1990, 1993 3180740Sdes * The Regents of the University of California. All rights reserved. 4225825Sdes * 5180740Sdes * This code is derived from software contributed to Berkeley by 6180740Sdes * Chris Torek. 7180740Sdes * 8225825Sdes * Redistribution and use in source and binary forms, with or without 9180740Sdes * modification, are permitted provided that the following conditions 10225825Sdes * are met: 11225825Sdes * 1. Redistributions of source code must retain the above copyright 12225825Sdes * notice, this list of conditions and the following disclaimer. 13225825Sdes * 2. Redistributions in binary form must reproduce the above copyright 14180740Sdes * notice, this list of conditions and the following disclaimer in the 15180740Sdes * documentation and/or other materials provided with the distribution. 16225825Sdes * 3. All advertising materials mentioning features or use of this software 17225825Sdes * must display the following acknowledgement: 18225825Sdes * This product includes software developed by the University of 19180740Sdes * California, Berkeley and its contributors. 20180740Sdes * 4. Neither the name of the University nor the names of its contributors 21180740Sdes * may be used to endorse or promote products derived from this software 22225825Sdes * without specific prior written permission. 23180740Sdes * 24180740Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25225825Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26180740Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27180740Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28180740Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29180740Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30225825Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31225825Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32225825Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33225825Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34225825Sdes * SUCH DAMAGE. 35180740Sdes * 36180740Sdes * @(#)stdio.h 8.5 (Berkeley) 4/29/95 37180740Sdes * $FreeBSD: head/include/stdio.h 189356 2009-03-04 03:38:51Z das $ 38180740Sdes */ 39225825Sdes 40225825Sdes#ifndef _STDIO_H_ 41225825Sdes#define _STDIO_H_ 42225825Sdes 43225825Sdes#include <sys/cdefs.h> 44225825Sdes#include <sys/_null.h> 45225825Sdes#include <sys/_types.h> 46225825Sdes 47225825Sdestypedef __off_t fpos_t; 48225825Sdes 49225825Sdes#ifndef _SIZE_T_DECLARED 50225825Sdestypedef __size_t size_t; 51225825Sdes#define _SIZE_T_DECLARED 52225825Sdes#endif 53225825Sdes 54225825Sdes#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 55225825Sdes#ifndef _OFF_T_DECLARED 56225825Sdes#define _OFF_T_DECLARED 57225825Sdestypedef __off_t off_t; 58225825Sdes#endif 59180740Sdes#ifndef _SSIZE_T_DECLARED 60225825Sdes#define _SSIZE_T_DECLARED 61225825Sdestypedef __ssize_t ssize_t; 62225825Sdes#endif 63225825Sdes#endif 64225825Sdes 65225825Sdes#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE 66225825Sdes#ifndef _VA_LIST_DECLARED 67225825Sdestypedef __va_list va_list; 68225825Sdes#define _VA_LIST_DECLARED 69225825Sdes#endif 70225825Sdes#endif 71225825Sdes 72180740Sdes#define _FSTDIO /* Define for new stdio with functions. */ 73225825Sdes 74225825Sdes/* 75180740Sdes * NB: to fit things in six character monocase externals, the stdio 76180740Sdes * code uses the prefix `__s' for stdio objects, typically followed 77225825Sdes * by a three-character attempt at a mnemonic. 78225825Sdes */ 79225825Sdes 80225825Sdes/* stdio buffers */ 81225825Sdesstruct __sbuf { 82225825Sdes unsigned char *_base; 83225825Sdes int _size; 84180740Sdes}; 85180740Sdes 86180740Sdes/* 87180740Sdes * stdio state variables. 88180740Sdes * 89180740Sdes * The following always hold: 90180740Sdes * 91180740Sdes * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), 92180740Sdes * _lbfsize is -_bf._size, else _lbfsize is 0 93180740Sdes * if _flags&__SRD, _w is 0 94180740Sdes * if _flags&__SWR, _r is 0 95225825Sdes * 96225825Sdes * This ensures that the getc and putc macros (or inline functions) never 97180740Sdes * try to write or read from a file that is in `read' or `write' mode. 98180740Sdes * (Moreover, they can, and do, automatically switch from read mode to 99180740Sdes * write mode, and back, on "r+" and "w+" files.) 100180740Sdes * 101180740Sdes * _lbfsize is used only to make the inline line-buffered output stream 102180740Sdes * code as compact as possible. 103225825Sdes * 104225825Sdes * _ub, _up, and _ur are used when ungetc() pushes back more characters 105180740Sdes * than fit in the current _bf, or when ungetc() pushes back a character 106180740Sdes * that does not match the previous one in _bf. When this happens, 107180740Sdes * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff 108180740Sdes * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. 109180740Sdes * 110180740Sdes * Certain members of __sFILE are accessed directly via macros or 111180740Sdes * inline functions. To preserve ABI compat, these members must not 112180740Sdes * be disturbed. These members are marked below with (*). 113180740Sdes */ 114180740Sdestypedef struct __sFILE { 115225825Sdes unsigned char *_p; /* (*) current position in (some) buffer */ 116225825Sdes int _r; /* (*) read space left for getc() */ 117180740Sdes int _w; /* (*) write space left for putc() */ 118180740Sdes short _flags; /* (*) flags, below; this FILE is free if 0 */ 119225825Sdes short _file; /* (*) fileno, if Unix descriptor, else -1 */ 120225825Sdes struct __sbuf _bf; /* (*) the buffer (at least 1 byte, if !NULL) */ 121225825Sdes int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */ 122225825Sdes 123225825Sdes /* operations */ 124225825Sdes void *_cookie; /* (*) cookie passed to io functions */ 125225825Sdes int (*_close)(void *); 126180740Sdes int (*_read)(void *, char *, int); 127180740Sdes fpos_t (*_seek)(void *, fpos_t, int); 128180740Sdes int (*_write)(void *, const char *, int); 129180740Sdes 130180740Sdes /* separate buffer for long sequences of ungetc() */ 131180740Sdes struct __sbuf _ub; /* ungetc buffer */ 132225825Sdes unsigned char *_up; /* saved _p when _p is doing ungetc data */ 133225825Sdes int _ur; /* saved _r when _r is counting ungetc data */ 134225825Sdes 135225825Sdes /* tricks to meet minimum requirements even when malloc() fails */ 136180740Sdes unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ 137180740Sdes unsigned char _nbuf[1]; /* guarantee a getc() buffer */ 138225825Sdes 139180740Sdes /* separate buffer for fgetln() when line crosses buffer boundary */ 140180740Sdes struct __sbuf _lb; /* buffer for fgetln() */ 141225825Sdes 142225825Sdes /* Unix stdio files get aligned to block boundaries on fseek() */ 143225825Sdes int _blksize; /* stat.st_blksize (may be != _bf._size) */ 144225825Sdes fpos_t _offset; /* current lseek offset */ 145225825Sdes 146225825Sdes struct pthread_mutex *_fl_mutex; /* used for MT-safety */ 147225825Sdes struct pthread *_fl_owner; /* current owner */ 148180740Sdes int _fl_count; /* recursive lock count */ 149225825Sdes int _orientation; /* orientation for fwide() */ 150225825Sdes __mbstate_t _mbstate; /* multibyte conversion state */ 151225825Sdes} FILE; 152225825Sdes 153225825Sdes#ifndef _STDSTREAM_DECLARED 154225825Sdes__BEGIN_DECLS 155180740Sdesextern FILE *__stdinp; 156225825Sdesextern FILE *__stdoutp; 157225825Sdesextern FILE *__stderrp; 158225825Sdes__END_DECLS 159225825Sdes#define _STDSTREAM_DECLARED 160225825Sdes#endif 161225825Sdes 162180740Sdes#define __SLBF 0x0001 /* line buffered */ 163180740Sdes#define __SNBF 0x0002 /* unbuffered */ 164225825Sdes#define __SRD 0x0004 /* OK to read */ 165225825Sdes#define __SWR 0x0008 /* OK to write */ 166225825Sdes /* RD and WR are never simultaneously asserted */ 167225825Sdes#define __SRW 0x0010 /* open for reading & writing */ 168225825Sdes#define __SEOF 0x0020 /* found EOF */ 169180740Sdes#define __SERR 0x0040 /* found error */ 170180740Sdes#define __SMBF 0x0080 /* _buf is from malloc */ 171225825Sdes#define __SAPP 0x0100 /* fdopen()ed in append mode */ 172180740Sdes#define __SSTR 0x0200 /* this is an sprintf/snprintf string */ 173225825Sdes#define __SOPT 0x0400 /* do fseek() optimization */ 174225825Sdes#define __SNPT 0x0800 /* do not do fseek() optimization */ 175225825Sdes#define __SOFF 0x1000 /* set iff _offset is in fact correct */ 176225825Sdes#define __SMOD 0x2000 /* true => fgetln modified _p text */ 177225825Sdes#define __SALC 0x4000 /* allocate string space dynamically */ 178225825Sdes#define __SIGN 0x8000 /* ignore this file in _fwalk */ 179225825Sdes 180225825Sdes/* 181180740Sdes * The following three definitions are for ANSI C, which took them 182225825Sdes * from System V, which brilliantly took internal interface macros and 183180740Sdes * made them official arguments to setvbuf(), without renaming them. 184225825Sdes * Hence, these ugly _IOxxx names are *supposed* to appear in user code. 185180740Sdes * 186180740Sdes * Although numbered as their counterparts above, the implementation 187225825Sdes * does not rely on this. 188225825Sdes */ 189180740Sdes#define _IOFBF 0 /* setvbuf should set fully buffered */ 190180740Sdes#define _IOLBF 1 /* setvbuf should set line buffered */ 191180740Sdes#define _IONBF 2 /* setvbuf should set unbuffered */ 192180740Sdes 193225825Sdes#define BUFSIZ 1024 /* size of buffer used by setbuf */ 194225825Sdes#define EOF (-1) 195180740Sdes 196180740Sdes/* 197225825Sdes * FOPEN_MAX is a minimum maximum, and is the number of streams that 198225825Sdes * stdio can provide without attempting to allocate further resources 199225825Sdes * (which could fail). Do not use this for anything. 200225825Sdes */ 201225825Sdes /* must be == _POSIX_STREAM_MAX <limits.h> */ 202225825Sdes#ifndef FOPEN_MAX 203225825Sdes#define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ 204225825Sdes#endif 205225825Sdes#define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ 206180740Sdes 207180740Sdes/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ 208225825Sdes#if __XSI_VISIBLE 209180740Sdes#define P_tmpdir "/var/tmp/" 210225825Sdes#endif 211225825Sdes#define L_tmpnam 1024 /* XXX must be == PATH_MAX */ 212225825Sdes#define TMP_MAX 308915776 213225825Sdes 214180740Sdes#ifndef SEEK_SET 215180740Sdes#define SEEK_SET 0 /* set file offset to offset */ 216180740Sdes#endif 217225825Sdes#ifndef SEEK_CUR 218225825Sdes#define SEEK_CUR 1 /* set file offset to current plus offset */ 219225825Sdes#endif 220225825Sdes#ifndef SEEK_END 221225825Sdes#define SEEK_END 2 /* set file offset to EOF plus offset */ 222225825Sdes#endif 223225825Sdes 224225825Sdes#define stdin __stdinp 225225825Sdes#define stdout __stdoutp 226225825Sdes#define stderr __stderrp 227225825Sdes 228225825Sdes__BEGIN_DECLS 229225825Sdes/* 230225825Sdes * Functions defined in ANSI C standard. 231225825Sdes */ 232225825Sdesvoid clearerr(FILE *); 233180740Sdesint fclose(FILE *); 234180740Sdesint feof(FILE *); 235225825Sdesint ferror(FILE *); 236225825Sdesint fflush(FILE *); 237225825Sdesint fgetc(FILE *); 238225825Sdesint fgetpos(FILE * __restrict, fpos_t * __restrict); 239225825Sdeschar *fgets(char * __restrict, int, FILE * __restrict); 240225825SdesFILE *fopen(const char * __restrict, const char * __restrict); 241225825Sdesint fprintf(FILE * __restrict, const char * __restrict, ...); 242225825Sdesint fputc(int, FILE *); 243225825Sdesint fputs(const char * __restrict, FILE * __restrict); 244225825Sdessize_t fread(void * __restrict, size_t, size_t, FILE * __restrict); 245225825SdesFILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict); 246225825Sdesint fscanf(FILE * __restrict, const char * __restrict, ...); 247225825Sdesint fseek(FILE *, long, int); 248225825Sdesint fsetpos(FILE *, const fpos_t *); 249180740Sdeslong ftell(FILE *); 250180740Sdessize_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); 251180740Sdesint getc(FILE *); 252225825Sdesint getchar(void); 253225825Sdeschar *gets(char *); 254225825Sdesvoid perror(const char *); 255225825Sdesint printf(const char * __restrict, ...); 256225825Sdesint putc(int, FILE *); 257180740Sdesint putchar(int); 258225825Sdesint puts(const char *); 259225825Sdesint remove(const char *); 260225825Sdesint rename(const char *, const char *); 261225825Sdesvoid rewind(FILE *); 262225825Sdesint scanf(const char * __restrict, ...); 263225825Sdesvoid setbuf(FILE * __restrict, char * __restrict); 264225825Sdesint setvbuf(FILE * __restrict, char * __restrict, int, size_t); 265225825Sdesint sprintf(char * __restrict, const char * __restrict, ...); 266225825Sdesint sscanf(const char * __restrict, const char * __restrict, ...); 267225825SdesFILE *tmpfile(void); 268225825Sdeschar *tmpnam(char *); 269180740Sdesint ungetc(int, FILE *); 270225825Sdesint vfprintf(FILE * __restrict, const char * __restrict, 271225825Sdes __va_list); 272225825Sdesint vprintf(const char * __restrict, __va_list); 273225825Sdesint vsprintf(char * __restrict, const char * __restrict, 274225825Sdes __va_list); 275225825Sdes 276225825Sdes#if __ISO_C_VISIBLE >= 1999 277180740Sdesint snprintf(char * __restrict, size_t, const char * __restrict, 278225825Sdes ...) __printflike(3, 4); 279225825Sdesint vfscanf(FILE * __restrict, const char * __restrict, __va_list) 280225825Sdes __scanflike(2, 0); 281225825Sdesint vscanf(const char * __restrict, __va_list) __scanflike(1, 0); 282225825Sdesint vsnprintf(char * __restrict, size_t, const char * __restrict, 283225825Sdes __va_list) __printflike(3, 0); 284225825Sdesint vsscanf(const char * __restrict, const char * __restrict, __va_list) 285225825Sdes __scanflike(2, 0); 286225825Sdes#endif 287180740Sdes 288225825Sdes/* 289225825Sdes * Functions defined in all versions of POSIX 1003.1. 290225825Sdes */ 291225825Sdes#if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506 292225825Sdes/* size for cuserid(3); UT_NAMESIZE + 1, see <utmp.h> */ 293180740Sdes#define L_cuserid 17 /* legacy */ 294225825Sdes#endif 295225825Sdes 296225825Sdes#if __POSIX_VISIBLE 297225825Sdes#define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */ 298225825Sdes 299225825Sdeschar *ctermid(char *); 300225825SdesFILE *fdopen(int, const char *); 301225825Sdesint fileno(FILE *); 302225825Sdes#endif /* __POSIX_VISIBLE */ 303225825Sdes 304225825Sdes#if __POSIX_VISIBLE >= 199209 305225825Sdesint pclose(FILE *); 306225825SdesFILE *popen(const char *, const char *); 307225825Sdes#endif 308225825Sdes 309225825Sdes#if __POSIX_VISIBLE >= 199506 310225825Sdesint ftrylockfile(FILE *); 311225825Sdesvoid flockfile(FILE *); 312225825Sdesvoid funlockfile(FILE *); 313225825Sdes 314225825Sdes/* 315225825Sdes * These are normally used through macros as defined below, but POSIX 316225825Sdes * requires functions as well. 317225825Sdes */ 318225825Sdesint getc_unlocked(FILE *); 319225825Sdesint getchar_unlocked(void); 320225825Sdesint putc_unlocked(int, FILE *); 321225825Sdesint putchar_unlocked(int); 322225825Sdes#endif 323225825Sdes#if __BSD_VISIBLE 324225825Sdesvoid clearerr_unlocked(FILE *); 325225825Sdesint feof_unlocked(FILE *); 326225825Sdesint ferror_unlocked(FILE *); 327225825Sdesint fileno_unlocked(FILE *); 328225825Sdes#endif 329225825Sdes 330225825Sdes#if __POSIX_VISIBLE >= 200112 331225825Sdesint fseeko(FILE *, __off_t, int); 332180740Sdes__off_t ftello(FILE *); 333180740Sdes#endif 334225825Sdes 335225825Sdes#if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 336225825Sdesint getw(FILE *); 337225825Sdesint putw(int, FILE *); 338225825Sdes#endif /* BSD or X/Open before issue 6 */ 339225825Sdes 340225825Sdes#if __XSI_VISIBLE 341225825Sdeschar *tempnam(const char *, const char *); 342225825Sdes#endif 343225825Sdes 344225825Sdes#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 345225825Sdesssize_t getdelim(char ** __restrict, size_t * __restrict, int, 346225825Sdes FILE * __restrict); 347225825Sdesint renameat(int, const char *, int, const char *); 348225825Sdesint vdprintf(int, const char * __restrict, __va_list); 349225825Sdes 350225825Sdes/* 351225825Sdes * Every programmer and his dog wrote functions called getline() and dprintf() 352180740Sdes * before POSIX.1-2008 came along and decided to usurp the names, so we 353225825Sdes * don't prototype them by default unless one of the following is true: 354225825Sdes * a) the app has requested them specifically by defining _WITH_GETLINE or 355225825Sdes * _WITH_DPRINTF, respectively 356225825Sdes * b) the app has requested a POSIX.1-2008 environment via _POSIX_C_SOURCE 357225825Sdes * c) the app defines a GNUism such as _BSD_SOURCE or _GNU_SOURCE 358225825Sdes */ 359225825Sdes#ifndef _WITH_GETLINE 360225825Sdes#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) 361225825Sdes#define _WITH_GETLINE 362225825Sdes#elif defined(_POSIX_C_SOURCE) 363225825Sdes#if _POSIX_C_SOURCE > 200809 364225825Sdes#define _WITH_GETLINE 365225825Sdes#endif 366225825Sdes#endif 367225825Sdes#endif 368225825Sdes 369180740Sdes#ifdef _WITH_GETLINE 370180740Sdesssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict); 371225825Sdes#endif 372225825Sdes 373225825Sdes#ifndef _WITH_DPRINTF 374225825Sdes#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) 375225825Sdes#define _WITH_DPRINTF 376225825Sdes#elif defined(_POSIX_C_SOURCE) 377225825Sdes#if _POSIX_C_SOURCE > 200809 378225825Sdes#define _WITH_DPRINTF 379225825Sdes#endif 380225825Sdes#endif 381225825Sdes#endif 382225825Sdes 383225825Sdes#ifdef _WITH_DPRINTF 384225825Sdesint dprintf(int, const char * __restrict, ...); 385225825Sdes#endif 386180740Sdes 387225825Sdes#endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 */ 388225825Sdes 389225825Sdes/* 390180740Sdes * Routines that are purely local. 391225825Sdes */ 392180740Sdes#if __BSD_VISIBLE 393180740Sdesint asprintf(char **, const char *, ...) __printflike(2, 3); 394225825Sdeschar *ctermid_r(char *); 395225825Sdesvoid fcloseall(void); 396180740Sdeschar *fgetln(FILE *, size_t *); 397225825Sdes__const char *fmtcheck(const char *, const char *) __format_arg(2); 398180740Sdesint fpurge(FILE *); 399180740Sdesvoid setbuffer(FILE *, char *, int); 400225825Sdesint setlinebuf(FILE *); 401225825Sdesint vasprintf(char **, const char *, __va_list) 402180740Sdes __printflike(2, 0); 403225825Sdes 404180740Sdes/* 405180740Sdes * The system error table contains messages for the first sys_nerr 406225825Sdes * positive errno values. Use strerror() or strerror_r() from <string.h> 407225825Sdes * instead. 408225825Sdes */ 409225825Sdesextern __const int sys_nerr; 410225825Sdesextern __const char *__const sys_errlist[]; 411225825Sdes 412225825Sdes/* 413225825Sdes * Stdio function-access interface. 414225825Sdes */ 415225825SdesFILE *funopen(const void *, 416225825Sdes int (*)(void *, char *, int), 417225825Sdes int (*)(void *, const char *, int), 418225825Sdes fpos_t (*)(void *, fpos_t, int), 419225825Sdes int (*)(void *)); 420225825Sdes#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) 421225825Sdes#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) 422225825Sdes 423225825Sdes/* 424180740Sdes * Portability hacks. See <sys/types.h>. 425225825Sdes */ 426225825Sdes#ifndef _FTRUNCATE_DECLARED 427225825Sdes#define _FTRUNCATE_DECLARED 428225825Sdesint ftruncate(int, __off_t); 429225825Sdes#endif 430225825Sdes#ifndef _LSEEK_DECLARED 431180740Sdes#define _LSEEK_DECLARED 432180740Sdes__off_t lseek(int, __off_t, int); 433225825Sdes#endif 434225825Sdes#ifndef _MMAP_DECLARED 435225825Sdes#define _MMAP_DECLARED 436225825Sdesvoid *mmap(void *, size_t, int, int, int, __off_t); 437225825Sdes#endif 438180740Sdes#ifndef _TRUNCATE_DECLARED 439180740Sdes#define _TRUNCATE_DECLARED 440180740Sdesint truncate(const char *, __off_t); 441180740Sdes#endif 442180740Sdes#endif /* __BSD_VISIBLE */ 443180740Sdes 444180740Sdes/* 445180740Sdes * Functions internal to the implementation. 446180740Sdes */ 447180740Sdesint __srget(FILE *); 448180740Sdesint __swbuf(int, FILE *); 449180740Sdes 450180740Sdes/* 451180740Sdes * The __sfoo macros are here so that we can 452180740Sdes * define function versions in the C library. 453180740Sdes */ 454225825Sdes#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) 455180740Sdes#if defined(__GNUC__) && defined(__STDC__) 456180740Sdesstatic __inline int __sputc(int _c, FILE *_p) { 457180740Sdes if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) 458180740Sdes return (*_p->_p++ = _c); 459180740Sdes else 460180740Sdes return (__swbuf(_c, _p)); 461180740Sdes} 462180740Sdes#else 463180740Sdes/* 464180740Sdes * This has been tuned to generate reasonable code on the vax using pcc. 465225825Sdes */ 466180740Sdes#define __sputc(c, p) \ 467225825Sdes (--(p)->_w < 0 ? \ 468180740Sdes (p)->_w >= (p)->_lbfsize ? \ 469225825Sdes (*(p)->_p = (c)), *(p)->_p != '\n' ? \ 470225825Sdes (int)*(p)->_p++ : \ 471225825Sdes __swbuf('\n', p) : \ 472180740Sdes __swbuf((int)(c), p) : \ 473180740Sdes (*(p)->_p = (c), (int)*(p)->_p++)) 474180740Sdes#endif 475180740Sdes 476204861Sdes#define __sfeof(p) (((p)->_flags & __SEOF) != 0) 477180740Sdes#define __sferror(p) (((p)->_flags & __SERR) != 0) 478180740Sdes#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) 479180740Sdes#define __sfileno(p) ((p)->_file) 480180740Sdes 481180740Sdesextern int __isthreaded; 482225825Sdes 483180740Sdes#define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p)) 484225825Sdes#define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p)) 485225825Sdes#define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p)) 486225825Sdes 487225825Sdes#if __POSIX_VISIBLE 488225825Sdes#define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p)) 489225825Sdes#endif 490225825Sdes 491225825Sdes#define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp)) 492225825Sdes#define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp)) 493225825Sdes 494225825Sdes#define getchar() getc(stdin) 495225825Sdes#define putchar(x) putc(x, stdout) 496180740Sdes 497225825Sdes#if __BSD_VISIBLE 498180740Sdes/* 499180740Sdes * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12 500180740Sdes * B.8.2.7 for the rationale behind the *_unlocked() macros. 501180740Sdes */ 502180740Sdes#define feof_unlocked(p) __sfeof(p) 503180740Sdes#define ferror_unlocked(p) __sferror(p) 504180740Sdes#define clearerr_unlocked(p) __sclearerr(p) 505225825Sdes#define fileno_unlocked(p) __sfileno(p) 506180740Sdes#endif 507180740Sdes#if __POSIX_VISIBLE >= 199506 508180740Sdes#define getc_unlocked(fp) __sgetc(fp) 509180740Sdes#define putc_unlocked(x, fp) __sputc(x, fp) 510180740Sdes 511180740Sdes#define getchar_unlocked() getc_unlocked(stdin) 512180740Sdes#define putchar_unlocked(x) putc_unlocked(x, stdout) 513180740Sdes#endif 514180740Sdes 515180740Sdes__END_DECLS 516180740Sdes#endif /* !_STDIO_H_ */ 517180740Sdes