stdio.h revision 306846
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. 16203964Simp * 3. Neither the name of the University nor the names of its contributors 171539Srgrimes * may be used to endorse or promote products derived from this software 181539Srgrimes * without specific prior written permission. 191539Srgrimes * 201539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231539Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301539Srgrimes * SUCH DAMAGE. 311539Srgrimes * 3223655Speter * @(#)stdio.h 8.5 (Berkeley) 4/29/95 3350473Speter * $FreeBSD: stable/10/include/stdio.h 306846 2016-10-08 14:10:45Z vangyzen $ 341539Srgrimes */ 351539Srgrimes 361539Srgrimes#ifndef _STDIO_H_ 371539Srgrimes#define _STDIO_H_ 381539Srgrimes 391539Srgrimes#include <sys/cdefs.h> 40123257Smarcel#include <sys/_null.h> 41102227Smike#include <sys/_types.h> 421539Srgrimes 43104585Smiketypedef __off_t fpos_t; 44104585Smike 45102227Smike#ifndef _SIZE_T_DECLARED 46102227Smiketypedef __size_t size_t; 47102227Smike#define _SIZE_T_DECLARED 481539Srgrimes#endif 491539Srgrimes 50189136Sdas#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 51189136Sdas#ifndef _OFF_T_DECLARED 52189136Sdas#define _OFF_T_DECLARED 53189136Sdastypedef __off_t off_t; 54189136Sdas#endif 55189136Sdas#ifndef _SSIZE_T_DECLARED 56189136Sdas#define _SSIZE_T_DECLARED 57189136Sdastypedef __ssize_t ssize_t; 58189136Sdas#endif 59189136Sdas#endif 60189136Sdas 61104585Smike#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE 62104585Smike#ifndef _VA_LIST_DECLARED 63104585Smiketypedef __va_list va_list; 64104585Smike#define _VA_LIST_DECLARED 65104585Smike#endif 66104585Smike#endif 67104585Smike 681539Srgrimes#define _FSTDIO /* Define for new stdio with functions. */ 691539Srgrimes 70178778Sjhb/* 71178778Sjhb * NB: to fit things in six character monocase externals, the stdio 72178778Sjhb * code uses the prefix `__s' for stdio objects, typically followed 73178778Sjhb * by a three-character attempt at a mnemonic. 74178778Sjhb */ 751539Srgrimes 76178778Sjhb/* stdio buffers */ 77178778Sjhbstruct __sbuf { 78178778Sjhb unsigned char *_base; 79178778Sjhb int _size; 80178778Sjhb}; 81178778Sjhb 82178778Sjhb/* 83178778Sjhb * stdio state variables. 84178778Sjhb * 85178778Sjhb * The following always hold: 86178778Sjhb * 87178778Sjhb * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), 88178778Sjhb * _lbfsize is -_bf._size, else _lbfsize is 0 89178778Sjhb * if _flags&__SRD, _w is 0 90178778Sjhb * if _flags&__SWR, _r is 0 91178778Sjhb * 92178778Sjhb * This ensures that the getc and putc macros (or inline functions) never 93178778Sjhb * try to write or read from a file that is in `read' or `write' mode. 94178778Sjhb * (Moreover, they can, and do, automatically switch from read mode to 95178778Sjhb * write mode, and back, on "r+" and "w+" files.) 96178778Sjhb * 97178778Sjhb * _lbfsize is used only to make the inline line-buffered output stream 98178778Sjhb * code as compact as possible. 99178778Sjhb * 100178778Sjhb * _ub, _up, and _ur are used when ungetc() pushes back more characters 101178778Sjhb * than fit in the current _bf, or when ungetc() pushes back a character 102178778Sjhb * that does not match the previous one in _bf. When this happens, 103178778Sjhb * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff 104178778Sjhb * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. 105178778Sjhb * 106178778Sjhb * Certain members of __sFILE are accessed directly via macros or 107178778Sjhb * inline functions. To preserve ABI compat, these members must not 108178778Sjhb * be disturbed. These members are marked below with (*). 109178778Sjhb */ 110227487Stheravenstruct __sFILE { 111178778Sjhb unsigned char *_p; /* (*) current position in (some) buffer */ 112178778Sjhb int _r; /* (*) read space left for getc() */ 113178778Sjhb int _w; /* (*) write space left for putc() */ 114178778Sjhb short _flags; /* (*) flags, below; this FILE is free if 0 */ 115178778Sjhb short _file; /* (*) fileno, if Unix descriptor, else -1 */ 116178829Sjhb struct __sbuf _bf; /* (*) the buffer (at least 1 byte, if !NULL) */ 117178778Sjhb int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */ 118178778Sjhb 119178778Sjhb /* operations */ 120178779Sjhb void *_cookie; /* (*) cookie passed to io functions */ 121178778Sjhb int (*_close)(void *); 122178778Sjhb int (*_read)(void *, char *, int); 123178778Sjhb fpos_t (*_seek)(void *, fpos_t, int); 124178778Sjhb int (*_write)(void *, const char *, int); 125178778Sjhb 126178778Sjhb /* separate buffer for long sequences of ungetc() */ 127178778Sjhb struct __sbuf _ub; /* ungetc buffer */ 128178778Sjhb unsigned char *_up; /* saved _p when _p is doing ungetc data */ 129178778Sjhb int _ur; /* saved _r when _r is counting ungetc data */ 130178778Sjhb 131178778Sjhb /* tricks to meet minimum requirements even when malloc() fails */ 132178778Sjhb unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ 133178778Sjhb unsigned char _nbuf[1]; /* guarantee a getc() buffer */ 134178778Sjhb 135178778Sjhb /* separate buffer for fgetln() when line crosses buffer boundary */ 136178778Sjhb struct __sbuf _lb; /* buffer for fgetln() */ 137178778Sjhb 138178778Sjhb /* Unix stdio files get aligned to block boundaries on fseek() */ 139178778Sjhb int _blksize; /* stat.st_blksize (may be != _bf._size) */ 140178778Sjhb fpos_t _offset; /* current lseek offset */ 141178778Sjhb 142178778Sjhb struct pthread_mutex *_fl_mutex; /* used for MT-safety */ 143178778Sjhb struct pthread *_fl_owner; /* current owner */ 144178778Sjhb int _fl_count; /* recursive lock count */ 145178778Sjhb int _orientation; /* orientation for fwide() */ 146178778Sjhb __mbstate_t _mbstate; /* multibyte conversion state */ 147290544Sache int _flags2; /* additional flags */ 148227487Stheraven}; 149227487Stheraven#ifndef _STDFILE_DECLARED 150227487Stheraven#define _STDFILE_DECLARED 151227487Stheraventypedef struct __sFILE FILE; 152227487Stheraven#endif 153129774Stjr#ifndef _STDSTREAM_DECLARED 1541539Srgrimes__BEGIN_DECLS 15581600Speterextern FILE *__stdinp; 15681600Speterextern FILE *__stdoutp; 15781600Speterextern FILE *__stderrp; 1581539Srgrimes__END_DECLS 159129774Stjr#define _STDSTREAM_DECLARED 160129774Stjr#endif 1611539Srgrimes 162178778Sjhb#define __SLBF 0x0001 /* line buffered */ 163178778Sjhb#define __SNBF 0x0002 /* unbuffered */ 164178778Sjhb#define __SRD 0x0004 /* OK to read */ 165178778Sjhb#define __SWR 0x0008 /* OK to write */ 166178778Sjhb /* RD and WR are never simultaneously asserted */ 167178778Sjhb#define __SRW 0x0010 /* open for reading & writing */ 168178778Sjhb#define __SEOF 0x0020 /* found EOF */ 169178778Sjhb#define __SERR 0x0040 /* found error */ 170281036Sbdrewery#define __SMBF 0x0080 /* _bf._base is from malloc */ 171178778Sjhb#define __SAPP 0x0100 /* fdopen()ed in append mode */ 172178778Sjhb#define __SSTR 0x0200 /* this is an sprintf/snprintf string */ 173178778Sjhb#define __SOPT 0x0400 /* do fseek() optimization */ 174178778Sjhb#define __SNPT 0x0800 /* do not do fseek() optimization */ 175178778Sjhb#define __SOFF 0x1000 /* set iff _offset is in fact correct */ 176178778Sjhb#define __SMOD 0x2000 /* true => fgetln modified _p text */ 177178778Sjhb#define __SALC 0x4000 /* allocate string space dynamically */ 178178778Sjhb#define __SIGN 0x8000 /* ignore this file in _fwalk */ 179178778Sjhb 180290544Sache#define __S2OAP 0x0001 /* O_APPEND mode is set */ 181290544Sache 1821539Srgrimes/* 1831539Srgrimes * The following three definitions are for ANSI C, which took them 1841539Srgrimes * from System V, which brilliantly took internal interface macros and 1851539Srgrimes * made them official arguments to setvbuf(), without renaming them. 1861539Srgrimes * Hence, these ugly _IOxxx names are *supposed* to appear in user code. 187178778Sjhb * 188178778Sjhb * Although numbered as their counterparts above, the implementation 189178778Sjhb * does not rely on this. 1901539Srgrimes */ 1911539Srgrimes#define _IOFBF 0 /* setvbuf should set fully buffered */ 1921539Srgrimes#define _IOLBF 1 /* setvbuf should set line buffered */ 1931539Srgrimes#define _IONBF 2 /* setvbuf should set unbuffered */ 1941539Srgrimes 1951539Srgrimes#define BUFSIZ 1024 /* size of buffer used by setbuf */ 1961539Srgrimes#define EOF (-1) 1971539Srgrimes 1981539Srgrimes/* 1991539Srgrimes * FOPEN_MAX is a minimum maximum, and is the number of streams that 2001539Srgrimes * stdio can provide without attempting to allocate further resources 2011539Srgrimes * (which could fail). Do not use this for anything. 2021539Srgrimes */ 2031539Srgrimes /* must be == _POSIX_STREAM_MAX <limits.h> */ 204177653Sjb#ifndef FOPEN_MAX 2051539Srgrimes#define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ 206177653Sjb#endif 2071539Srgrimes#define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ 2081539Srgrimes 2091539Srgrimes/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ 210100133Swollman#if __XSI_VISIBLE 211228924Sdelphij#define P_tmpdir "/tmp/" 2121539Srgrimes#endif 2131539Srgrimes#define L_tmpnam 1024 /* XXX must be == PATH_MAX */ 2141539Srgrimes#define TMP_MAX 308915776 2151539Srgrimes 2161539Srgrimes#ifndef SEEK_SET 2171539Srgrimes#define SEEK_SET 0 /* set file offset to offset */ 2181539Srgrimes#endif 2191539Srgrimes#ifndef SEEK_CUR 2201539Srgrimes#define SEEK_CUR 1 /* set file offset to current plus offset */ 2211539Srgrimes#endif 2221539Srgrimes#ifndef SEEK_END 2231539Srgrimes#define SEEK_END 2 /* set file offset to EOF plus offset */ 2241539Srgrimes#endif 2251539Srgrimes 22681600Speter#define stdin __stdinp 22781600Speter#define stdout __stdoutp 22881600Speter#define stderr __stderrp 2291539Srgrimes 230100133Swollman__BEGIN_DECLS 231233600Stheraven#ifdef _XLOCALE_H_ 232233600Stheraven#include <xlocale/_stdio.h> 233233600Stheraven#endif 2341539Srgrimes/* 2351539Srgrimes * Functions defined in ANSI C standard. 2361539Srgrimes */ 23793032Simpvoid clearerr(FILE *); 23893032Simpint fclose(FILE *); 23993032Simpint feof(FILE *); 24093032Simpint ferror(FILE *); 24193032Simpint fflush(FILE *); 24293032Simpint fgetc(FILE *); 243104989Smikeint fgetpos(FILE * __restrict, fpos_t * __restrict); 244104989Smikechar *fgets(char * __restrict, int, FILE * __restrict); 245104989SmikeFILE *fopen(const char * __restrict, const char * __restrict); 246103012Stjrint fprintf(FILE * __restrict, const char * __restrict, ...); 24793032Simpint fputc(int, FILE *); 248104989Smikeint fputs(const char * __restrict, FILE * __restrict); 249104989Smikesize_t fread(void * __restrict, size_t, size_t, FILE * __restrict); 250104989SmikeFILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict); 251104989Smikeint fscanf(FILE * __restrict, const char * __restrict, ...); 25293032Simpint fseek(FILE *, long, int); 25393032Simpint fsetpos(FILE *, const fpos_t *); 25493032Simplong ftell(FILE *); 255104989Smikesize_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); 25693032Simpint getc(FILE *); 25793032Simpint getchar(void); 25893032Simpchar *gets(char *); 25993032Simpvoid perror(const char *); 260103012Stjrint printf(const char * __restrict, ...); 26193032Simpint putc(int, FILE *); 26293032Simpint putchar(int); 26393032Simpint puts(const char *); 26493032Simpint remove(const char *); 26593032Simpint rename(const char *, const char *); 26693032Simpvoid rewind(FILE *); 267104989Smikeint scanf(const char * __restrict, ...); 268103012Stjrvoid setbuf(FILE * __restrict, char * __restrict); 269103012Stjrint setvbuf(FILE * __restrict, char * __restrict, int, size_t); 270103012Stjrint sprintf(char * __restrict, const char * __restrict, ...); 271104989Smikeint sscanf(const char * __restrict, const char * __restrict, ...); 27293032SimpFILE *tmpfile(void); 27393032Simpchar *tmpnam(char *); 27493032Simpint ungetc(int, FILE *); 275103012Stjrint vfprintf(FILE * __restrict, const char * __restrict, 276102227Smike __va_list); 277103012Stjrint vprintf(const char * __restrict, __va_list); 278103012Stjrint vsprintf(char * __restrict, const char * __restrict, 279102227Smike __va_list); 2801539Srgrimes 281100133Swollman#if __ISO_C_VISIBLE >= 1999 282103012Stjrint snprintf(char * __restrict, size_t, const char * __restrict, 283101914Srobert ...) __printflike(3, 4); 284105098Stjrint vfscanf(FILE * __restrict, const char * __restrict, __va_list) 285105098Stjr __scanflike(2, 0); 286104989Smikeint vscanf(const char * __restrict, __va_list) __scanflike(1, 0); 287103012Stjrint vsnprintf(char * __restrict, size_t, const char * __restrict, 288102227Smike __va_list) __printflike(3, 0); 289104989Smikeint vsscanf(const char * __restrict, const char * __restrict, __va_list) 290104585Smike __scanflike(2, 0); 291100133Swollman#endif 292100133Swollman 2931539Srgrimes/* 294100133Swollman * Functions defined in all versions of POSIX 1003.1. 2951539Srgrimes */ 296104585Smike#if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506 297210957Sed#define L_cuserid 17 /* size for cuserid(3); MAXLOGNAME, legacy */ 298104585Smike#endif 2991539Srgrimes 300104585Smike#if __POSIX_VISIBLE 30119211Swosch#define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */ 30219211Swosch 30393032Simpchar *ctermid(char *); 30493032SimpFILE *fdopen(int, const char *); 30593032Simpint fileno(FILE *); 306100133Swollman#endif /* __POSIX_VISIBLE */ 307100133Swollman 308100133Swollman#if __POSIX_VISIBLE >= 199209 309100133Swollmanint pclose(FILE *); 310100133SwollmanFILE *popen(const char *, const char *); 311100133Swollman#endif 312100133Swollman 313100133Swollman#if __POSIX_VISIBLE >= 199506 31493032Simpint ftrylockfile(FILE *); 31593032Simpvoid flockfile(FILE *); 31693032Simpvoid funlockfile(FILE *); 3171539Srgrimes 3181539Srgrimes/* 319178778Sjhb * These are normally used through macros as defined below, but POSIX 320178778Sjhb * requires functions as well. 32124897Sbde */ 322100133Swollmanint getc_unlocked(FILE *); 323100133Swollmanint getchar_unlocked(void); 324100133Swollmanint putc_unlocked(int, FILE *); 325100133Swollmanint putchar_unlocked(int); 32624897Sbde#endif 327109168Stjr#if __BSD_VISIBLE 328178722Sjhbvoid clearerr_unlocked(FILE *); 329178722Sjhbint feof_unlocked(FILE *); 330178722Sjhbint ferror_unlocked(FILE *); 331178722Sjhbint fileno_unlocked(FILE *); 332109168Stjr#endif 333100133Swollman 334100133Swollman#if __POSIX_VISIBLE >= 200112 335102227Smikeint fseeko(FILE *, __off_t, int); 336102227Smike__off_t ftello(FILE *); 33724897Sbde#endif 338100133Swollman 339100133Swollman#if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 340100133Swollmanint getw(FILE *); 341100133Swollmanint putw(int, FILE *); 342100133Swollman#endif /* BSD or X/Open before issue 6 */ 343100133Swollman 344100133Swollman#if __XSI_VISIBLE 345100133Swollmanchar *tempnam(const char *, const char *); 34624897Sbde#endif 34724897Sbde 348189136Sdas#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 349246120SgahrFILE *fmemopen(void * __restrict, size_t, const char * __restrict); 350189136Sdasssize_t getdelim(char ** __restrict, size_t * __restrict, int, 351189136Sdas FILE * __restrict); 352247411SjhbFILE *open_memstream(char **, size_t *); 353189355Sdasint renameat(int, const char *, int, const char *); 354306846Svangyzenint vdprintf(int, const char * __restrict, __va_list) __printflike(2, 0); 355189136Sdas 35624897Sbde/* 357189356Sdas * Every programmer and his dog wrote functions called getline() and dprintf() 358189356Sdas * before POSIX.1-2008 came along and decided to usurp the names, so we 359189356Sdas * don't prototype them by default unless one of the following is true: 360189356Sdas * a) the app has requested them specifically by defining _WITH_GETLINE or 361189356Sdas * _WITH_DPRINTF, respectively 362189136Sdas * b) the app has requested a POSIX.1-2008 environment via _POSIX_C_SOURCE 363189136Sdas * c) the app defines a GNUism such as _BSD_SOURCE or _GNU_SOURCE 364189136Sdas */ 365189136Sdas#ifndef _WITH_GETLINE 366189136Sdas#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) 367189136Sdas#define _WITH_GETLINE 368189136Sdas#elif defined(_POSIX_C_SOURCE) 369189818Sdas#if _POSIX_C_SOURCE >= 200809 370189136Sdas#define _WITH_GETLINE 371189136Sdas#endif 372189136Sdas#endif 373189136Sdas#endif 374189136Sdas 375189136Sdas#ifdef _WITH_GETLINE 376189136Sdasssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict); 377189136Sdas#endif 378189136Sdas 379189356Sdas#ifndef _WITH_DPRINTF 380189356Sdas#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) 381189356Sdas#define _WITH_DPRINTF 382189356Sdas#elif defined(_POSIX_C_SOURCE) 383189818Sdas#if _POSIX_C_SOURCE >= 200809 384189356Sdas#define _WITH_DPRINTF 385189356Sdas#endif 386189356Sdas#endif 387189356Sdas#endif 388189356Sdas 389189356Sdas#ifdef _WITH_DPRINTF 390306846Svangyzenint (dprintf)(int, const char * __restrict, ...) __printflike(2, 3); 391189356Sdas#endif 392189356Sdas 393189136Sdas#endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 */ 394189136Sdas 395189136Sdas/* 3961539Srgrimes * Routines that are purely local. 3971539Srgrimes */ 398100133Swollman#if __BSD_VISIBLE 39993032Simpint asprintf(char **, const char *, ...) __printflike(2, 3); 40093032Simpchar *ctermid_r(char *); 401178722Sjhbvoid fcloseall(void); 402291602Sngieint fdclose(FILE *, int *); 40393032Simpchar *fgetln(FILE *, size_t *); 404194801Sdelphijconst char *fmtcheck(const char *, const char *) __format_arg(2); 40593032Simpint fpurge(FILE *); 40693032Simpvoid setbuffer(FILE *, char *, int); 40793032Simpint setlinebuf(FILE *); 408102227Smikeint vasprintf(char **, const char *, __va_list) 40937614Sbde __printflike(2, 0); 4101539Srgrimes 4111539Srgrimes/* 412100133Swollman * The system error table contains messages for the first sys_nerr 413100133Swollman * positive errno values. Use strerror() or strerror_r() from <string.h> 414100133Swollman * instead. 415100133Swollman */ 416228468Sedextern const int sys_nerr; 417228468Sedextern const char * const sys_errlist[]; 418100133Swollman 419100133Swollman/* 4201539Srgrimes * Stdio function-access interface. 4211539Srgrimes */ 42293032SimpFILE *funopen(const void *, 42375818Sobrien int (*)(void *, char *, int), 42475818Sobrien int (*)(void *, const char *, int), 42575818Sobrien fpos_t (*)(void *, fpos_t, int), 42693032Simp int (*)(void *)); 4271539Srgrimes#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) 4281539Srgrimes#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) 4291539Srgrimes 4301539Srgrimes/* 431100133Swollman * Portability hacks. See <sys/types.h>. 432100133Swollman */ 433100133Swollman#ifndef _FTRUNCATE_DECLARED 434100133Swollman#define _FTRUNCATE_DECLARED 435102227Smikeint ftruncate(int, __off_t); 436100133Swollman#endif 437100133Swollman#ifndef _LSEEK_DECLARED 438100133Swollman#define _LSEEK_DECLARED 439102227Smike__off_t lseek(int, __off_t, int); 440100133Swollman#endif 441100133Swollman#ifndef _MMAP_DECLARED 442100133Swollman#define _MMAP_DECLARED 443102227Smikevoid *mmap(void *, size_t, int, int, int, __off_t); 444100133Swollman#endif 445100133Swollman#ifndef _TRUNCATE_DECLARED 446100133Swollman#define _TRUNCATE_DECLARED 447102227Smikeint truncate(const char *, __off_t); 448100133Swollman#endif 449100133Swollman#endif /* __BSD_VISIBLE */ 450100133Swollman 451178778Sjhb/* 452178778Sjhb * Functions internal to the implementation. 453178778Sjhb */ 454178778Sjhbint __srget(FILE *); 455178778Sjhbint __swbuf(int, FILE *); 456178778Sjhb 457178778Sjhb/* 458178778Sjhb * The __sfoo macros are here so that we can 459178778Sjhb * define function versions in the C library. 460178778Sjhb */ 461178778Sjhb#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) 462178778Sjhb#if defined(__GNUC__) && defined(__STDC__) 463178778Sjhbstatic __inline int __sputc(int _c, FILE *_p) { 464178778Sjhb if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) 465178778Sjhb return (*_p->_p++ = _c); 466178778Sjhb else 467178778Sjhb return (__swbuf(_c, _p)); 468178778Sjhb} 469178778Sjhb#else 470178778Sjhb/* 471178778Sjhb * This has been tuned to generate reasonable code on the vax using pcc. 472178778Sjhb */ 473178778Sjhb#define __sputc(c, p) \ 474178778Sjhb (--(p)->_w < 0 ? \ 475178778Sjhb (p)->_w >= (p)->_lbfsize ? \ 476178778Sjhb (*(p)->_p = (c)), *(p)->_p != '\n' ? \ 477178778Sjhb (int)*(p)->_p++ : \ 478178778Sjhb __swbuf('\n', p) : \ 479178778Sjhb __swbuf((int)(c), p) : \ 480178778Sjhb (*(p)->_p = (c), (int)*(p)->_p++)) 481178778Sjhb#endif 482228875Stheraven 483228875Stheravenextern int __isthreaded; 484228875Stheraven 485227487Stheraven#ifndef __cplusplus 486178778Sjhb 487178778Sjhb#define __sfeof(p) (((p)->_flags & __SEOF) != 0) 488178778Sjhb#define __sferror(p) (((p)->_flags & __SERR) != 0) 489178778Sjhb#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) 490178778Sjhb#define __sfileno(p) ((p)->_file) 491178778Sjhb 492178778Sjhb 493178778Sjhb#define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p)) 494178778Sjhb#define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p)) 495178778Sjhb#define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p)) 496178778Sjhb 497178778Sjhb#if __POSIX_VISIBLE 498178778Sjhb#define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p)) 499178778Sjhb#endif 500178778Sjhb 501178778Sjhb#define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp)) 502178778Sjhb#define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp)) 503178778Sjhb 504178778Sjhb#define getchar() getc(stdin) 505178778Sjhb#define putchar(x) putc(x, stdout) 506178778Sjhb 507178778Sjhb#if __BSD_VISIBLE 508178778Sjhb/* 509178778Sjhb * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12 510178778Sjhb * B.8.2.7 for the rationale behind the *_unlocked() macros. 511178778Sjhb */ 512178778Sjhb#define feof_unlocked(p) __sfeof(p) 513178778Sjhb#define ferror_unlocked(p) __sferror(p) 514178778Sjhb#define clearerr_unlocked(p) __sclearerr(p) 515178778Sjhb#define fileno_unlocked(p) __sfileno(p) 516178778Sjhb#endif 517178778Sjhb#if __POSIX_VISIBLE >= 199506 518178778Sjhb#define getc_unlocked(fp) __sgetc(fp) 519178778Sjhb#define putc_unlocked(x, fp) __sputc(x, fp) 520178778Sjhb 521178778Sjhb#define getchar_unlocked() getc_unlocked(stdin) 522178778Sjhb#define putchar_unlocked(x) putc_unlocked(x, stdout) 523178778Sjhb#endif 524227487Stheraven#endif /* __cplusplus */ 525178778Sjhb 526100133Swollman__END_DECLS 52724897Sbde#endif /* !_STDIO_H_ */ 528