stdio.h revision 210957
1254984Sjoel/*- 261981Sbrian * Copyright (c) 1990, 1993 361981Sbrian * The Regents of the University of California. All rights reserved. 461981Sbrian * 561981Sbrian * This code is derived from software contributed to Berkeley by 661981Sbrian * Chris Torek. 761981Sbrian * 861981Sbrian * Redistribution and use in source and binary forms, with or without 961981Sbrian * modification, are permitted provided that the following conditions 1061981Sbrian * are met: 1161981Sbrian * 1. Redistributions of source code must retain the above copyright 1261981Sbrian * notice, this list of conditions and the following disclaimer. 1361981Sbrian * 2. Redistributions in binary form must reproduce the above copyright 1461981Sbrian * notice, this list of conditions and the following disclaimer in the 1561981Sbrian * documentation and/or other materials provided with the distribution. 1661981Sbrian * 3. Neither the name of the University nor the names of its contributors 1761981Sbrian * may be used to endorse or promote products derived from this software 1861981Sbrian * without specific prior written permission. 1961981Sbrian * 2061981Sbrian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2161981Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2261981Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2361981Sbrian * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2461981Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2561981Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2661981Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2761981Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28280721Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2961981Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3079538Sru * SUCH DAMAGE. 3161981Sbrian * 3261981Sbrian * @(#)stdio.h 8.5 (Berkeley) 4/29/95 3375670Sru * $FreeBSD: head/include/stdio.h 210957 2010-08-06 19:35:40Z ed $ 3461981Sbrian */ 3561981Sbrian 3668962Sru#ifndef _STDIO_H_ 3789608Smpp#define _STDIO_H_ 3861981Sbrian 3961981Sbrian#include <sys/cdefs.h> 4061981Sbrian#include <sys/_null.h> 4161981Sbrian#include <sys/_types.h> 4261981Sbrian 4361981Sbriantypedef __off_t fpos_t; 4461981Sbrian 4561981Sbrian#ifndef _SIZE_T_DECLARED 4661981Sbriantypedef __size_t size_t; 47161707Sru#define _SIZE_T_DECLARED 4861981Sbrian#endif 49161707Sru 5061981Sbrian#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 5161981Sbrian#ifndef _OFF_T_DECLARED 5261981Sbrian#define _OFF_T_DECLARED 5365843Sbriantypedef __off_t off_t; 5465843Sbrian#endif 5565843Sbrian#ifndef _SSIZE_T_DECLARED 5661981Sbrian#define _SSIZE_T_DECLARED 5776120Sddtypedef __ssize_t ssize_t; 5876120Sdd#endif 5976120Sdd#endif 6065843Sbrian 6165843Sbrian#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE 6265843Sbrian#ifndef _VA_LIST_DECLARED 6365843Sbriantypedef __va_list va_list; 6465843Sbrian#define _VA_LIST_DECLARED 65161707Sru#endif 6676120Sdd#endif 6789608Smpp 6865843Sbrian#define _FSTDIO /* Define for new stdio with functions. */ 6965843Sbrian 7065843Sbrian/* 7172089Sasmodai * NB: to fit things in six character monocase externals, the stdio 7265843Sbrian * code uses the prefix `__s' for stdio objects, typically followed 7366084Sbrian * by a three-character attempt at a mnemonic. 7465843Sbrian */ 7565843Sbrian 7676120Sdd/* stdio buffers */ 7776120Sddstruct __sbuf { 7865843Sbrian unsigned char *_base; 7976120Sdd int _size; 8065843Sbrian}; 81161707Sru 82161707Sru/* 8365843Sbrian * stdio state variables. 84161707Sru * 8565843Sbrian * The following always hold: 8665843Sbrian * 8765843Sbrian * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), 88161707Sru * _lbfsize is -_bf._size, else _lbfsize is 0 89161707Sru * if _flags&__SRD, _w is 0 90161707Sru * if _flags&__SWR, _r is 0 9176120Sdd * 9276120Sdd * This ensures that the getc and putc macros (or inline functions) never 9365843Sbrian * try to write or read from a file that is in `read' or `write' mode. 9489608Smpp * (Moreover, they can, and do, automatically switch from read mode to 9565843Sbrian * write mode, and back, on "r+" and "w+" files.) 9665843Sbrian * 9765843Sbrian * _lbfsize is used only to make the inline line-buffered output stream 9865843Sbrian * code as compact as possible. 9965843Sbrian * 10065843Sbrian * _ub, _up, and _ur are used when ungetc() pushes back more characters 101161707Sru * than fit in the current _bf, or when ungetc() pushes back a character 10276120Sdd * that does not match the previous one in _bf. When this happens, 103161707Sru * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff 10465843Sbrian * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. 10565843Sbrian * 10665843Sbrian * Certain members of __sFILE are accessed directly via macros or 10765843Sbrian * inline functions. To preserve ABI compat, these members must not 10865843Sbrian * be disturbed. These members are marked below with (*). 109161707Sru */ 11076120Sddtypedef struct __sFILE { 111161707Sru unsigned char *_p; /* (*) current position in (some) buffer */ 11265843Sbrian int _r; /* (*) read space left for getc() */ 11365843Sbrian int _w; /* (*) write space left for putc() */ 11465843Sbrian short _flags; /* (*) flags, below; this FILE is free if 0 */ 11565843Sbrian short _file; /* (*) fileno, if Unix descriptor, else -1 */ 11665843Sbrian struct __sbuf _bf; /* (*) the buffer (at least 1 byte, if !NULL) */ 117161707Sru int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */ 11876120Sdd 119161707Sru /* operations */ 12065843Sbrian void *_cookie; /* (*) cookie passed to io functions */ 12165843Sbrian int (*_close)(void *); 12265843Sbrian int (*_read)(void *, char *, int); 123161707Sru fpos_t (*_seek)(void *, fpos_t, int); 12465843Sbrian int (*_write)(void *, const char *, int); 125161707Sru 12686956Sru /* separate buffer for long sequences of ungetc() */ 127161707Sru struct __sbuf _ub; /* ungetc buffer */ 128161707Sru unsigned char *_up; /* saved _p when _p is doing ungetc data */ 12965843Sbrian int _ur; /* saved _r when _r is counting ungetc data */ 130161707Sru 13165843Sbrian /* tricks to meet minimum requirements even when malloc() fails */ 13265843Sbrian unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ 13365843Sbrian unsigned char _nbuf[1]; /* guarantee a getc() buffer */ 13465843Sbrian 135147700Shmp /* separate buffer for fgetln() when line crosses buffer boundary */ 13661981Sbrian struct __sbuf _lb; /* buffer for fgetln() */ 13761981Sbrian 13861981Sbrian /* Unix stdio files get aligned to block boundaries on fseek() */ 13961981Sbrian int _blksize; /* stat.st_blksize (may be != _bf._size) */ 14061981Sbrian fpos_t _offset; /* current lseek offset */ 14176120Sdd 14276120Sdd struct pthread_mutex *_fl_mutex; /* used for MT-safety */ 14376120Sdd struct pthread *_fl_owner; /* current owner */ 144161707Sru int _fl_count; /* recursive lock count */ 14561981Sbrian int _orientation; /* orientation for fwide() */ 14676120Sdd __mbstate_t _mbstate; /* multibyte conversion state */ 14761981Sbrian} FILE; 14876120Sdd 14976120Sdd#ifndef _STDSTREAM_DECLARED 15076120Sdd__BEGIN_DECLS 15161981Sbrianextern FILE *__stdinp; 15276120Sddextern FILE *__stdoutp; 15376120Sddextern FILE *__stderrp; 15476120Sdd__END_DECLS 15576120Sdd#define _STDSTREAM_DECLARED 15661981Sbrian#endif 157161707Sru 15861981Sbrian#define __SLBF 0x0001 /* line buffered */ 159141851Sru#define __SNBF 0x0002 /* unbuffered */ 16076120Sdd#define __SRD 0x0004 /* OK to read */ 16176120Sdd#define __SWR 0x0008 /* OK to write */ 16276120Sdd /* RD and WR are never simultaneously asserted */ 163161707Sru#define __SRW 0x0010 /* open for reading & writing */ 16461981Sbrian#define __SEOF 0x0020 /* found EOF */ 16576120Sdd#define __SERR 0x0040 /* found error */ 16676120Sdd#define __SMBF 0x0080 /* _buf is from malloc */ 16776120Sdd#define __SAPP 0x0100 /* fdopen()ed in append mode */ 168161707Sru#define __SSTR 0x0200 /* this is an sprintf/snprintf string */ 16961981Sbrian#define __SOPT 0x0400 /* do fseek() optimization */ 17076120Sdd#define __SNPT 0x0800 /* do not do fseek() optimization */ 17176120Sdd#define __SOFF 0x1000 /* set iff _offset is in fact correct */ 17276120Sdd#define __SMOD 0x2000 /* true => fgetln modified _p text */ 17376120Sdd#define __SALC 0x4000 /* allocate string space dynamically */ 17461981Sbrian#define __SIGN 0x8000 /* ignore this file in _fwalk */ 175161707Sru 17676120Sdd/* 17776120Sdd * The following three definitions are for ANSI C, which took them 17876120Sdd * from System V, which brilliantly took internal interface macros and 17976120Sdd * made them official arguments to setvbuf(), without renaming them. 18061981Sbrian * Hence, these ugly _IOxxx names are *supposed* to appear in user code. 181141851Sru * 18276120Sdd * Although numbered as their counterparts above, the implementation 18376120Sdd * does not rely on this. 18476120Sdd */ 18576120Sdd#define _IOFBF 0 /* setvbuf should set fully buffered */ 18661981Sbrian#define _IOLBF 1 /* setvbuf should set line buffered */ 187161707Sru#define _IONBF 2 /* setvbuf should set unbuffered */ 18861981Sbrian 18976120Sdd#define BUFSIZ 1024 /* size of buffer used by setbuf */ 19076120Sdd#define EOF (-1) 19176120Sdd 192161707Sru/* 19361981Sbrian * FOPEN_MAX is a minimum maximum, and is the number of streams that 19476120Sdd * stdio can provide without attempting to allocate further resources 19576120Sdd * (which could fail). Do not use this for anything. 19676120Sdd */ 197161707Sru /* must be == _POSIX_STREAM_MAX <limits.h> */ 19861981Sbrian#ifndef FOPEN_MAX 19961981Sbrian#define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ 20076120Sdd#endif 20176120Sdd#define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ 20276120Sdd 20361981Sbrian/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ 20476120Sdd#if __XSI_VISIBLE 20576120Sdd#define P_tmpdir "/var/tmp/" 20676120Sdd#endif 207161707Sru#define L_tmpnam 1024 /* XXX must be == PATH_MAX */ 20861981Sbrian#define TMP_MAX 308915776 20976120Sdd 21076120Sdd#ifndef SEEK_SET 21176120Sdd#define SEEK_SET 0 /* set file offset to offset */ 212161707Sru#endif 21386956Sru#ifndef SEEK_CUR 21476120Sdd#define SEEK_CUR 1 /* set file offset to current plus offset */ 21576120Sdd#endif 21676120Sdd#ifndef SEEK_END 21761981Sbrian#define SEEK_END 2 /* set file offset to EOF plus offset */ 21861981Sbrian#endif 21961981Sbrian 22061981Sbrian#define stdin __stdinp 22176120Sdd#define stdout __stdoutp 22276120Sdd#define stderr __stderrp 22376120Sdd 224161707Sru__BEGIN_DECLS 22561981Sbrian/* 22661981Sbrian * Functions defined in ANSI C standard. 22761981Sbrian */ 22876120Sddvoid clearerr(FILE *); 22976120Sddint fclose(FILE *); 23076120Sddint feof(FILE *); 23161981Sbrianint ferror(FILE *); 23276120Sddint fflush(FILE *); 23376120Sddint fgetc(FILE *); 23476120Sddint fgetpos(FILE * __restrict, fpos_t * __restrict); 235161707Sruchar *fgets(char * __restrict, int, FILE * __restrict); 23661981SbrianFILE *fopen(const char * __restrict, const char * __restrict); 23776120Sddint fprintf(FILE * __restrict, const char * __restrict, ...); 23876120Sddint fputc(int, FILE *); 23976120Sddint fputs(const char * __restrict, FILE * __restrict); 240161707Srusize_t fread(void * __restrict, size_t, size_t, FILE * __restrict); 241108958SwollmanFILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict); 242111447Sruint fscanf(FILE * __restrict, const char * __restrict, ...); 243108958Swollmanint fseek(FILE *, long, int); 244108958Swollmanint fsetpos(FILE *, const fpos_t *); 245108958Swollmanlong ftell(FILE *); 246108958Swollmansize_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); 247111447Sruint getc(FILE *); 248108958Swollmanint getchar(void); 249108958Swollmanchar *gets(char *); 250108958Swollmanvoid perror(const char *); 25176120Sddint printf(const char * __restrict, ...); 25276120Sddint putc(int, FILE *); 25376120Sddint putchar(int); 254161707Sruint puts(const char *); 25561981Sbrianint remove(const char *); 25661981Sbrianint rename(const char *, const char *); 25761981Sbrianvoid rewind(FILE *); 25861981Sbrianint scanf(const char * __restrict, ...); 25961981Sbrianvoid setbuf(FILE * __restrict, char * __restrict); 26061981Sbrianint setvbuf(FILE * __restrict, char * __restrict, int, size_t); 26161981Sbrianint sprintf(char * __restrict, const char * __restrict, ...); 26261981Sbrianint sscanf(const char * __restrict, const char * __restrict, ...); 26361981SbrianFILE *tmpfile(void); 26461981Sbrianchar *tmpnam(char *); 26576120Sddint ungetc(int, FILE *); 26676120Sddint vfprintf(FILE * __restrict, const char * __restrict, 26776120Sdd __va_list); 268161707Sruint vprintf(const char * __restrict, __va_list); 26961981Sbrianint vsprintf(char * __restrict, const char * __restrict, 27064618Sgshapiro __va_list); 27161981Sbrian 27276120Sdd#if __ISO_C_VISIBLE >= 1999 27376120Sddint snprintf(char * __restrict, size_t, const char * __restrict, 27476120Sdd ...) __printflike(3, 4); 275161707Sruint vfscanf(FILE * __restrict, const char * __restrict, __va_list) 27661981Sbrian __scanflike(2, 0); 277111447Sruint vscanf(const char * __restrict, __va_list) __scanflike(1, 0); 27861981Sbrianint vsnprintf(char * __restrict, size_t, const char * __restrict, 27976120Sdd __va_list) __printflike(3, 0); 28076120Sddint vsscanf(const char * __restrict, const char * __restrict, __va_list) 28176120Sdd __scanflike(2, 0); 282161707Sru#endif 28361981Sbrian 28461981Sbrian/* 28576120Sdd * Functions defined in all versions of POSIX 1003.1. 28661981Sbrian */ 28761981Sbrian#if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506 28876120Sdd#define L_cuserid 17 /* size for cuserid(3); MAXLOGNAME, legacy */ 28976120Sdd#endif 29076120Sdd 291161707Sru#if __POSIX_VISIBLE 29262153Sbrian#define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */ 29362153Sbrian 29479219Sruchar *ctermid(char *); 29579219SruFILE *fdopen(int, const char *); 29677492Sbrianint fileno(FILE *); 29779219Sru#endif /* __POSIX_VISIBLE */ 29877492Sbrian 29977492Sbrian#if __POSIX_VISIBLE >= 199209 30077492Sbrianint pclose(FILE *); 301161707SruFILE *popen(const char *, const char *); 30279219Sru#endif 30377492Sbrian 30477492Sbrian#if __POSIX_VISIBLE >= 199506 30582139Sruint ftrylockfile(FILE *); 30677492Sbrianvoid flockfile(FILE *); 30777492Sbrianvoid funlockfile(FILE *); 30877492Sbrian 30979219Sru/* 31077492Sbrian * These are normally used through macros as defined below, but POSIX 311161707Sru * requires functions as well. 31277496Sbrian */ 31377496Sbrianint getc_unlocked(FILE *); 31489455Ssheldonhint getchar_unlocked(void); 31576120Sddint putc_unlocked(int, FILE *); 31676120Sddint putchar_unlocked(int); 317161707Sru#endif 31861981Sbrian#if __BSD_VISIBLE 31961981Sbrianvoid clearerr_unlocked(FILE *); 32076120Sddint feof_unlocked(FILE *); 32176120Sddint ferror_unlocked(FILE *); 32276120Sddint fileno_unlocked(FILE *); 323161707Sru#endif 32461981Sbrian 32562636Ssheldonh#if __POSIX_VISIBLE >= 200112 32681251Sruint fseeko(FILE *, __off_t, int); 32781251Sru__off_t ftello(FILE *); 32861981Sbrian#endif 329111447Sru 33076120Sdd#if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 33176120Sddint getw(FILE *); 33276120Sddint putw(int, FILE *); 33362636Ssheldonh#endif /* BSD or X/Open before issue 6 */ 33462636Ssheldonh 33576120Sdd#if __XSI_VISIBLE 33662636Ssheldonhchar *tempnam(const char *, const char *); 337161707Sru#endif 338279952Sjhb 339279952Sjhb#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 340231171Sgjbssize_t getdelim(char ** __restrict, size_t * __restrict, int, 341231171Sgjb FILE * __restrict); 342231171Sgjbint renameat(int, const char *, int, const char *); 343231171Sgjbint vdprintf(int, const char * __restrict, __va_list); 344231171Sgjb 345231171Sgjb/* 346231171Sgjb * Every programmer and his dog wrote functions called getline() and dprintf() 347231171Sgjb * before POSIX.1-2008 came along and decided to usurp the names, so we 348231171Sgjb * don't prototype them by default unless one of the following is true: 349231171Sgjb * a) the app has requested them specifically by defining _WITH_GETLINE or 350231171Sgjb * _WITH_DPRINTF, respectively 351231171Sgjb * b) the app has requested a POSIX.1-2008 environment via _POSIX_C_SOURCE 352231171Sgjb * c) the app defines a GNUism such as _BSD_SOURCE or _GNU_SOURCE 353231171Sgjb */ 354231171Sgjb#ifndef _WITH_GETLINE 355231171Sgjb#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) 356231171Sgjb#define _WITH_GETLINE 357231171Sgjb#elif defined(_POSIX_C_SOURCE) 358231171Sgjb#if _POSIX_C_SOURCE >= 200809 359231171Sgjb#define _WITH_GETLINE 360231171Sgjb#endif 361231171Sgjb#endif 362155130Sbrueffer#endif 363155130Sbrueffer 364155130Sbrueffer#ifdef _WITH_GETLINE 365161707Srussize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict); 366155130Sbrueffer#endif 367161707Sru 368155130Sbrueffer#ifndef _WITH_DPRINTF 369155130Sbrueffer#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) 370155130Sbrueffer#define _WITH_DPRINTF 371156217Sbrueffer#elif defined(_POSIX_C_SOURCE) 372156217Sbrueffer#if _POSIX_C_SOURCE >= 200809 373156217Sbrueffer#define _WITH_DPRINTF 374161707Sru#endif 375156217Sbrueffer#endif 376161707Sru#endif 377156217Sbrueffer 378156217Sbrueffer#ifdef _WITH_DPRINTF 379156217Sbruefferint (dprintf)(int, const char * __restrict, ...); 380156217Sbrueffer#endif 381156217Sbrueffer 382156217Sbrueffer#endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 */ 383161707Sru 384156217Sbrueffer/* 385161707Sru * Routines that are purely local. 386156217Sbrueffer */ 387156217Sbrueffer#if __BSD_VISIBLE 388156217Sbruefferint asprintf(char **, const char *, ...) __printflike(2, 3); 389156217Sbruefferchar *ctermid_r(char *); 390156217Sbrueffervoid fcloseall(void); 391156217Sbruefferchar *fgetln(FILE *, size_t *); 392161707Sruconst char *fmtcheck(const char *, const char *) __format_arg(2); 393156217Sbruefferint fpurge(FILE *); 394161707Sruvoid setbuffer(FILE *, char *, int); 395156217Sbruefferint setlinebuf(FILE *); 396156217Sbruefferint vasprintf(char **, const char *, __va_list) 397156217Sbrueffer __printflike(2, 0); 39876120Sdd 39976120Sdd/* 40076120Sdd * The system error table contains messages for the first sys_nerr 401161707Sru * positive errno values. Use strerror() or strerror_r() from <string.h> 40261981Sbrian * instead. 403111447Sru */ 404280721Sjhbextern __const int sys_nerr; 405280721Sjhbextern __const char *__const sys_errlist[]; 406280721Sjhb 407280721Sjhb/* 408280721Sjhb * Stdio function-access interface. 409280721Sjhb */ 410280721SjhbFILE *funopen(const void *, 411280721Sjhb int (*)(void *, char *, int), 412280721Sjhb int (*)(void *, const char *, int), 413280721Sjhb fpos_t (*)(void *, fpos_t, int), 41476120Sdd int (*)(void *)); 41576120Sdd#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) 41676120Sdd#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) 417161707Sru 41861981Sbrian/* 41961981Sbrian * Portability hacks. See <sys/types.h>. 42061981Sbrian */ 42161981Sbrian#ifndef _FTRUNCATE_DECLARED 42261981Sbrian#define _FTRUNCATE_DECLARED 42376120Sddint ftruncate(int, __off_t); 42476120Sdd#endif 42576120Sdd#ifndef _LSEEK_DECLARED 426161707Sru#define _LSEEK_DECLARED 42761981Sbrian__off_t lseek(int, __off_t, int); 42861981Sbrian#endif 42961981Sbrian#ifndef _MMAP_DECLARED 43061981Sbrian#define _MMAP_DECLARED 43179727Sschweikhvoid *mmap(void *, size_t, int, int, int, __off_t); 43276120Sdd#endif 43361981Sbrian#ifndef _TRUNCATE_DECLARED 434161707Sru#define _TRUNCATE_DECLARED 43561981Sbrianint truncate(const char *, __off_t); 43671895Sru#endif 43776120Sdd#endif /* __BSD_VISIBLE */ 43876120Sdd 43976120Sdd/* 440161707Sru * Functions internal to the implementation. 44161981Sbrian */ 44261981Sbrianint __srget(FILE *); 44376120Sddint __swbuf(int, FILE *); 44476120Sdd 44576120Sdd/* 446161707Sru * The __sfoo macros are here so that we can 44761981Sbrian * define function versions in the C library. 448111447Sru */ 44961981Sbrian#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) 45076120Sdd#if defined(__GNUC__) && defined(__STDC__) 45161981Sbrianstatic __inline int __sputc(int _c, FILE *_p) { 452161707Sru if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) 45394342Sgshapiro return (*_p->_p++ = _c); 45494342Sgshapiro else 45594342Sgshapiro return (__swbuf(_c, _p)); 456161707Sru} 45794342Sgshapiro#else 45894342Sgshapiro/* 45994342Sgshapiro * This has been tuned to generate reasonable code on the vax using pcc. 46094342Sgshapiro */ 46194342Sgshapiro#define __sputc(c, p) \ 462161707Sru (--(p)->_w < 0 ? \ 463110574Sgshapiro (p)->_w >= (p)->_lbfsize ? \ 464110574Sgshapiro (*(p)->_p = (c)), *(p)->_p != '\n' ? \ 46576120Sdd (int)*(p)->_p++ : \ 46676120Sdd __swbuf('\n', p) : \ 46776120Sdd __swbuf((int)(c), p) : \ 468161707Sru (*(p)->_p = (c), (int)*(p)->_p++)) 46987514Scjc#endif 47087514Scjc 47187514Scjc#define __sfeof(p) (((p)->_flags & __SEOF) != 0) 47287514Scjc#define __sferror(p) (((p)->_flags & __SERR) != 0) 47387514Scjc#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) 47487514Scjc#define __sfileno(p) ((p)->_file) 47587514Scjc 47687514Scjcextern int __isthreaded; 47787514Scjc 47887514Scjc#define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p)) 47987514Scjc#define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p)) 48076120Sdd#define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p)) 48176120Sdd 48276120Sdd#if __POSIX_VISIBLE 483161707Sru#define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p)) 48487514Scjc#endif 48571834Sbrian 48676120Sdd#define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp)) 48776120Sdd#define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp)) 48876120Sdd 48987514Scjc#define getchar() getc(stdin) 49076120Sdd#define putchar(x) putc(x, stdout) 49171834Sbrian 492161707Sru#if __BSD_VISIBLE 49371834Sbrian/* 49476120Sdd * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12 49571834Sbrian * B.8.2.7 for the rationale behind the *_unlocked() macros. 49671834Sbrian */ 497255170Sjlh#define feof_unlocked(p) __sfeof(p) 498255170Sjlh#define ferror_unlocked(p) __sferror(p) 499255170Sjlh#define clearerr_unlocked(p) __sclearerr(p) 500255170Sjlh#define fileno_unlocked(p) __sfileno(p) 501255170Sjlh#endif 502255170Sjlh#if __POSIX_VISIBLE >= 199506 503255170Sjlh#define getc_unlocked(fp) __sgetc(fp) 504255170Sjlh#define putc_unlocked(x, fp) __sputc(x, fp) 505255170Sjlh 506255170Sjlh#define getchar_unlocked() getc_unlocked(stdin) 507255170Sjlh#define putchar_unlocked(x) putc_unlocked(x, stdout) 508255170Sjlh#endif 509255170Sjlh 510255170Sjlh__END_DECLS 511255170Sjlh#endif /* !_STDIO_H_ */ 512255170Sjlh