159deaec5SRodney W. Grimes /*- 259deaec5SRodney W. Grimes * Copyright (c) 1990, 1993 359deaec5SRodney W. Grimes * The Regents of the University of California. All rights reserved. 459deaec5SRodney W. Grimes * 559deaec5SRodney W. Grimes * This code is derived from software contributed to Berkeley by 659deaec5SRodney W. Grimes * Chris Torek. 759deaec5SRodney W. Grimes * 859deaec5SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 959deaec5SRodney W. Grimes * modification, are permitted provided that the following conditions 1059deaec5SRodney W. Grimes * are met: 1159deaec5SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 1259deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 1359deaec5SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 1459deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 1559deaec5SRodney W. Grimes * documentation and/or other materials provided with the distribution. 1659deaec5SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 1759deaec5SRodney W. Grimes * must display the following acknowledgement: 1859deaec5SRodney W. Grimes * This product includes software developed by the University of 1959deaec5SRodney W. Grimes * California, Berkeley and its contributors. 2059deaec5SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 2159deaec5SRodney W. Grimes * may be used to endorse or promote products derived from this software 2259deaec5SRodney W. Grimes * without specific prior written permission. 2359deaec5SRodney W. Grimes * 2459deaec5SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2559deaec5SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2659deaec5SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2759deaec5SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2859deaec5SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2959deaec5SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3059deaec5SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3159deaec5SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3259deaec5SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3359deaec5SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3459deaec5SRodney W. Grimes * SUCH DAMAGE. 3559deaec5SRodney W. Grimes * 36161f948dSPeter Wemm * @(#)stdio.h 8.5 (Berkeley) 4/29/95 37a4add9a9SPeter Wemm * $FreeBSD$ 3859deaec5SRodney W. Grimes */ 3959deaec5SRodney W. Grimes 4059deaec5SRodney W. Grimes #ifndef _STDIO_H_ 4159deaec5SRodney W. Grimes #define _STDIO_H_ 4259deaec5SRodney W. Grimes 4359deaec5SRodney W. Grimes #include <sys/cdefs.h> 4412eb46c8SMarcel Moolenaar #include <sys/_null.h> 45abbd8902SMike Barcroft #include <sys/_types.h> 4615aa51b0SBruce Evans 475dfca833SMike Barcroft typedef __off_t fpos_t; 485dfca833SMike Barcroft 49abbd8902SMike Barcroft #ifndef _SIZE_T_DECLARED 50abbd8902SMike Barcroft typedef __size_t size_t; 51abbd8902SMike Barcroft #define _SIZE_T_DECLARED 5259deaec5SRodney W. Grimes #endif 5359deaec5SRodney W. Grimes 5469099ba2SDavid Schultz #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 5569099ba2SDavid Schultz #ifndef _OFF_T_DECLARED 5669099ba2SDavid Schultz #define _OFF_T_DECLARED 5769099ba2SDavid Schultz typedef __off_t off_t; 5869099ba2SDavid Schultz #endif 5969099ba2SDavid Schultz #ifndef _SSIZE_T_DECLARED 6069099ba2SDavid Schultz #define _SSIZE_T_DECLARED 6169099ba2SDavid Schultz typedef __ssize_t ssize_t; 6269099ba2SDavid Schultz #endif 6369099ba2SDavid Schultz #endif 6469099ba2SDavid Schultz 655dfca833SMike Barcroft #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE 665dfca833SMike Barcroft #ifndef _VA_LIST_DECLARED 675dfca833SMike Barcroft typedef __va_list va_list; 685dfca833SMike Barcroft #define _VA_LIST_DECLARED 695dfca833SMike Barcroft #endif 705dfca833SMike Barcroft #endif 715dfca833SMike Barcroft 7259deaec5SRodney W. Grimes #define _FSTDIO /* Define for new stdio with functions. */ 7359deaec5SRodney W. Grimes 7419e03ca8SJohn Baldwin /* 7519e03ca8SJohn Baldwin * NB: to fit things in six character monocase externals, the stdio 7619e03ca8SJohn Baldwin * code uses the prefix `__s' for stdio objects, typically followed 7719e03ca8SJohn Baldwin * by a three-character attempt at a mnemonic. 7819e03ca8SJohn Baldwin */ 7919e03ca8SJohn Baldwin 8019e03ca8SJohn Baldwin /* stdio buffers */ 8119e03ca8SJohn Baldwin struct __sbuf { 8219e03ca8SJohn Baldwin unsigned char *_base; 8319e03ca8SJohn Baldwin int _size; 8419e03ca8SJohn Baldwin }; 8519e03ca8SJohn Baldwin 8619e03ca8SJohn Baldwin /* 8719e03ca8SJohn Baldwin * stdio state variables. 8819e03ca8SJohn Baldwin * 8919e03ca8SJohn Baldwin * The following always hold: 9019e03ca8SJohn Baldwin * 9119e03ca8SJohn Baldwin * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), 9219e03ca8SJohn Baldwin * _lbfsize is -_bf._size, else _lbfsize is 0 9319e03ca8SJohn Baldwin * if _flags&__SRD, _w is 0 9419e03ca8SJohn Baldwin * if _flags&__SWR, _r is 0 9519e03ca8SJohn Baldwin * 9619e03ca8SJohn Baldwin * This ensures that the getc and putc macros (or inline functions) never 9719e03ca8SJohn Baldwin * try to write or read from a file that is in `read' or `write' mode. 9819e03ca8SJohn Baldwin * (Moreover, they can, and do, automatically switch from read mode to 9919e03ca8SJohn Baldwin * write mode, and back, on "r+" and "w+" files.) 10019e03ca8SJohn Baldwin * 10119e03ca8SJohn Baldwin * _lbfsize is used only to make the inline line-buffered output stream 10219e03ca8SJohn Baldwin * code as compact as possible. 10319e03ca8SJohn Baldwin * 10419e03ca8SJohn Baldwin * _ub, _up, and _ur are used when ungetc() pushes back more characters 10519e03ca8SJohn Baldwin * than fit in the current _bf, or when ungetc() pushes back a character 10619e03ca8SJohn Baldwin * that does not match the previous one in _bf. When this happens, 10719e03ca8SJohn Baldwin * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff 10819e03ca8SJohn Baldwin * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. 10919e03ca8SJohn Baldwin * 11019e03ca8SJohn Baldwin * Certain members of __sFILE are accessed directly via macros or 11119e03ca8SJohn Baldwin * inline functions. To preserve ABI compat, these members must not 11219e03ca8SJohn Baldwin * be disturbed. These members are marked below with (*). 11319e03ca8SJohn Baldwin */ 11419e03ca8SJohn Baldwin typedef struct __sFILE { 11519e03ca8SJohn Baldwin unsigned char *_p; /* (*) current position in (some) buffer */ 11619e03ca8SJohn Baldwin int _r; /* (*) read space left for getc() */ 11719e03ca8SJohn Baldwin int _w; /* (*) write space left for putc() */ 11819e03ca8SJohn Baldwin short _flags; /* (*) flags, below; this FILE is free if 0 */ 11919e03ca8SJohn Baldwin short _file; /* (*) fileno, if Unix descriptor, else -1 */ 12041a5b871SJohn Baldwin struct __sbuf _bf; /* (*) the buffer (at least 1 byte, if !NULL) */ 12119e03ca8SJohn Baldwin int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */ 12219e03ca8SJohn Baldwin 12319e03ca8SJohn Baldwin /* operations */ 124a1b482adSJohn Baldwin void *_cookie; /* (*) cookie passed to io functions */ 12519e03ca8SJohn Baldwin int (*_close)(void *); 12619e03ca8SJohn Baldwin int (*_read)(void *, char *, int); 12719e03ca8SJohn Baldwin fpos_t (*_seek)(void *, fpos_t, int); 12819e03ca8SJohn Baldwin int (*_write)(void *, const char *, int); 12919e03ca8SJohn Baldwin 13019e03ca8SJohn Baldwin /* separate buffer for long sequences of ungetc() */ 13119e03ca8SJohn Baldwin struct __sbuf _ub; /* ungetc buffer */ 13219e03ca8SJohn Baldwin unsigned char *_up; /* saved _p when _p is doing ungetc data */ 13319e03ca8SJohn Baldwin int _ur; /* saved _r when _r is counting ungetc data */ 13419e03ca8SJohn Baldwin 13519e03ca8SJohn Baldwin /* tricks to meet minimum requirements even when malloc() fails */ 13619e03ca8SJohn Baldwin unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ 13719e03ca8SJohn Baldwin unsigned char _nbuf[1]; /* guarantee a getc() buffer */ 13819e03ca8SJohn Baldwin 13919e03ca8SJohn Baldwin /* separate buffer for fgetln() when line crosses buffer boundary */ 14019e03ca8SJohn Baldwin struct __sbuf _lb; /* buffer for fgetln() */ 14119e03ca8SJohn Baldwin 14219e03ca8SJohn Baldwin /* Unix stdio files get aligned to block boundaries on fseek() */ 14319e03ca8SJohn Baldwin int _blksize; /* stat.st_blksize (may be != _bf._size) */ 14419e03ca8SJohn Baldwin fpos_t _offset; /* current lseek offset */ 14519e03ca8SJohn Baldwin 14619e03ca8SJohn Baldwin struct pthread_mutex *_fl_mutex; /* used for MT-safety */ 14719e03ca8SJohn Baldwin struct pthread *_fl_owner; /* current owner */ 14819e03ca8SJohn Baldwin int _fl_count; /* recursive lock count */ 14919e03ca8SJohn Baldwin int _orientation; /* orientation for fwide() */ 15019e03ca8SJohn Baldwin __mbstate_t _mbstate; /* multibyte conversion state */ 15119e03ca8SJohn Baldwin } FILE; 15259deaec5SRodney W. Grimes 15384bb9aaaSTim J. Robbins #ifndef _STDSTREAM_DECLARED 15459deaec5SRodney W. Grimes __BEGIN_DECLS 1552b618987SPeter Wemm extern FILE *__stdinp; 1562b618987SPeter Wemm extern FILE *__stdoutp; 1572b618987SPeter Wemm extern FILE *__stderrp; 15859deaec5SRodney W. Grimes __END_DECLS 15984bb9aaaSTim J. Robbins #define _STDSTREAM_DECLARED 16084bb9aaaSTim J. Robbins #endif 16159deaec5SRodney W. Grimes 16219e03ca8SJohn Baldwin #define __SLBF 0x0001 /* line buffered */ 16319e03ca8SJohn Baldwin #define __SNBF 0x0002 /* unbuffered */ 16419e03ca8SJohn Baldwin #define __SRD 0x0004 /* OK to read */ 16519e03ca8SJohn Baldwin #define __SWR 0x0008 /* OK to write */ 16619e03ca8SJohn Baldwin /* RD and WR are never simultaneously asserted */ 16719e03ca8SJohn Baldwin #define __SRW 0x0010 /* open for reading & writing */ 16819e03ca8SJohn Baldwin #define __SEOF 0x0020 /* found EOF */ 16919e03ca8SJohn Baldwin #define __SERR 0x0040 /* found error */ 17019e03ca8SJohn Baldwin #define __SMBF 0x0080 /* _buf is from malloc */ 17119e03ca8SJohn Baldwin #define __SAPP 0x0100 /* fdopen()ed in append mode */ 17219e03ca8SJohn Baldwin #define __SSTR 0x0200 /* this is an sprintf/snprintf string */ 17319e03ca8SJohn Baldwin #define __SOPT 0x0400 /* do fseek() optimization */ 17419e03ca8SJohn Baldwin #define __SNPT 0x0800 /* do not do fseek() optimization */ 17519e03ca8SJohn Baldwin #define __SOFF 0x1000 /* set iff _offset is in fact correct */ 17619e03ca8SJohn Baldwin #define __SMOD 0x2000 /* true => fgetln modified _p text */ 17719e03ca8SJohn Baldwin #define __SALC 0x4000 /* allocate string space dynamically */ 17819e03ca8SJohn Baldwin #define __SIGN 0x8000 /* ignore this file in _fwalk */ 17919e03ca8SJohn Baldwin 18059deaec5SRodney W. Grimes /* 18159deaec5SRodney W. Grimes * The following three definitions are for ANSI C, which took them 18259deaec5SRodney W. Grimes * from System V, which brilliantly took internal interface macros and 18359deaec5SRodney W. Grimes * made them official arguments to setvbuf(), without renaming them. 18459deaec5SRodney W. Grimes * Hence, these ugly _IOxxx names are *supposed* to appear in user code. 18519e03ca8SJohn Baldwin * 18619e03ca8SJohn Baldwin * Although numbered as their counterparts above, the implementation 18719e03ca8SJohn Baldwin * does not rely on this. 18859deaec5SRodney W. Grimes */ 18959deaec5SRodney W. Grimes #define _IOFBF 0 /* setvbuf should set fully buffered */ 19059deaec5SRodney W. Grimes #define _IOLBF 1 /* setvbuf should set line buffered */ 19159deaec5SRodney W. Grimes #define _IONBF 2 /* setvbuf should set unbuffered */ 19259deaec5SRodney W. Grimes 19359deaec5SRodney W. Grimes #define BUFSIZ 1024 /* size of buffer used by setbuf */ 19459deaec5SRodney W. Grimes #define EOF (-1) 19559deaec5SRodney W. Grimes 19659deaec5SRodney W. Grimes /* 19759deaec5SRodney W. Grimes * FOPEN_MAX is a minimum maximum, and is the number of streams that 19859deaec5SRodney W. Grimes * stdio can provide without attempting to allocate further resources 19959deaec5SRodney W. Grimes * (which could fail). Do not use this for anything. 20059deaec5SRodney W. Grimes */ 20159deaec5SRodney W. Grimes /* must be == _POSIX_STREAM_MAX <limits.h> */ 2022c2f4a60SJohn Birrell #ifndef FOPEN_MAX 20359deaec5SRodney W. Grimes #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ 2042c2f4a60SJohn Birrell #endif 20559deaec5SRodney W. Grimes #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ 20659deaec5SRodney W. Grimes 20759deaec5SRodney W. Grimes /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ 208702b2a72SGarrett Wollman #if __XSI_VISIBLE 20959deaec5SRodney W. Grimes #define P_tmpdir "/var/tmp/" 21059deaec5SRodney W. Grimes #endif 21159deaec5SRodney W. Grimes #define L_tmpnam 1024 /* XXX must be == PATH_MAX */ 21259deaec5SRodney W. Grimes #define TMP_MAX 308915776 21359deaec5SRodney W. Grimes 21459deaec5SRodney W. Grimes #ifndef SEEK_SET 21559deaec5SRodney W. Grimes #define SEEK_SET 0 /* set file offset to offset */ 21659deaec5SRodney W. Grimes #endif 21759deaec5SRodney W. Grimes #ifndef SEEK_CUR 21859deaec5SRodney W. Grimes #define SEEK_CUR 1 /* set file offset to current plus offset */ 21959deaec5SRodney W. Grimes #endif 22059deaec5SRodney W. Grimes #ifndef SEEK_END 22159deaec5SRodney W. Grimes #define SEEK_END 2 /* set file offset to EOF plus offset */ 22259deaec5SRodney W. Grimes #endif 22359deaec5SRodney W. Grimes 2242b618987SPeter Wemm #define stdin __stdinp 2252b618987SPeter Wemm #define stdout __stdoutp 2262b618987SPeter Wemm #define stderr __stderrp 22759deaec5SRodney W. Grimes 228702b2a72SGarrett Wollman __BEGIN_DECLS 22959deaec5SRodney W. Grimes /* 23059deaec5SRodney W. Grimes * Functions defined in ANSI C standard. 23159deaec5SRodney W. Grimes */ 232bb28f3c2SWarner Losh void clearerr(FILE *); 233bb28f3c2SWarner Losh int fclose(FILE *); 234bb28f3c2SWarner Losh int feof(FILE *); 235bb28f3c2SWarner Losh int ferror(FILE *); 236bb28f3c2SWarner Losh int fflush(FILE *); 237bb28f3c2SWarner Losh int fgetc(FILE *); 23854e4e385SMike Barcroft int fgetpos(FILE * __restrict, fpos_t * __restrict); 23954e4e385SMike Barcroft char *fgets(char * __restrict, int, FILE * __restrict); 24054e4e385SMike Barcroft FILE *fopen(const char * __restrict, const char * __restrict); 24171a00a44SRobert Drehmel int fprintf(FILE * __restrict, const char * __restrict, ...); 242bb28f3c2SWarner Losh int fputc(int, FILE *); 24354e4e385SMike Barcroft int fputs(const char * __restrict, FILE * __restrict); 24454e4e385SMike Barcroft size_t fread(void * __restrict, size_t, size_t, FILE * __restrict); 24554e4e385SMike Barcroft FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict); 24654e4e385SMike Barcroft int fscanf(FILE * __restrict, const char * __restrict, ...); 247bb28f3c2SWarner Losh int fseek(FILE *, long, int); 248bb28f3c2SWarner Losh int fsetpos(FILE *, const fpos_t *); 249bb28f3c2SWarner Losh long ftell(FILE *); 25054e4e385SMike Barcroft size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); 251bb28f3c2SWarner Losh int getc(FILE *); 252bb28f3c2SWarner Losh int getchar(void); 253bb28f3c2SWarner Losh char *gets(char *); 254bb28f3c2SWarner Losh void perror(const char *); 25571a00a44SRobert Drehmel int printf(const char * __restrict, ...); 256bb28f3c2SWarner Losh int putc(int, FILE *); 257bb28f3c2SWarner Losh int putchar(int); 258bb28f3c2SWarner Losh int puts(const char *); 259bb28f3c2SWarner Losh int remove(const char *); 260bb28f3c2SWarner Losh int rename(const char *, const char *); 261bb28f3c2SWarner Losh void rewind(FILE *); 26254e4e385SMike Barcroft int scanf(const char * __restrict, ...); 2633248d0a5SRobert Drehmel void setbuf(FILE * __restrict, char * __restrict); 2643248d0a5SRobert Drehmel int setvbuf(FILE * __restrict, char * __restrict, int, size_t); 26571a00a44SRobert Drehmel int sprintf(char * __restrict, const char * __restrict, ...); 26654e4e385SMike Barcroft int sscanf(const char * __restrict, const char * __restrict, ...); 267bb28f3c2SWarner Losh FILE *tmpfile(void); 268bb28f3c2SWarner Losh char *tmpnam(char *); 269bb28f3c2SWarner Losh int ungetc(int, FILE *); 270f8418db7SRobert Drehmel int vfprintf(FILE * __restrict, const char * __restrict, 271abbd8902SMike Barcroft __va_list); 272abbd8902SMike Barcroft int vprintf(const char * __restrict, __va_list); 273f8418db7SRobert Drehmel int vsprintf(char * __restrict, const char * __restrict, 274abbd8902SMike Barcroft __va_list); 275702b2a72SGarrett Wollman 276702b2a72SGarrett Wollman #if __ISO_C_VISIBLE >= 1999 277f8418db7SRobert Drehmel int snprintf(char * __restrict, size_t, const char * __restrict, 278f8418db7SRobert Drehmel ...) __printflike(3, 4); 279af1c9c0eSTim J. Robbins int vfscanf(FILE * __restrict, const char * __restrict, __va_list) 280af1c9c0eSTim J. Robbins __scanflike(2, 0); 28154e4e385SMike Barcroft int vscanf(const char * __restrict, __va_list) __scanflike(1, 0); 282f8418db7SRobert Drehmel int vsnprintf(char * __restrict, size_t, const char * __restrict, 283abbd8902SMike Barcroft __va_list) __printflike(3, 0); 28454e4e385SMike Barcroft int vsscanf(const char * __restrict, const char * __restrict, __va_list) 2855dfca833SMike Barcroft __scanflike(2, 0); 286702b2a72SGarrett Wollman #endif 28759deaec5SRodney W. Grimes 28859deaec5SRodney W. Grimes /* 289702b2a72SGarrett Wollman * Functions defined in all versions of POSIX 1003.1. 29059deaec5SRodney W. Grimes */ 2915dfca833SMike Barcroft #if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506 2928c372bd8SWolfram Schneider /* size for cuserid(3); UT_NAMESIZE + 1, see <utmp.h> */ 2935dfca833SMike Barcroft #define L_cuserid 17 /* legacy */ 2945dfca833SMike Barcroft #endif 2958c372bd8SWolfram Schneider 2965dfca833SMike Barcroft #if __POSIX_VISIBLE 2978c372bd8SWolfram Schneider #define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */ 29859deaec5SRodney W. Grimes 299bb28f3c2SWarner Losh char *ctermid(char *); 300bb28f3c2SWarner Losh FILE *fdopen(int, const char *); 301bb28f3c2SWarner Losh int fileno(FILE *); 302702b2a72SGarrett Wollman #endif /* __POSIX_VISIBLE */ 303702b2a72SGarrett Wollman 304702b2a72SGarrett Wollman #if __POSIX_VISIBLE >= 199209 305702b2a72SGarrett Wollman int pclose(FILE *); 306702b2a72SGarrett Wollman FILE *popen(const char *, const char *); 307702b2a72SGarrett Wollman #endif 308702b2a72SGarrett Wollman 309702b2a72SGarrett Wollman #if __POSIX_VISIBLE >= 199506 310bb28f3c2SWarner Losh int ftrylockfile(FILE *); 311bb28f3c2SWarner Losh void flockfile(FILE *); 312bb28f3c2SWarner Losh void funlockfile(FILE *); 313702b2a72SGarrett Wollman 314702b2a72SGarrett Wollman /* 31519e03ca8SJohn Baldwin * These are normally used through macros as defined below, but POSIX 31619e03ca8SJohn Baldwin * requires functions as well. 317702b2a72SGarrett Wollman */ 318702b2a72SGarrett Wollman int getc_unlocked(FILE *); 319702b2a72SGarrett Wollman int getchar_unlocked(void); 320702b2a72SGarrett Wollman int putc_unlocked(int, FILE *); 321702b2a72SGarrett Wollman int putchar_unlocked(int); 322702b2a72SGarrett Wollman #endif 323e8065dc4STim J. Robbins #if __BSD_VISIBLE 324e8065dc4STim J. Robbins void clearerr_unlocked(FILE *); 325e8065dc4STim J. Robbins int feof_unlocked(FILE *); 326e8065dc4STim J. Robbins int ferror_unlocked(FILE *); 327e8065dc4STim J. Robbins int fileno_unlocked(FILE *); 328e8065dc4STim J. Robbins #endif 329702b2a72SGarrett Wollman 330702b2a72SGarrett Wollman #if __POSIX_VISIBLE >= 200112 331abbd8902SMike Barcroft int fseeko(FILE *, __off_t, int); 332abbd8902SMike Barcroft __off_t ftello(FILE *); 333702b2a72SGarrett Wollman #endif 334702b2a72SGarrett Wollman 335702b2a72SGarrett Wollman #if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 336702b2a72SGarrett Wollman int getw(FILE *); 337702b2a72SGarrett Wollman int putw(int, FILE *); 338702b2a72SGarrett Wollman #endif /* BSD or X/Open before issue 6 */ 339702b2a72SGarrett Wollman 340702b2a72SGarrett Wollman #if __XSI_VISIBLE 341702b2a72SGarrett Wollman char *tempnam(const char *, const char *); 342702b2a72SGarrett Wollman #endif 343702b2a72SGarrett Wollman 34469099ba2SDavid Schultz #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 34569099ba2SDavid Schultz ssize_t getdelim(char ** __restrict, size_t * __restrict, int, 34669099ba2SDavid Schultz FILE * __restrict); 34738953375SDavid Schultz int renameat(int, const char *, int, const char *); 348ad760e6fSDavid Schultz int vdprintf(int, const char * __restrict, __va_list); 34969099ba2SDavid Schultz 35069099ba2SDavid Schultz /* 351ad760e6fSDavid Schultz * Every programmer and his dog wrote functions called getline() and dprintf() 352ad760e6fSDavid Schultz * before POSIX.1-2008 came along and decided to usurp the names, so we 353ad760e6fSDavid Schultz * don't prototype them by default unless one of the following is true: 354ad760e6fSDavid Schultz * a) the app has requested them specifically by defining _WITH_GETLINE or 355ad760e6fSDavid Schultz * _WITH_DPRINTF, respectively 35669099ba2SDavid Schultz * b) the app has requested a POSIX.1-2008 environment via _POSIX_C_SOURCE 35769099ba2SDavid Schultz * c) the app defines a GNUism such as _BSD_SOURCE or _GNU_SOURCE 35869099ba2SDavid Schultz */ 35969099ba2SDavid Schultz #ifndef _WITH_GETLINE 36069099ba2SDavid Schultz #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) 36169099ba2SDavid Schultz #define _WITH_GETLINE 36269099ba2SDavid Schultz #elif defined(_POSIX_C_SOURCE) 36344bf9512SDavid Schultz #if _POSIX_C_SOURCE >= 200809 36469099ba2SDavid Schultz #define _WITH_GETLINE 36569099ba2SDavid Schultz #endif 36669099ba2SDavid Schultz #endif 36769099ba2SDavid Schultz #endif 36869099ba2SDavid Schultz 36969099ba2SDavid Schultz #ifdef _WITH_GETLINE 37069099ba2SDavid Schultz ssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict); 37169099ba2SDavid Schultz #endif 37269099ba2SDavid Schultz 373ad760e6fSDavid Schultz #ifndef _WITH_DPRINTF 374ad760e6fSDavid Schultz #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) 375ad760e6fSDavid Schultz #define _WITH_DPRINTF 376ad760e6fSDavid Schultz #elif defined(_POSIX_C_SOURCE) 37744bf9512SDavid Schultz #if _POSIX_C_SOURCE >= 200809 378ad760e6fSDavid Schultz #define _WITH_DPRINTF 379ad760e6fSDavid Schultz #endif 380ad760e6fSDavid Schultz #endif 381ad760e6fSDavid Schultz #endif 382ad760e6fSDavid Schultz 383ad760e6fSDavid Schultz #ifdef _WITH_DPRINTF 384bccfb078SDavid Schultz int (dprintf)(int, const char * __restrict, ...); 385ad760e6fSDavid Schultz #endif 386ad760e6fSDavid Schultz 38769099ba2SDavid Schultz #endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 */ 38869099ba2SDavid Schultz 389702b2a72SGarrett Wollman /* 390702b2a72SGarrett Wollman * Routines that are purely local. 391702b2a72SGarrett Wollman */ 392702b2a72SGarrett Wollman #if __BSD_VISIBLE 393702b2a72SGarrett Wollman int asprintf(char **, const char *, ...) __printflike(2, 3); 394702b2a72SGarrett Wollman char *ctermid_r(char *); 39528c94ec4SDaniel Eischen void fcloseall(void); 396702b2a72SGarrett Wollman char *fgetln(FILE *, size_t *); 397efa952cdSXin LI const char *fmtcheck(const char *, const char *) __format_arg(2); 398702b2a72SGarrett Wollman int fpurge(FILE *); 399702b2a72SGarrett Wollman void setbuffer(FILE *, char *, int); 400702b2a72SGarrett Wollman int setlinebuf(FILE *); 401abbd8902SMike Barcroft int vasprintf(char **, const char *, __va_list) 402702b2a72SGarrett Wollman __printflike(2, 0); 403702b2a72SGarrett Wollman 404702b2a72SGarrett Wollman /* 405702b2a72SGarrett Wollman * The system error table contains messages for the first sys_nerr 406702b2a72SGarrett Wollman * positive errno values. Use strerror() or strerror_r() from <string.h> 407702b2a72SGarrett Wollman * instead. 408702b2a72SGarrett Wollman */ 409702b2a72SGarrett Wollman extern __const int sys_nerr; 410702b2a72SGarrett Wollman extern __const char *__const sys_errlist[]; 411702b2a72SGarrett Wollman 412702b2a72SGarrett Wollman /* 413702b2a72SGarrett Wollman * Stdio function-access interface. 414702b2a72SGarrett Wollman */ 415702b2a72SGarrett Wollman FILE *funopen(const void *, 416702b2a72SGarrett Wollman int (*)(void *, char *, int), 417702b2a72SGarrett Wollman int (*)(void *, const char *, int), 418702b2a72SGarrett Wollman fpos_t (*)(void *, fpos_t, int), 419702b2a72SGarrett Wollman int (*)(void *)); 420702b2a72SGarrett Wollman #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) 421702b2a72SGarrett Wollman #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) 42259deaec5SRodney W. Grimes 42359deaec5SRodney W. Grimes /* 42415aa51b0SBruce Evans * Portability hacks. See <sys/types.h>. 42515aa51b0SBruce Evans */ 42615aa51b0SBruce Evans #ifndef _FTRUNCATE_DECLARED 42715aa51b0SBruce Evans #define _FTRUNCATE_DECLARED 428abbd8902SMike Barcroft int ftruncate(int, __off_t); 42915aa51b0SBruce Evans #endif 43015aa51b0SBruce Evans #ifndef _LSEEK_DECLARED 43115aa51b0SBruce Evans #define _LSEEK_DECLARED 432abbd8902SMike Barcroft __off_t lseek(int, __off_t, int); 43315aa51b0SBruce Evans #endif 43415aa51b0SBruce Evans #ifndef _MMAP_DECLARED 43515aa51b0SBruce Evans #define _MMAP_DECLARED 436abbd8902SMike Barcroft void *mmap(void *, size_t, int, int, int, __off_t); 43715aa51b0SBruce Evans #endif 43815aa51b0SBruce Evans #ifndef _TRUNCATE_DECLARED 43915aa51b0SBruce Evans #define _TRUNCATE_DECLARED 440abbd8902SMike Barcroft int truncate(const char *, __off_t); 44115aa51b0SBruce Evans #endif 442702b2a72SGarrett Wollman #endif /* __BSD_VISIBLE */ 44359deaec5SRodney W. Grimes 44419e03ca8SJohn Baldwin /* 44519e03ca8SJohn Baldwin * Functions internal to the implementation. 44619e03ca8SJohn Baldwin */ 44719e03ca8SJohn Baldwin int __srget(FILE *); 44819e03ca8SJohn Baldwin int __swbuf(int, FILE *); 44919e03ca8SJohn Baldwin 45019e03ca8SJohn Baldwin /* 45119e03ca8SJohn Baldwin * The __sfoo macros are here so that we can 45219e03ca8SJohn Baldwin * define function versions in the C library. 45319e03ca8SJohn Baldwin */ 45419e03ca8SJohn Baldwin #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) 45519e03ca8SJohn Baldwin #if defined(__GNUC__) && defined(__STDC__) 45619e03ca8SJohn Baldwin static __inline int __sputc(int _c, FILE *_p) { 45719e03ca8SJohn Baldwin if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) 45819e03ca8SJohn Baldwin return (*_p->_p++ = _c); 45919e03ca8SJohn Baldwin else 46019e03ca8SJohn Baldwin return (__swbuf(_c, _p)); 46119e03ca8SJohn Baldwin } 46219e03ca8SJohn Baldwin #else 46319e03ca8SJohn Baldwin /* 46419e03ca8SJohn Baldwin * This has been tuned to generate reasonable code on the vax using pcc. 46519e03ca8SJohn Baldwin */ 46619e03ca8SJohn Baldwin #define __sputc(c, p) \ 46719e03ca8SJohn Baldwin (--(p)->_w < 0 ? \ 46819e03ca8SJohn Baldwin (p)->_w >= (p)->_lbfsize ? \ 46919e03ca8SJohn Baldwin (*(p)->_p = (c)), *(p)->_p != '\n' ? \ 47019e03ca8SJohn Baldwin (int)*(p)->_p++ : \ 47119e03ca8SJohn Baldwin __swbuf('\n', p) : \ 47219e03ca8SJohn Baldwin __swbuf((int)(c), p) : \ 47319e03ca8SJohn Baldwin (*(p)->_p = (c), (int)*(p)->_p++)) 47419e03ca8SJohn Baldwin #endif 47519e03ca8SJohn Baldwin 47619e03ca8SJohn Baldwin #define __sfeof(p) (((p)->_flags & __SEOF) != 0) 47719e03ca8SJohn Baldwin #define __sferror(p) (((p)->_flags & __SERR) != 0) 47819e03ca8SJohn Baldwin #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) 47919e03ca8SJohn Baldwin #define __sfileno(p) ((p)->_file) 48019e03ca8SJohn Baldwin 48119e03ca8SJohn Baldwin extern int __isthreaded; 48219e03ca8SJohn Baldwin 48319e03ca8SJohn Baldwin #define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p)) 48419e03ca8SJohn Baldwin #define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p)) 48519e03ca8SJohn Baldwin #define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p)) 48619e03ca8SJohn Baldwin 48719e03ca8SJohn Baldwin #if __POSIX_VISIBLE 48819e03ca8SJohn Baldwin #define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p)) 48919e03ca8SJohn Baldwin #endif 49019e03ca8SJohn Baldwin 49119e03ca8SJohn Baldwin #define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp)) 49219e03ca8SJohn Baldwin #define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp)) 49319e03ca8SJohn Baldwin 49419e03ca8SJohn Baldwin #define getchar() getc(stdin) 49519e03ca8SJohn Baldwin #define putchar(x) putc(x, stdout) 49619e03ca8SJohn Baldwin 49719e03ca8SJohn Baldwin #if __BSD_VISIBLE 49819e03ca8SJohn Baldwin /* 49919e03ca8SJohn Baldwin * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12 50019e03ca8SJohn Baldwin * B.8.2.7 for the rationale behind the *_unlocked() macros. 50119e03ca8SJohn Baldwin */ 50219e03ca8SJohn Baldwin #define feof_unlocked(p) __sfeof(p) 50319e03ca8SJohn Baldwin #define ferror_unlocked(p) __sferror(p) 50419e03ca8SJohn Baldwin #define clearerr_unlocked(p) __sclearerr(p) 50519e03ca8SJohn Baldwin #define fileno_unlocked(p) __sfileno(p) 50619e03ca8SJohn Baldwin #endif 50719e03ca8SJohn Baldwin #if __POSIX_VISIBLE >= 199506 50819e03ca8SJohn Baldwin #define getc_unlocked(fp) __sgetc(fp) 50919e03ca8SJohn Baldwin #define putc_unlocked(x, fp) __sputc(x, fp) 51019e03ca8SJohn Baldwin 51119e03ca8SJohn Baldwin #define getchar_unlocked() getc_unlocked(stdin) 51219e03ca8SJohn Baldwin #define putchar_unlocked(x) putc_unlocked(x, stdout) 51319e03ca8SJohn Baldwin #endif 51419e03ca8SJohn Baldwin 515702b2a72SGarrett Wollman __END_DECLS 51615aa51b0SBruce Evans #endif /* !_STDIO_H_ */ 517