159deaec5SRodney W. Grimes /*- 22321c474SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 32321c474SPedro F. Giffuni * 459deaec5SRodney W. Grimes * Copyright (c) 1990, 1993 559deaec5SRodney W. Grimes * The Regents of the University of California. All rights reserved. 659deaec5SRodney W. Grimes * 759deaec5SRodney W. Grimes * This code is derived from software contributed to Berkeley by 859deaec5SRodney W. Grimes * Chris Torek. 959deaec5SRodney W. Grimes * 1059deaec5SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 1159deaec5SRodney W. Grimes * modification, are permitted provided that the following conditions 1259deaec5SRodney W. Grimes * are met: 1359deaec5SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 1459deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 1559deaec5SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 1659deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 1759deaec5SRodney W. Grimes * documentation and/or other materials provided with the distribution. 18f2556687SWarner Losh * 3. Neither the name of the University nor the names of its contributors 1959deaec5SRodney W. Grimes * may be used to endorse or promote products derived from this software 2059deaec5SRodney W. Grimes * without specific prior written permission. 2159deaec5SRodney W. Grimes * 2259deaec5SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2359deaec5SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2459deaec5SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2559deaec5SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2659deaec5SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2759deaec5SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2859deaec5SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2959deaec5SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3059deaec5SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3159deaec5SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3259deaec5SRodney W. Grimes * SUCH DAMAGE. 3359deaec5SRodney W. Grimes */ 3459deaec5SRodney W. Grimes 3559deaec5SRodney W. Grimes #ifndef _STDIO_H_ 3659deaec5SRodney W. Grimes #define _STDIO_H_ 3759deaec5SRodney W. Grimes 3859deaec5SRodney W. Grimes #include <sys/cdefs.h> 3912eb46c8SMarcel Moolenaar #include <sys/_null.h> 40abbd8902SMike Barcroft #include <sys/_types.h> 4115aa51b0SBruce Evans 42649702c5SPedro F. Giffuni __NULLABILITY_PRAGMA_PUSH 43649702c5SPedro F. Giffuni 445dfca833SMike Barcroft typedef __off_t fpos_t; 455dfca833SMike Barcroft 46abbd8902SMike Barcroft #ifndef _SIZE_T_DECLARED 47abbd8902SMike Barcroft typedef __size_t size_t; 48abbd8902SMike Barcroft #define _SIZE_T_DECLARED 4959deaec5SRodney W. Grimes #endif 5059deaec5SRodney W. Grimes 51*eb84c129SGraham Percival #if __EXT1_VISIBLE 52*eb84c129SGraham Percival /* ISO/IEC 9899:2011 K.3.3.2 */ 53c13559d3SCy Schubert #ifndef _RSIZE_T_DEFINED 54c13559d3SCy Schubert #define _RSIZE_T_DEFINED 55c13559d3SCy Schubert typedef size_t rsize_t; 56c13559d3SCy Schubert #endif 57*eb84c129SGraham Percival #endif /* __EXT1_VISIBLE */ 58c13559d3SCy Schubert 59448f5f73SJilles Tjoelker #if __POSIX_VISIBLE >= 200809 6069099ba2SDavid Schultz #ifndef _OFF_T_DECLARED 6169099ba2SDavid Schultz #define _OFF_T_DECLARED 6269099ba2SDavid Schultz typedef __off_t off_t; 6369099ba2SDavid Schultz #endif 6469099ba2SDavid Schultz #ifndef _SSIZE_T_DECLARED 6569099ba2SDavid Schultz #define _SSIZE_T_DECLARED 6669099ba2SDavid Schultz typedef __ssize_t ssize_t; 6769099ba2SDavid Schultz #endif 6869099ba2SDavid Schultz #endif 6969099ba2SDavid Schultz 70877a840cSConrad Meyer #ifndef _OFF64_T_DECLARED 71877a840cSConrad Meyer #define _OFF64_T_DECLARED 726710d21dSConrad Meyer typedef __off64_t off64_t; 73877a840cSConrad Meyer #endif 74877a840cSConrad Meyer 75448f5f73SJilles Tjoelker #if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE 765dfca833SMike Barcroft #ifndef _VA_LIST_DECLARED 775dfca833SMike Barcroft typedef __va_list va_list; 785dfca833SMike Barcroft #define _VA_LIST_DECLARED 795dfca833SMike Barcroft #endif 805dfca833SMike Barcroft #endif 815dfca833SMike Barcroft 8259deaec5SRodney W. Grimes #define _FSTDIO /* Define for new stdio with functions. */ 8359deaec5SRodney W. Grimes 8419e03ca8SJohn Baldwin /* 8519e03ca8SJohn Baldwin * NB: to fit things in six character monocase externals, the stdio 8619e03ca8SJohn Baldwin * code uses the prefix `__s' for stdio objects, typically followed 8719e03ca8SJohn Baldwin * by a three-character attempt at a mnemonic. 8819e03ca8SJohn Baldwin */ 8919e03ca8SJohn Baldwin 9019e03ca8SJohn Baldwin /* stdio buffers */ 9119e03ca8SJohn Baldwin struct __sbuf { 9219e03ca8SJohn Baldwin unsigned char *_base; 9319e03ca8SJohn Baldwin int _size; 9419e03ca8SJohn Baldwin }; 9519e03ca8SJohn Baldwin 9619e03ca8SJohn Baldwin /* 9719e03ca8SJohn Baldwin * stdio state variables. 9819e03ca8SJohn Baldwin * 9919e03ca8SJohn Baldwin * The following always hold: 10019e03ca8SJohn Baldwin * 10119e03ca8SJohn Baldwin * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), 10219e03ca8SJohn Baldwin * _lbfsize is -_bf._size, else _lbfsize is 0 10319e03ca8SJohn Baldwin * if _flags&__SRD, _w is 0 10419e03ca8SJohn Baldwin * if _flags&__SWR, _r is 0 10519e03ca8SJohn Baldwin * 10619e03ca8SJohn Baldwin * This ensures that the getc and putc macros (or inline functions) never 10719e03ca8SJohn Baldwin * try to write or read from a file that is in `read' or `write' mode. 10819e03ca8SJohn Baldwin * (Moreover, they can, and do, automatically switch from read mode to 10919e03ca8SJohn Baldwin * write mode, and back, on "r+" and "w+" files.) 11019e03ca8SJohn Baldwin * 11119e03ca8SJohn Baldwin * _lbfsize is used only to make the inline line-buffered output stream 11219e03ca8SJohn Baldwin * code as compact as possible. 11319e03ca8SJohn Baldwin * 11419e03ca8SJohn Baldwin * _ub, _up, and _ur are used when ungetc() pushes back more characters 11519e03ca8SJohn Baldwin * than fit in the current _bf, or when ungetc() pushes back a character 11619e03ca8SJohn Baldwin * that does not match the previous one in _bf. When this happens, 11719e03ca8SJohn Baldwin * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff 11819e03ca8SJohn Baldwin * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. 11919e03ca8SJohn Baldwin * 12019e03ca8SJohn Baldwin * Certain members of __sFILE are accessed directly via macros or 12119e03ca8SJohn Baldwin * inline functions. To preserve ABI compat, these members must not 12219e03ca8SJohn Baldwin * be disturbed. These members are marked below with (*). 12319e03ca8SJohn Baldwin */ 124c9e7ce2fSDavid Chisnall struct __sFILE { 12519e03ca8SJohn Baldwin unsigned char *_p; /* (*) current position in (some) buffer */ 12619e03ca8SJohn Baldwin int _r; /* (*) read space left for getc() */ 12719e03ca8SJohn Baldwin int _w; /* (*) write space left for putc() */ 12819e03ca8SJohn Baldwin short _flags; /* (*) flags, below; this FILE is free if 0 */ 12919e03ca8SJohn Baldwin short _file; /* (*) fileno, if Unix descriptor, else -1 */ 13041a5b871SJohn Baldwin struct __sbuf _bf; /* (*) the buffer (at least 1 byte, if !NULL) */ 13119e03ca8SJohn Baldwin int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */ 13219e03ca8SJohn Baldwin 13319e03ca8SJohn Baldwin /* operations */ 134a1b482adSJohn Baldwin void *_cookie; /* (*) cookie passed to io functions */ 135649702c5SPedro F. Giffuni int (* _Nullable _close)(void *); 136649702c5SPedro F. Giffuni int (* _Nullable _read)(void *, char *, int); 137649702c5SPedro F. Giffuni fpos_t (* _Nullable _seek)(void *, fpos_t, int); 138649702c5SPedro F. Giffuni int (* _Nullable _write)(void *, const char *, int); 13919e03ca8SJohn Baldwin 14019e03ca8SJohn Baldwin /* separate buffer for long sequences of ungetc() */ 14119e03ca8SJohn Baldwin struct __sbuf _ub; /* ungetc buffer */ 14219e03ca8SJohn Baldwin unsigned char *_up; /* saved _p when _p is doing ungetc data */ 14319e03ca8SJohn Baldwin int _ur; /* saved _r when _r is counting ungetc data */ 14419e03ca8SJohn Baldwin 14519e03ca8SJohn Baldwin /* tricks to meet minimum requirements even when malloc() fails */ 14619e03ca8SJohn Baldwin unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ 14719e03ca8SJohn Baldwin unsigned char _nbuf[1]; /* guarantee a getc() buffer */ 14819e03ca8SJohn Baldwin 14919e03ca8SJohn Baldwin /* separate buffer for fgetln() when line crosses buffer boundary */ 15019e03ca8SJohn Baldwin struct __sbuf _lb; /* buffer for fgetln() */ 15119e03ca8SJohn Baldwin 15219e03ca8SJohn Baldwin /* Unix stdio files get aligned to block boundaries on fseek() */ 15319e03ca8SJohn Baldwin int _blksize; /* stat.st_blksize (may be != _bf._size) */ 15419e03ca8SJohn Baldwin fpos_t _offset; /* current lseek offset */ 15519e03ca8SJohn Baldwin 15619e03ca8SJohn Baldwin struct pthread_mutex *_fl_mutex; /* used for MT-safety */ 15719e03ca8SJohn Baldwin struct pthread *_fl_owner; /* current owner */ 15819e03ca8SJohn Baldwin int _fl_count; /* recursive lock count */ 15919e03ca8SJohn Baldwin int _orientation; /* orientation for fwide() */ 16019e03ca8SJohn Baldwin __mbstate_t _mbstate; /* multibyte conversion state */ 1618b63538dSAndrey A. Chernov int _flags2; /* additional flags */ 162c9e7ce2fSDavid Chisnall }; 163c9e7ce2fSDavid Chisnall #ifndef _STDFILE_DECLARED 164c9e7ce2fSDavid Chisnall #define _STDFILE_DECLARED 165c9e7ce2fSDavid Chisnall typedef struct __sFILE FILE; 166c9e7ce2fSDavid Chisnall #endif 16784bb9aaaSTim J. Robbins #ifndef _STDSTREAM_DECLARED 16859deaec5SRodney W. Grimes __BEGIN_DECLS 1692b618987SPeter Wemm extern FILE *__stdinp; 1702b618987SPeter Wemm extern FILE *__stdoutp; 1712b618987SPeter Wemm extern FILE *__stderrp; 17259deaec5SRodney W. Grimes __END_DECLS 17384bb9aaaSTim J. Robbins #define _STDSTREAM_DECLARED 17484bb9aaaSTim J. Robbins #endif 17559deaec5SRodney W. Grimes 17619e03ca8SJohn Baldwin #define __SLBF 0x0001 /* line buffered */ 17719e03ca8SJohn Baldwin #define __SNBF 0x0002 /* unbuffered */ 17819e03ca8SJohn Baldwin #define __SRD 0x0004 /* OK to read */ 17919e03ca8SJohn Baldwin #define __SWR 0x0008 /* OK to write */ 18019e03ca8SJohn Baldwin /* RD and WR are never simultaneously asserted */ 18119e03ca8SJohn Baldwin #define __SRW 0x0010 /* open for reading & writing */ 18219e03ca8SJohn Baldwin #define __SEOF 0x0020 /* found EOF */ 18319e03ca8SJohn Baldwin #define __SERR 0x0040 /* found error */ 184addf3409SBryan Drewery #define __SMBF 0x0080 /* _bf._base is from malloc */ 18519e03ca8SJohn Baldwin #define __SAPP 0x0100 /* fdopen()ed in append mode */ 18619e03ca8SJohn Baldwin #define __SSTR 0x0200 /* this is an sprintf/snprintf string */ 18719e03ca8SJohn Baldwin #define __SOPT 0x0400 /* do fseek() optimization */ 18819e03ca8SJohn Baldwin #define __SNPT 0x0800 /* do not do fseek() optimization */ 18919e03ca8SJohn Baldwin #define __SOFF 0x1000 /* set iff _offset is in fact correct */ 19019e03ca8SJohn Baldwin #define __SMOD 0x2000 /* true => fgetln modified _p text */ 19119e03ca8SJohn Baldwin #define __SALC 0x4000 /* allocate string space dynamically */ 19219e03ca8SJohn Baldwin #define __SIGN 0x8000 /* ignore this file in _fwalk */ 19319e03ca8SJohn Baldwin 1948b63538dSAndrey A. Chernov #define __S2OAP 0x0001 /* O_APPEND mode is set */ 1958b63538dSAndrey A. Chernov 19659deaec5SRodney W. Grimes /* 19759deaec5SRodney W. Grimes * The following three definitions are for ANSI C, which took them 19859deaec5SRodney W. Grimes * from System V, which brilliantly took internal interface macros and 19959deaec5SRodney W. Grimes * made them official arguments to setvbuf(), without renaming them. 20059deaec5SRodney W. Grimes * Hence, these ugly _IOxxx names are *supposed* to appear in user code. 20119e03ca8SJohn Baldwin * 20219e03ca8SJohn Baldwin * Although numbered as their counterparts above, the implementation 20319e03ca8SJohn Baldwin * does not rely on this. 20459deaec5SRodney W. Grimes */ 20559deaec5SRodney W. Grimes #define _IOFBF 0 /* setvbuf should set fully buffered */ 20659deaec5SRodney W. Grimes #define _IOLBF 1 /* setvbuf should set line buffered */ 20759deaec5SRodney W. Grimes #define _IONBF 2 /* setvbuf should set unbuffered */ 20859deaec5SRodney W. Grimes 20959deaec5SRodney W. Grimes #define BUFSIZ 1024 /* size of buffer used by setbuf */ 21059deaec5SRodney W. Grimes #define EOF (-1) 21159deaec5SRodney W. Grimes 21259deaec5SRodney W. Grimes /* 21359deaec5SRodney W. Grimes * FOPEN_MAX is a minimum maximum, and is the number of streams that 21459deaec5SRodney W. Grimes * stdio can provide without attempting to allocate further resources 21559deaec5SRodney W. Grimes * (which could fail). Do not use this for anything. 21659deaec5SRodney W. Grimes */ 21759deaec5SRodney W. Grimes /* must be == _POSIX_STREAM_MAX <limits.h> */ 2182c2f4a60SJohn Birrell #ifndef FOPEN_MAX 21959deaec5SRodney W. Grimes #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ 2202c2f4a60SJohn Birrell #endif 22159deaec5SRodney W. Grimes #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ 22259deaec5SRodney W. Grimes 22359deaec5SRodney W. Grimes /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ 224702b2a72SGarrett Wollman #if __XSI_VISIBLE 225c8fb747dSXin LI #define P_tmpdir "/tmp/" 22659deaec5SRodney W. Grimes #endif 22759deaec5SRodney W. Grimes #define L_tmpnam 1024 /* XXX must be == PATH_MAX */ 22859deaec5SRodney W. Grimes #define TMP_MAX 308915776 22959deaec5SRodney W. Grimes 23059deaec5SRodney W. Grimes #ifndef SEEK_SET 23159deaec5SRodney W. Grimes #define SEEK_SET 0 /* set file offset to offset */ 23259deaec5SRodney W. Grimes #endif 23359deaec5SRodney W. Grimes #ifndef SEEK_CUR 23459deaec5SRodney W. Grimes #define SEEK_CUR 1 /* set file offset to current plus offset */ 23559deaec5SRodney W. Grimes #endif 23659deaec5SRodney W. Grimes #ifndef SEEK_END 23759deaec5SRodney W. Grimes #define SEEK_END 2 /* set file offset to EOF plus offset */ 23859deaec5SRodney W. Grimes #endif 23959deaec5SRodney W. Grimes 2402b618987SPeter Wemm #define stdin __stdinp 2412b618987SPeter Wemm #define stdout __stdoutp 2422b618987SPeter Wemm #define stderr __stderrp 24359deaec5SRodney W. Grimes 244cf8e5289SKyle Evans /* 245cf8e5289SKyle Evans * Functions defined in all versions of POSIX 1003.1. 246cf8e5289SKyle Evans */ 247cf8e5289SKyle Evans #if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 199506) 248cf8e5289SKyle Evans #define L_cuserid 17 /* size for cuserid(3); MAXLOGNAME, legacy */ 249cf8e5289SKyle Evans #endif 250cf8e5289SKyle Evans 251cf8e5289SKyle Evans #if __POSIX_VISIBLE 252cf8e5289SKyle Evans #define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */ 253cf8e5289SKyle Evans #endif /* __POSIX_VISIBLE */ 254cf8e5289SKyle Evans 255cf8e5289SKyle Evans #if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 256cf8e5289SKyle Evans #include <ssp/stdio.h> 257cf8e5289SKyle Evans #endif 258cf8e5289SKyle Evans 259702b2a72SGarrett Wollman __BEGIN_DECLS 2603ac9d659SDavid Chisnall #ifdef _XLOCALE_H_ 2613ac9d659SDavid Chisnall #include <xlocale/_stdio.h> 2623ac9d659SDavid Chisnall #endif 26359deaec5SRodney W. Grimes /* 26459deaec5SRodney W. Grimes * Functions defined in ANSI C standard. 26559deaec5SRodney W. Grimes */ 266bb28f3c2SWarner Losh void clearerr(FILE *); 267bb28f3c2SWarner Losh int fclose(FILE *); 268bb28f3c2SWarner Losh int feof(FILE *); 269bb28f3c2SWarner Losh int ferror(FILE *); 270bb28f3c2SWarner Losh int fflush(FILE *); 271bb28f3c2SWarner Losh int fgetc(FILE *); 27254e4e385SMike Barcroft int fgetpos(FILE * __restrict, fpos_t * __restrict); 273cf8e5289SKyle Evans char *(fgets)(char * __restrict, int, FILE * __restrict); 27454e4e385SMike Barcroft FILE *fopen(const char * __restrict, const char * __restrict); 27571a00a44SRobert Drehmel int fprintf(FILE * __restrict, const char * __restrict, ...); 276bb28f3c2SWarner Losh int fputc(int, FILE *); 27754e4e385SMike Barcroft int fputs(const char * __restrict, FILE * __restrict); 27854e4e385SMike Barcroft size_t fread(void * __restrict, size_t, size_t, FILE * __restrict); 27954e4e385SMike Barcroft FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict); 28054e4e385SMike Barcroft int fscanf(FILE * __restrict, const char * __restrict, ...); 281bb28f3c2SWarner Losh int fseek(FILE *, long, int); 282bb28f3c2SWarner Losh int fsetpos(FILE *, const fpos_t *); 283bb28f3c2SWarner Losh long ftell(FILE *); 28454e4e385SMike Barcroft size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); 285bb28f3c2SWarner Losh int getc(FILE *); 286bb28f3c2SWarner Losh int getchar(void); 287dc711d6dSCy Schubert #if __EXT1_VISIBLE 288c13559d3SCy Schubert char *gets_s(char *, rsize_t); 289c13559d3SCy Schubert #endif 290bb28f3c2SWarner Losh void perror(const char *); 29171a00a44SRobert Drehmel int printf(const char * __restrict, ...); 292bb28f3c2SWarner Losh int putc(int, FILE *); 293bb28f3c2SWarner Losh int putchar(int); 294bb28f3c2SWarner Losh int puts(const char *); 295bb28f3c2SWarner Losh int remove(const char *); 296bb28f3c2SWarner Losh int rename(const char *, const char *); 297bb28f3c2SWarner Losh void rewind(FILE *); 29854e4e385SMike Barcroft int scanf(const char * __restrict, ...); 2993248d0a5SRobert Drehmel void setbuf(FILE * __restrict, char * __restrict); 3003248d0a5SRobert Drehmel int setvbuf(FILE * __restrict, char * __restrict, int, size_t); 301cf8e5289SKyle Evans int (sprintf)(char * __restrict, const char * __restrict, ...); 30254e4e385SMike Barcroft int sscanf(const char * __restrict, const char * __restrict, ...); 303bb28f3c2SWarner Losh FILE *tmpfile(void); 304bb28f3c2SWarner Losh char *tmpnam(char *); 305bb28f3c2SWarner Losh int ungetc(int, FILE *); 306f8418db7SRobert Drehmel int vfprintf(FILE * __restrict, const char * __restrict, 307abbd8902SMike Barcroft __va_list); 308abbd8902SMike Barcroft int vprintf(const char * __restrict, __va_list); 309cf8e5289SKyle Evans int (vsprintf)(char * __restrict, const char * __restrict, 310abbd8902SMike Barcroft __va_list); 311702b2a72SGarrett Wollman 3127f3ea0abSKonstantin Belousov #if __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE >= 199506 313cf8e5289SKyle Evans int (snprintf)(char * __restrict, size_t, const char * __restrict, 314f8418db7SRobert Drehmel ...) __printflike(3, 4); 315cf8e5289SKyle Evans int (vsnprintf)(char * __restrict, size_t, const char * __restrict, 3167f3ea0abSKonstantin Belousov __va_list) __printflike(3, 0); 3177f3ea0abSKonstantin Belousov #endif 3187f3ea0abSKonstantin Belousov #if __ISO_C_VISIBLE >= 1999 319af1c9c0eSTim J. Robbins int vfscanf(FILE * __restrict, const char * __restrict, __va_list) 320af1c9c0eSTim J. Robbins __scanflike(2, 0); 32154e4e385SMike Barcroft int vscanf(const char * __restrict, __va_list) __scanflike(1, 0); 32254e4e385SMike Barcroft int vsscanf(const char * __restrict, const char * __restrict, __va_list) 3235dfca833SMike Barcroft __scanflike(2, 0); 324702b2a72SGarrett Wollman #endif 32559deaec5SRodney W. Grimes 3265dfca833SMike Barcroft #if __POSIX_VISIBLE 327bb28f3c2SWarner Losh char *ctermid(char *); 328bb28f3c2SWarner Losh FILE *fdopen(int, const char *); 329bb28f3c2SWarner Losh int fileno(FILE *); 330702b2a72SGarrett Wollman #endif /* __POSIX_VISIBLE */ 331702b2a72SGarrett Wollman 332702b2a72SGarrett Wollman #if __POSIX_VISIBLE >= 199209 333702b2a72SGarrett Wollman int pclose(FILE *); 334702b2a72SGarrett Wollman FILE *popen(const char *, const char *); 335702b2a72SGarrett Wollman #endif 336702b2a72SGarrett Wollman 337702b2a72SGarrett Wollman #if __POSIX_VISIBLE >= 199506 338bb28f3c2SWarner Losh int ftrylockfile(FILE *); 339bb28f3c2SWarner Losh void flockfile(FILE *); 340bb28f3c2SWarner Losh void funlockfile(FILE *); 341702b2a72SGarrett Wollman 342702b2a72SGarrett Wollman /* 34319e03ca8SJohn Baldwin * These are normally used through macros as defined below, but POSIX 34419e03ca8SJohn Baldwin * requires functions as well. 345702b2a72SGarrett Wollman */ 346702b2a72SGarrett Wollman int getc_unlocked(FILE *); 347702b2a72SGarrett Wollman int getchar_unlocked(void); 348702b2a72SGarrett Wollman int putc_unlocked(int, FILE *); 349702b2a72SGarrett Wollman int putchar_unlocked(int); 350702b2a72SGarrett Wollman #endif 351e8065dc4STim J. Robbins #if __BSD_VISIBLE 352e8065dc4STim J. Robbins void clearerr_unlocked(FILE *); 353e8065dc4STim J. Robbins int feof_unlocked(FILE *); 354e8065dc4STim J. Robbins int ferror_unlocked(FILE *); 35512fe218fSKyle Evans int fflush_unlocked(FILE *); 356e8065dc4STim J. Robbins int fileno_unlocked(FILE *); 357b85ea809SKyle Evans int fputc_unlocked(int, FILE *); 35812fe218fSKyle Evans int fputs_unlocked(const char * __restrict, FILE * __restrict); 35912fe218fSKyle Evans size_t fread_unlocked(void * __restrict, size_t, size_t, FILE * __restrict); 36012fe218fSKyle Evans size_t fwrite_unlocked(const void * __restrict, size_t, size_t, 36112fe218fSKyle Evans FILE * __restrict); 362e8065dc4STim J. Robbins #endif 363702b2a72SGarrett Wollman 3640558617bSPedro F. Giffuni #if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 365abbd8902SMike Barcroft int fseeko(FILE *, __off_t, int); 366abbd8902SMike Barcroft __off_t ftello(FILE *); 367702b2a72SGarrett Wollman #endif 368702b2a72SGarrett Wollman 369702b2a72SGarrett Wollman #if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 370702b2a72SGarrett Wollman int getw(FILE *); 371702b2a72SGarrett Wollman int putw(int, FILE *); 372702b2a72SGarrett Wollman #endif /* BSD or X/Open before issue 6 */ 373702b2a72SGarrett Wollman 374702b2a72SGarrett Wollman #if __XSI_VISIBLE 375702b2a72SGarrett Wollman char *tempnam(const char *, const char *); 376702b2a72SGarrett Wollman #endif 377702b2a72SGarrett Wollman 378448f5f73SJilles Tjoelker #if __POSIX_VISIBLE >= 200809 37996c95412SPietro Cerutti FILE *fmemopen(void * __restrict, size_t, const char * __restrict); 38069099ba2SDavid Schultz ssize_t getdelim(char ** __restrict, size_t * __restrict, int, 38169099ba2SDavid Schultz FILE * __restrict); 3829240031aSJohn Baldwin FILE *open_memstream(char **, size_t *); 38338953375SDavid Schultz int renameat(int, const char *, int, const char *); 384d6744932SEric van Gyzen int vdprintf(int, const char * __restrict, __va_list) __printflike(2, 0); 38508ed5b80SWarner Losh /* _WITH_GETLINE to allow pre 11 sources to build on 11+ systems */ 38669099ba2SDavid Schultz ssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict); 38721ac7a7fSEric van Gyzen int dprintf(int, const char * __restrict, ...) __printflike(2, 3); 388448f5f73SJilles Tjoelker #endif /* __POSIX_VISIBLE >= 200809 */ 38969099ba2SDavid Schultz 390702b2a72SGarrett Wollman /* 391702b2a72SGarrett Wollman * Routines that are purely local. 392702b2a72SGarrett Wollman */ 393702b2a72SGarrett Wollman #if __BSD_VISIBLE 394702b2a72SGarrett Wollman int asprintf(char **, const char *, ...) __printflike(2, 3); 395702b2a72SGarrett Wollman char *ctermid_r(char *); 39628c94ec4SDaniel Eischen void fcloseall(void); 397fd109954SMariusz Zaborski int fdclose(FILE *, int *); 398702b2a72SGarrett Wollman char *fgetln(FILE *, size_t *); 399efa952cdSXin LI const char *fmtcheck(const char *, const char *) __format_arg(2); 400702b2a72SGarrett Wollman int fpurge(FILE *); 401702b2a72SGarrett Wollman void setbuffer(FILE *, char *, int); 402702b2a72SGarrett Wollman int setlinebuf(FILE *); 403abbd8902SMike Barcroft int vasprintf(char **, const char *, __va_list) 404702b2a72SGarrett Wollman __printflike(2, 0); 405702b2a72SGarrett Wollman 406702b2a72SGarrett Wollman /* 407702b2a72SGarrett Wollman * The system error table contains messages for the first sys_nerr 408702b2a72SGarrett Wollman * positive errno values. Use strerror() or strerror_r() from <string.h> 409702b2a72SGarrett Wollman * instead. 410702b2a72SGarrett Wollman */ 411f6ab8089SEd Schouten extern const int sys_nerr; 412f6ab8089SEd Schouten extern const char * const sys_errlist[]; 413702b2a72SGarrett Wollman 414702b2a72SGarrett Wollman /* 415702b2a72SGarrett Wollman * Stdio function-access interface. 416702b2a72SGarrett Wollman */ 417702b2a72SGarrett Wollman FILE *funopen(const void *, 418649702c5SPedro F. Giffuni int (* _Nullable)(void *, char *, int), 419649702c5SPedro F. Giffuni int (* _Nullable)(void *, const char *, int), 420649702c5SPedro F. Giffuni fpos_t (* _Nullable)(void *, fpos_t, int), 421649702c5SPedro F. Giffuni int (* _Nullable)(void *)); 422702b2a72SGarrett Wollman #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) 423702b2a72SGarrett Wollman #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) 42459deaec5SRodney W. Grimes 4255d518624SWarner Losh #if __BSD_VISIBLE 4269183be81SConrad Meyer typedef __ssize_t cookie_read_function_t(void *, char *, size_t); 4279183be81SConrad Meyer typedef __ssize_t cookie_write_function_t(void *, const char *, size_t); 4289183be81SConrad Meyer typedef int cookie_seek_function_t(void *, off64_t *, int); 4299183be81SConrad Meyer typedef int cookie_close_function_t(void *); 430877a840cSConrad Meyer typedef struct { 431877a840cSConrad Meyer cookie_read_function_t *read; 432877a840cSConrad Meyer cookie_write_function_t *write; 433877a840cSConrad Meyer cookie_seek_function_t *seek; 434877a840cSConrad Meyer cookie_close_function_t *close; 435877a840cSConrad Meyer } cookie_io_functions_t; 436877a840cSConrad Meyer FILE *fopencookie(void *, const char *, cookie_io_functions_t); 4375d518624SWarner Losh #endif 438877a840cSConrad Meyer 43959deaec5SRodney W. Grimes /* 44015aa51b0SBruce Evans * Portability hacks. See <sys/types.h>. 44115aa51b0SBruce Evans */ 44215aa51b0SBruce Evans #ifndef _FTRUNCATE_DECLARED 44315aa51b0SBruce Evans #define _FTRUNCATE_DECLARED 444abbd8902SMike Barcroft int ftruncate(int, __off_t); 44515aa51b0SBruce Evans #endif 44615aa51b0SBruce Evans #ifndef _LSEEK_DECLARED 44715aa51b0SBruce Evans #define _LSEEK_DECLARED 448abbd8902SMike Barcroft __off_t lseek(int, __off_t, int); 44915aa51b0SBruce Evans #endif 45015aa51b0SBruce Evans #ifndef _MMAP_DECLARED 45115aa51b0SBruce Evans #define _MMAP_DECLARED 452abbd8902SMike Barcroft void *mmap(void *, size_t, int, int, int, __off_t); 45315aa51b0SBruce Evans #endif 45415aa51b0SBruce Evans #ifndef _TRUNCATE_DECLARED 45515aa51b0SBruce Evans #define _TRUNCATE_DECLARED 456abbd8902SMike Barcroft int truncate(const char *, __off_t); 45715aa51b0SBruce Evans #endif 458702b2a72SGarrett Wollman #endif /* __BSD_VISIBLE */ 45959deaec5SRodney W. Grimes 46019e03ca8SJohn Baldwin /* 46119e03ca8SJohn Baldwin * Functions internal to the implementation. 46219e03ca8SJohn Baldwin */ 46319e03ca8SJohn Baldwin int __srget(FILE *); 46419e03ca8SJohn Baldwin int __swbuf(int, FILE *); 46519e03ca8SJohn Baldwin 46619e03ca8SJohn Baldwin /* 46719e03ca8SJohn Baldwin * The __sfoo macros are here so that we can 46819e03ca8SJohn Baldwin * define function versions in the C library. 46919e03ca8SJohn Baldwin */ 47019e03ca8SJohn Baldwin #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) 47119e03ca8SJohn Baldwin #if defined(__GNUC__) && defined(__STDC__) 47219e03ca8SJohn Baldwin static __inline int __sputc(int _c, FILE *_p) { 47319e03ca8SJohn Baldwin if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) 47419e03ca8SJohn Baldwin return (*_p->_p++ = _c); 47519e03ca8SJohn Baldwin else 47619e03ca8SJohn Baldwin return (__swbuf(_c, _p)); 47719e03ca8SJohn Baldwin } 47819e03ca8SJohn Baldwin #else 47919e03ca8SJohn Baldwin /* 48019e03ca8SJohn Baldwin * This has been tuned to generate reasonable code on the vax using pcc. 48119e03ca8SJohn Baldwin */ 48219e03ca8SJohn Baldwin #define __sputc(c, p) \ 48319e03ca8SJohn Baldwin (--(p)->_w < 0 ? \ 48419e03ca8SJohn Baldwin (p)->_w >= (p)->_lbfsize ? \ 48519e03ca8SJohn Baldwin (*(p)->_p = (c)), *(p)->_p != '\n' ? \ 48619e03ca8SJohn Baldwin (int)*(p)->_p++ : \ 48719e03ca8SJohn Baldwin __swbuf('\n', p) : \ 48819e03ca8SJohn Baldwin __swbuf((int)(c), p) : \ 48919e03ca8SJohn Baldwin (*(p)->_p = (c), (int)*(p)->_p++)) 49019e03ca8SJohn Baldwin #endif 491eb1f614bSDavid Chisnall 4925a6d7b72SEric van Gyzen #ifndef __LIBC_ISTHREADED_DECLARED 4935a6d7b72SEric van Gyzen #define __LIBC_ISTHREADED_DECLARED 494eb1f614bSDavid Chisnall extern int __isthreaded; 4955a6d7b72SEric van Gyzen #endif 496eb1f614bSDavid Chisnall 497c9e7ce2fSDavid Chisnall #ifndef __cplusplus 49819e03ca8SJohn Baldwin 49919e03ca8SJohn Baldwin #define __sfeof(p) (((p)->_flags & __SEOF) != 0) 50019e03ca8SJohn Baldwin #define __sferror(p) (((p)->_flags & __SERR) != 0) 50119e03ca8SJohn Baldwin #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) 50219e03ca8SJohn Baldwin #define __sfileno(p) ((p)->_file) 50319e03ca8SJohn Baldwin 50419e03ca8SJohn Baldwin 50519e03ca8SJohn Baldwin #define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p)) 50619e03ca8SJohn Baldwin #define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p)) 50719e03ca8SJohn Baldwin #define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p)) 50819e03ca8SJohn Baldwin 50919e03ca8SJohn Baldwin #define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp)) 51019e03ca8SJohn Baldwin #define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp)) 51119e03ca8SJohn Baldwin 51219e03ca8SJohn Baldwin #define getchar() getc(stdin) 51319e03ca8SJohn Baldwin #define putchar(x) putc(x, stdout) 51419e03ca8SJohn Baldwin 51519e03ca8SJohn Baldwin #if __BSD_VISIBLE 51619e03ca8SJohn Baldwin /* 51719e03ca8SJohn Baldwin * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12 51819e03ca8SJohn Baldwin * B.8.2.7 for the rationale behind the *_unlocked() macros. 51919e03ca8SJohn Baldwin */ 52012fe218fSKyle Evans #define clearerr_unlocked(p) __sclearerr(p) 52119e03ca8SJohn Baldwin #define feof_unlocked(p) __sfeof(p) 52219e03ca8SJohn Baldwin #define ferror_unlocked(p) __sferror(p) 52319e03ca8SJohn Baldwin #define fileno_unlocked(p) __sfileno(p) 52412fe218fSKyle Evans #define fputc_unlocked(s, p) __sputc(s, p) 52519e03ca8SJohn Baldwin #endif 52619e03ca8SJohn Baldwin #if __POSIX_VISIBLE >= 199506 52719e03ca8SJohn Baldwin #define getc_unlocked(fp) __sgetc(fp) 52819e03ca8SJohn Baldwin #define putc_unlocked(x, fp) __sputc(x, fp) 52919e03ca8SJohn Baldwin 53019e03ca8SJohn Baldwin #define getchar_unlocked() getc_unlocked(stdin) 53119e03ca8SJohn Baldwin #define putchar_unlocked(x) putc_unlocked(x, stdout) 53219e03ca8SJohn Baldwin #endif 533c9e7ce2fSDavid Chisnall #endif /* __cplusplus */ 53419e03ca8SJohn Baldwin 535702b2a72SGarrett Wollman __END_DECLS 536649702c5SPedro F. Giffuni __NULLABILITY_PRAGMA_POP 537649702c5SPedro F. Giffuni 53815aa51b0SBruce Evans #endif /* !_STDIO_H_ */ 539