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. 16f2556687SWarner Losh * 3. Neither the name of the University nor the names of its contributors 1759deaec5SRodney W. Grimes * may be used to endorse or promote products derived from this software 1859deaec5SRodney W. Grimes * without specific prior written permission. 1959deaec5SRodney W. Grimes * 2059deaec5SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2159deaec5SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2259deaec5SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2359deaec5SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2459deaec5SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2559deaec5SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2659deaec5SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2759deaec5SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2859deaec5SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2959deaec5SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3059deaec5SRodney W. Grimes * SUCH DAMAGE. 3159deaec5SRodney W. Grimes * 32161f948dSPeter Wemm * @(#)stdio.h 8.5 (Berkeley) 4/29/95 33a4add9a9SPeter Wemm * $FreeBSD$ 3459deaec5SRodney W. Grimes */ 3559deaec5SRodney W. Grimes 3659deaec5SRodney W. Grimes #ifndef _STDIO_H_ 3759deaec5SRodney W. Grimes #define _STDIO_H_ 3859deaec5SRodney W. Grimes 3959deaec5SRodney W. Grimes #include <sys/cdefs.h> 4012eb46c8SMarcel Moolenaar #include <sys/_null.h> 41abbd8902SMike Barcroft #include <sys/_types.h> 4215aa51b0SBruce Evans 435dfca833SMike Barcroft typedef __off_t fpos_t; 445dfca833SMike Barcroft 45abbd8902SMike Barcroft #ifndef _SIZE_T_DECLARED 46abbd8902SMike Barcroft typedef __size_t size_t; 47abbd8902SMike Barcroft #define _SIZE_T_DECLARED 4859deaec5SRodney W. Grimes #endif 4959deaec5SRodney W. Grimes 50448f5f73SJilles Tjoelker #if __POSIX_VISIBLE >= 200809 5169099ba2SDavid Schultz #ifndef _OFF_T_DECLARED 5269099ba2SDavid Schultz #define _OFF_T_DECLARED 5369099ba2SDavid Schultz typedef __off_t off_t; 5469099ba2SDavid Schultz #endif 5569099ba2SDavid Schultz #ifndef _SSIZE_T_DECLARED 5669099ba2SDavid Schultz #define _SSIZE_T_DECLARED 5769099ba2SDavid Schultz typedef __ssize_t ssize_t; 5869099ba2SDavid Schultz #endif 5969099ba2SDavid Schultz #endif 6069099ba2SDavid Schultz 61877a840cSConrad Meyer #ifndef _OFF64_T_DECLARED 62877a840cSConrad Meyer #define _OFF64_T_DECLARED 636710d21dSConrad Meyer typedef __off64_t off64_t; 64877a840cSConrad Meyer #endif 65877a840cSConrad Meyer 66448f5f73SJilles Tjoelker #if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE 675dfca833SMike Barcroft #ifndef _VA_LIST_DECLARED 685dfca833SMike Barcroft typedef __va_list va_list; 695dfca833SMike Barcroft #define _VA_LIST_DECLARED 705dfca833SMike Barcroft #endif 715dfca833SMike Barcroft #endif 725dfca833SMike Barcroft 7359deaec5SRodney W. Grimes #define _FSTDIO /* Define for new stdio with functions. */ 7459deaec5SRodney W. Grimes 7519e03ca8SJohn Baldwin /* 7619e03ca8SJohn Baldwin * NB: to fit things in six character monocase externals, the stdio 7719e03ca8SJohn Baldwin * code uses the prefix `__s' for stdio objects, typically followed 7819e03ca8SJohn Baldwin * by a three-character attempt at a mnemonic. 7919e03ca8SJohn Baldwin */ 8019e03ca8SJohn Baldwin 8119e03ca8SJohn Baldwin /* stdio buffers */ 8219e03ca8SJohn Baldwin struct __sbuf { 8319e03ca8SJohn Baldwin unsigned char *_base; 8419e03ca8SJohn Baldwin int _size; 8519e03ca8SJohn Baldwin }; 8619e03ca8SJohn Baldwin 8719e03ca8SJohn Baldwin /* 8819e03ca8SJohn Baldwin * stdio state variables. 8919e03ca8SJohn Baldwin * 9019e03ca8SJohn Baldwin * The following always hold: 9119e03ca8SJohn Baldwin * 9219e03ca8SJohn Baldwin * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), 9319e03ca8SJohn Baldwin * _lbfsize is -_bf._size, else _lbfsize is 0 9419e03ca8SJohn Baldwin * if _flags&__SRD, _w is 0 9519e03ca8SJohn Baldwin * if _flags&__SWR, _r is 0 9619e03ca8SJohn Baldwin * 9719e03ca8SJohn Baldwin * This ensures that the getc and putc macros (or inline functions) never 9819e03ca8SJohn Baldwin * try to write or read from a file that is in `read' or `write' mode. 9919e03ca8SJohn Baldwin * (Moreover, they can, and do, automatically switch from read mode to 10019e03ca8SJohn Baldwin * write mode, and back, on "r+" and "w+" files.) 10119e03ca8SJohn Baldwin * 10219e03ca8SJohn Baldwin * _lbfsize is used only to make the inline line-buffered output stream 10319e03ca8SJohn Baldwin * code as compact as possible. 10419e03ca8SJohn Baldwin * 10519e03ca8SJohn Baldwin * _ub, _up, and _ur are used when ungetc() pushes back more characters 10619e03ca8SJohn Baldwin * than fit in the current _bf, or when ungetc() pushes back a character 10719e03ca8SJohn Baldwin * that does not match the previous one in _bf. When this happens, 10819e03ca8SJohn Baldwin * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff 10919e03ca8SJohn Baldwin * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. 11019e03ca8SJohn Baldwin * 11119e03ca8SJohn Baldwin * Certain members of __sFILE are accessed directly via macros or 11219e03ca8SJohn Baldwin * inline functions. To preserve ABI compat, these members must not 11319e03ca8SJohn Baldwin * be disturbed. These members are marked below with (*). 11419e03ca8SJohn Baldwin */ 115c9e7ce2fSDavid Chisnall struct __sFILE { 11619e03ca8SJohn Baldwin unsigned char *_p; /* (*) current position in (some) buffer */ 11719e03ca8SJohn Baldwin int _r; /* (*) read space left for getc() */ 11819e03ca8SJohn Baldwin int _w; /* (*) write space left for putc() */ 11919e03ca8SJohn Baldwin short _flags; /* (*) flags, below; this FILE is free if 0 */ 12019e03ca8SJohn Baldwin short _file; /* (*) fileno, if Unix descriptor, else -1 */ 12141a5b871SJohn Baldwin struct __sbuf _bf; /* (*) the buffer (at least 1 byte, if !NULL) */ 12219e03ca8SJohn Baldwin int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */ 12319e03ca8SJohn Baldwin 12419e03ca8SJohn Baldwin /* operations */ 125a1b482adSJohn Baldwin void *_cookie; /* (*) cookie passed to io functions */ 12619e03ca8SJohn Baldwin int (*_close)(void *); 12719e03ca8SJohn Baldwin int (*_read)(void *, char *, int); 12819e03ca8SJohn Baldwin fpos_t (*_seek)(void *, fpos_t, int); 12919e03ca8SJohn Baldwin int (*_write)(void *, const char *, int); 13019e03ca8SJohn Baldwin 13119e03ca8SJohn Baldwin /* separate buffer for long sequences of ungetc() */ 13219e03ca8SJohn Baldwin struct __sbuf _ub; /* ungetc buffer */ 13319e03ca8SJohn Baldwin unsigned char *_up; /* saved _p when _p is doing ungetc data */ 13419e03ca8SJohn Baldwin int _ur; /* saved _r when _r is counting ungetc data */ 13519e03ca8SJohn Baldwin 13619e03ca8SJohn Baldwin /* tricks to meet minimum requirements even when malloc() fails */ 13719e03ca8SJohn Baldwin unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ 13819e03ca8SJohn Baldwin unsigned char _nbuf[1]; /* guarantee a getc() buffer */ 13919e03ca8SJohn Baldwin 14019e03ca8SJohn Baldwin /* separate buffer for fgetln() when line crosses buffer boundary */ 14119e03ca8SJohn Baldwin struct __sbuf _lb; /* buffer for fgetln() */ 14219e03ca8SJohn Baldwin 14319e03ca8SJohn Baldwin /* Unix stdio files get aligned to block boundaries on fseek() */ 14419e03ca8SJohn Baldwin int _blksize; /* stat.st_blksize (may be != _bf._size) */ 14519e03ca8SJohn Baldwin fpos_t _offset; /* current lseek offset */ 14619e03ca8SJohn Baldwin 14719e03ca8SJohn Baldwin struct pthread_mutex *_fl_mutex; /* used for MT-safety */ 14819e03ca8SJohn Baldwin struct pthread *_fl_owner; /* current owner */ 14919e03ca8SJohn Baldwin int _fl_count; /* recursive lock count */ 15019e03ca8SJohn Baldwin int _orientation; /* orientation for fwide() */ 15119e03ca8SJohn Baldwin __mbstate_t _mbstate; /* multibyte conversion state */ 1528b63538dSAndrey A. Chernov int _flags2; /* additional flags */ 153c9e7ce2fSDavid Chisnall }; 154c9e7ce2fSDavid Chisnall #ifndef _STDFILE_DECLARED 155c9e7ce2fSDavid Chisnall #define _STDFILE_DECLARED 156c9e7ce2fSDavid Chisnall typedef struct __sFILE FILE; 157c9e7ce2fSDavid Chisnall #endif 15884bb9aaaSTim J. Robbins #ifndef _STDSTREAM_DECLARED 15959deaec5SRodney W. Grimes __BEGIN_DECLS 1602b618987SPeter Wemm extern FILE *__stdinp; 1612b618987SPeter Wemm extern FILE *__stdoutp; 1622b618987SPeter Wemm extern FILE *__stderrp; 16359deaec5SRodney W. Grimes __END_DECLS 16484bb9aaaSTim J. Robbins #define _STDSTREAM_DECLARED 16584bb9aaaSTim J. Robbins #endif 16659deaec5SRodney W. Grimes 16719e03ca8SJohn Baldwin #define __SLBF 0x0001 /* line buffered */ 16819e03ca8SJohn Baldwin #define __SNBF 0x0002 /* unbuffered */ 16919e03ca8SJohn Baldwin #define __SRD 0x0004 /* OK to read */ 17019e03ca8SJohn Baldwin #define __SWR 0x0008 /* OK to write */ 17119e03ca8SJohn Baldwin /* RD and WR are never simultaneously asserted */ 17219e03ca8SJohn Baldwin #define __SRW 0x0010 /* open for reading & writing */ 17319e03ca8SJohn Baldwin #define __SEOF 0x0020 /* found EOF */ 17419e03ca8SJohn Baldwin #define __SERR 0x0040 /* found error */ 175addf3409SBryan Drewery #define __SMBF 0x0080 /* _bf._base is from malloc */ 17619e03ca8SJohn Baldwin #define __SAPP 0x0100 /* fdopen()ed in append mode */ 17719e03ca8SJohn Baldwin #define __SSTR 0x0200 /* this is an sprintf/snprintf string */ 17819e03ca8SJohn Baldwin #define __SOPT 0x0400 /* do fseek() optimization */ 17919e03ca8SJohn Baldwin #define __SNPT 0x0800 /* do not do fseek() optimization */ 18019e03ca8SJohn Baldwin #define __SOFF 0x1000 /* set iff _offset is in fact correct */ 18119e03ca8SJohn Baldwin #define __SMOD 0x2000 /* true => fgetln modified _p text */ 18219e03ca8SJohn Baldwin #define __SALC 0x4000 /* allocate string space dynamically */ 18319e03ca8SJohn Baldwin #define __SIGN 0x8000 /* ignore this file in _fwalk */ 18419e03ca8SJohn Baldwin 1858b63538dSAndrey A. Chernov #define __S2OAP 0x0001 /* O_APPEND mode is set */ 1868b63538dSAndrey A. Chernov 18759deaec5SRodney W. Grimes /* 18859deaec5SRodney W. Grimes * The following three definitions are for ANSI C, which took them 18959deaec5SRodney W. Grimes * from System V, which brilliantly took internal interface macros and 19059deaec5SRodney W. Grimes * made them official arguments to setvbuf(), without renaming them. 19159deaec5SRodney W. Grimes * Hence, these ugly _IOxxx names are *supposed* to appear in user code. 19219e03ca8SJohn Baldwin * 19319e03ca8SJohn Baldwin * Although numbered as their counterparts above, the implementation 19419e03ca8SJohn Baldwin * does not rely on this. 19559deaec5SRodney W. Grimes */ 19659deaec5SRodney W. Grimes #define _IOFBF 0 /* setvbuf should set fully buffered */ 19759deaec5SRodney W. Grimes #define _IOLBF 1 /* setvbuf should set line buffered */ 19859deaec5SRodney W. Grimes #define _IONBF 2 /* setvbuf should set unbuffered */ 19959deaec5SRodney W. Grimes 20059deaec5SRodney W. Grimes #define BUFSIZ 1024 /* size of buffer used by setbuf */ 20159deaec5SRodney W. Grimes #define EOF (-1) 20259deaec5SRodney W. Grimes 20359deaec5SRodney W. Grimes /* 20459deaec5SRodney W. Grimes * FOPEN_MAX is a minimum maximum, and is the number of streams that 20559deaec5SRodney W. Grimes * stdio can provide without attempting to allocate further resources 20659deaec5SRodney W. Grimes * (which could fail). Do not use this for anything. 20759deaec5SRodney W. Grimes */ 20859deaec5SRodney W. Grimes /* must be == _POSIX_STREAM_MAX <limits.h> */ 2092c2f4a60SJohn Birrell #ifndef FOPEN_MAX 21059deaec5SRodney W. Grimes #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ 2112c2f4a60SJohn Birrell #endif 21259deaec5SRodney W. Grimes #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ 21359deaec5SRodney W. Grimes 21459deaec5SRodney W. Grimes /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ 215702b2a72SGarrett Wollman #if __XSI_VISIBLE 216c8fb747dSXin LI #define P_tmpdir "/tmp/" 21759deaec5SRodney W. Grimes #endif 21859deaec5SRodney W. Grimes #define L_tmpnam 1024 /* XXX must be == PATH_MAX */ 21959deaec5SRodney W. Grimes #define TMP_MAX 308915776 22059deaec5SRodney W. Grimes 22159deaec5SRodney W. Grimes #ifndef SEEK_SET 22259deaec5SRodney W. Grimes #define SEEK_SET 0 /* set file offset to offset */ 22359deaec5SRodney W. Grimes #endif 22459deaec5SRodney W. Grimes #ifndef SEEK_CUR 22559deaec5SRodney W. Grimes #define SEEK_CUR 1 /* set file offset to current plus offset */ 22659deaec5SRodney W. Grimes #endif 22759deaec5SRodney W. Grimes #ifndef SEEK_END 22859deaec5SRodney W. Grimes #define SEEK_END 2 /* set file offset to EOF plus offset */ 22959deaec5SRodney W. Grimes #endif 23059deaec5SRodney W. Grimes 2312b618987SPeter Wemm #define stdin __stdinp 2322b618987SPeter Wemm #define stdout __stdoutp 2332b618987SPeter Wemm #define stderr __stderrp 23459deaec5SRodney W. Grimes 235702b2a72SGarrett Wollman __BEGIN_DECLS 2363ac9d659SDavid Chisnall #ifdef _XLOCALE_H_ 2373ac9d659SDavid Chisnall #include <xlocale/_stdio.h> 2383ac9d659SDavid Chisnall #endif 23959deaec5SRodney W. Grimes /* 24059deaec5SRodney W. Grimes * Functions defined in ANSI C standard. 24159deaec5SRodney W. Grimes */ 242bb28f3c2SWarner Losh void clearerr(FILE *); 243bb28f3c2SWarner Losh int fclose(FILE *); 244bb28f3c2SWarner Losh int feof(FILE *); 245bb28f3c2SWarner Losh int ferror(FILE *); 246bb28f3c2SWarner Losh int fflush(FILE *); 247bb28f3c2SWarner Losh int fgetc(FILE *); 24854e4e385SMike Barcroft int fgetpos(FILE * __restrict, fpos_t * __restrict); 24954e4e385SMike Barcroft char *fgets(char * __restrict, int, FILE * __restrict); 25054e4e385SMike Barcroft FILE *fopen(const char * __restrict, const char * __restrict); 25171a00a44SRobert Drehmel int fprintf(FILE * __restrict, const char * __restrict, ...); 252bb28f3c2SWarner Losh int fputc(int, FILE *); 25354e4e385SMike Barcroft int fputs(const char * __restrict, FILE * __restrict); 25454e4e385SMike Barcroft size_t fread(void * __restrict, size_t, size_t, FILE * __restrict); 25554e4e385SMike Barcroft FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict); 25654e4e385SMike Barcroft int fscanf(FILE * __restrict, const char * __restrict, ...); 257bb28f3c2SWarner Losh int fseek(FILE *, long, int); 258bb28f3c2SWarner Losh int fsetpos(FILE *, const fpos_t *); 259bb28f3c2SWarner Losh long ftell(FILE *); 26054e4e385SMike Barcroft size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); 261bb28f3c2SWarner Losh int getc(FILE *); 262bb28f3c2SWarner Losh int getchar(void); 263bb28f3c2SWarner Losh char *gets(char *); 264bb28f3c2SWarner Losh void perror(const char *); 26571a00a44SRobert Drehmel int printf(const char * __restrict, ...); 266bb28f3c2SWarner Losh int putc(int, FILE *); 267bb28f3c2SWarner Losh int putchar(int); 268bb28f3c2SWarner Losh int puts(const char *); 269bb28f3c2SWarner Losh int remove(const char *); 270bb28f3c2SWarner Losh int rename(const char *, const char *); 271bb28f3c2SWarner Losh void rewind(FILE *); 27254e4e385SMike Barcroft int scanf(const char * __restrict, ...); 2733248d0a5SRobert Drehmel void setbuf(FILE * __restrict, char * __restrict); 2743248d0a5SRobert Drehmel int setvbuf(FILE * __restrict, char * __restrict, int, size_t); 27571a00a44SRobert Drehmel int sprintf(char * __restrict, const char * __restrict, ...); 27654e4e385SMike Barcroft int sscanf(const char * __restrict, const char * __restrict, ...); 277bb28f3c2SWarner Losh FILE *tmpfile(void); 278bb28f3c2SWarner Losh char *tmpnam(char *); 279bb28f3c2SWarner Losh int ungetc(int, FILE *); 280f8418db7SRobert Drehmel int vfprintf(FILE * __restrict, const char * __restrict, 281abbd8902SMike Barcroft __va_list); 282abbd8902SMike Barcroft int vprintf(const char * __restrict, __va_list); 283f8418db7SRobert Drehmel int vsprintf(char * __restrict, const char * __restrict, 284abbd8902SMike Barcroft __va_list); 285702b2a72SGarrett Wollman 286702b2a72SGarrett Wollman #if __ISO_C_VISIBLE >= 1999 287f8418db7SRobert Drehmel int snprintf(char * __restrict, size_t, const char * __restrict, 288f8418db7SRobert Drehmel ...) __printflike(3, 4); 289af1c9c0eSTim J. Robbins int vfscanf(FILE * __restrict, const char * __restrict, __va_list) 290af1c9c0eSTim J. Robbins __scanflike(2, 0); 29154e4e385SMike Barcroft int vscanf(const char * __restrict, __va_list) __scanflike(1, 0); 292f8418db7SRobert Drehmel int vsnprintf(char * __restrict, size_t, const char * __restrict, 293abbd8902SMike Barcroft __va_list) __printflike(3, 0); 29454e4e385SMike Barcroft int vsscanf(const char * __restrict, const char * __restrict, __va_list) 2955dfca833SMike Barcroft __scanflike(2, 0); 296702b2a72SGarrett Wollman #endif 29759deaec5SRodney W. Grimes 29859deaec5SRodney W. Grimes /* 299702b2a72SGarrett Wollman * Functions defined in all versions of POSIX 1003.1. 30059deaec5SRodney W. Grimes */ 30176902266SJilles Tjoelker #if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 199506) 302cdd337c2SEd Schouten #define L_cuserid 17 /* size for cuserid(3); MAXLOGNAME, legacy */ 3035dfca833SMike Barcroft #endif 3048c372bd8SWolfram Schneider 3055dfca833SMike Barcroft #if __POSIX_VISIBLE 3068c372bd8SWolfram Schneider #define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */ 30759deaec5SRodney W. Grimes 308bb28f3c2SWarner Losh char *ctermid(char *); 309bb28f3c2SWarner Losh FILE *fdopen(int, const char *); 310bb28f3c2SWarner Losh int fileno(FILE *); 311702b2a72SGarrett Wollman #endif /* __POSIX_VISIBLE */ 312702b2a72SGarrett Wollman 313702b2a72SGarrett Wollman #if __POSIX_VISIBLE >= 199209 314702b2a72SGarrett Wollman int pclose(FILE *); 315702b2a72SGarrett Wollman FILE *popen(const char *, const char *); 316702b2a72SGarrett Wollman #endif 317702b2a72SGarrett Wollman 318702b2a72SGarrett Wollman #if __POSIX_VISIBLE >= 199506 319bb28f3c2SWarner Losh int ftrylockfile(FILE *); 320bb28f3c2SWarner Losh void flockfile(FILE *); 321bb28f3c2SWarner Losh void funlockfile(FILE *); 322702b2a72SGarrett Wollman 323702b2a72SGarrett Wollman /* 32419e03ca8SJohn Baldwin * These are normally used through macros as defined below, but POSIX 32519e03ca8SJohn Baldwin * requires functions as well. 326702b2a72SGarrett Wollman */ 327702b2a72SGarrett Wollman int getc_unlocked(FILE *); 328702b2a72SGarrett Wollman int getchar_unlocked(void); 329702b2a72SGarrett Wollman int putc_unlocked(int, FILE *); 330702b2a72SGarrett Wollman int putchar_unlocked(int); 331702b2a72SGarrett Wollman #endif 332e8065dc4STim J. Robbins #if __BSD_VISIBLE 333e8065dc4STim J. Robbins void clearerr_unlocked(FILE *); 334e8065dc4STim J. Robbins int feof_unlocked(FILE *); 335e8065dc4STim J. Robbins int ferror_unlocked(FILE *); 336e8065dc4STim J. Robbins int fileno_unlocked(FILE *); 337e8065dc4STim J. Robbins #endif 338702b2a72SGarrett Wollman 339702b2a72SGarrett Wollman #if __POSIX_VISIBLE >= 200112 340abbd8902SMike Barcroft int fseeko(FILE *, __off_t, int); 341abbd8902SMike Barcroft __off_t ftello(FILE *); 342702b2a72SGarrett Wollman #endif 343702b2a72SGarrett Wollman 344702b2a72SGarrett Wollman #if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 345702b2a72SGarrett Wollman int getw(FILE *); 346702b2a72SGarrett Wollman int putw(int, FILE *); 347702b2a72SGarrett Wollman #endif /* BSD or X/Open before issue 6 */ 348702b2a72SGarrett Wollman 349702b2a72SGarrett Wollman #if __XSI_VISIBLE 350702b2a72SGarrett Wollman char *tempnam(const char *, const char *); 351702b2a72SGarrett Wollman #endif 352702b2a72SGarrett Wollman 353448f5f73SJilles Tjoelker #if __POSIX_VISIBLE >= 200809 35496c95412SPietro Cerutti FILE *fmemopen(void * __restrict, size_t, const char * __restrict); 35569099ba2SDavid Schultz ssize_t getdelim(char ** __restrict, size_t * __restrict, int, 35669099ba2SDavid Schultz FILE * __restrict); 3579240031aSJohn Baldwin FILE *open_memstream(char **, size_t *); 35838953375SDavid Schultz int renameat(int, const char *, int, const char *); 359ad760e6fSDavid Schultz int vdprintf(int, const char * __restrict, __va_list); 360*08ed5b80SWarner Losh /* _WITH_GETLINE to allow pre 11 sources to build on 11+ systems */ 36169099ba2SDavid Schultz ssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict); 362dd47921eSBaptiste Daroussin int dprintf(int, const char * __restrict, ...); 363448f5f73SJilles Tjoelker #endif /* __POSIX_VISIBLE >= 200809 */ 36469099ba2SDavid Schultz 365702b2a72SGarrett Wollman /* 366702b2a72SGarrett Wollman * Routines that are purely local. 367702b2a72SGarrett Wollman */ 368702b2a72SGarrett Wollman #if __BSD_VISIBLE 369702b2a72SGarrett Wollman int asprintf(char **, const char *, ...) __printflike(2, 3); 370702b2a72SGarrett Wollman char *ctermid_r(char *); 37128c94ec4SDaniel Eischen void fcloseall(void); 372fd109954SMariusz Zaborski int fdclose(FILE *, int *); 373702b2a72SGarrett Wollman char *fgetln(FILE *, size_t *); 374efa952cdSXin LI const char *fmtcheck(const char *, const char *) __format_arg(2); 375702b2a72SGarrett Wollman int fpurge(FILE *); 376702b2a72SGarrett Wollman void setbuffer(FILE *, char *, int); 377702b2a72SGarrett Wollman int setlinebuf(FILE *); 378abbd8902SMike Barcroft int vasprintf(char **, const char *, __va_list) 379702b2a72SGarrett Wollman __printflike(2, 0); 380702b2a72SGarrett Wollman 381702b2a72SGarrett Wollman /* 382702b2a72SGarrett Wollman * The system error table contains messages for the first sys_nerr 383702b2a72SGarrett Wollman * positive errno values. Use strerror() or strerror_r() from <string.h> 384702b2a72SGarrett Wollman * instead. 385702b2a72SGarrett Wollman */ 386f6ab8089SEd Schouten extern const int sys_nerr; 387f6ab8089SEd Schouten extern const char * const sys_errlist[]; 388702b2a72SGarrett Wollman 389702b2a72SGarrett Wollman /* 390702b2a72SGarrett Wollman * Stdio function-access interface. 391702b2a72SGarrett Wollman */ 392702b2a72SGarrett Wollman FILE *funopen(const void *, 393702b2a72SGarrett Wollman int (*)(void *, char *, int), 394702b2a72SGarrett Wollman int (*)(void *, const char *, int), 395702b2a72SGarrett Wollman fpos_t (*)(void *, fpos_t, int), 396702b2a72SGarrett Wollman int (*)(void *)); 397702b2a72SGarrett Wollman #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) 398702b2a72SGarrett Wollman #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) 39959deaec5SRodney W. Grimes 4009183be81SConrad Meyer typedef __ssize_t cookie_read_function_t(void *, char *, size_t); 4019183be81SConrad Meyer typedef __ssize_t cookie_write_function_t(void *, const char *, size_t); 4029183be81SConrad Meyer typedef int cookie_seek_function_t(void *, off64_t *, int); 4039183be81SConrad Meyer typedef int cookie_close_function_t(void *); 404877a840cSConrad Meyer typedef struct { 405877a840cSConrad Meyer cookie_read_function_t *read; 406877a840cSConrad Meyer cookie_write_function_t *write; 407877a840cSConrad Meyer cookie_seek_function_t *seek; 408877a840cSConrad Meyer cookie_close_function_t *close; 409877a840cSConrad Meyer } cookie_io_functions_t; 410877a840cSConrad Meyer FILE *fopencookie(void *, const char *, cookie_io_functions_t); 411877a840cSConrad Meyer 41259deaec5SRodney W. Grimes /* 41315aa51b0SBruce Evans * Portability hacks. See <sys/types.h>. 41415aa51b0SBruce Evans */ 41515aa51b0SBruce Evans #ifndef _FTRUNCATE_DECLARED 41615aa51b0SBruce Evans #define _FTRUNCATE_DECLARED 417abbd8902SMike Barcroft int ftruncate(int, __off_t); 41815aa51b0SBruce Evans #endif 41915aa51b0SBruce Evans #ifndef _LSEEK_DECLARED 42015aa51b0SBruce Evans #define _LSEEK_DECLARED 421abbd8902SMike Barcroft __off_t lseek(int, __off_t, int); 42215aa51b0SBruce Evans #endif 42315aa51b0SBruce Evans #ifndef _MMAP_DECLARED 42415aa51b0SBruce Evans #define _MMAP_DECLARED 425abbd8902SMike Barcroft void *mmap(void *, size_t, int, int, int, __off_t); 42615aa51b0SBruce Evans #endif 42715aa51b0SBruce Evans #ifndef _TRUNCATE_DECLARED 42815aa51b0SBruce Evans #define _TRUNCATE_DECLARED 429abbd8902SMike Barcroft int truncate(const char *, __off_t); 43015aa51b0SBruce Evans #endif 431702b2a72SGarrett Wollman #endif /* __BSD_VISIBLE */ 43259deaec5SRodney W. Grimes 43319e03ca8SJohn Baldwin /* 43419e03ca8SJohn Baldwin * Functions internal to the implementation. 43519e03ca8SJohn Baldwin */ 43619e03ca8SJohn Baldwin int __srget(FILE *); 43719e03ca8SJohn Baldwin int __swbuf(int, FILE *); 43819e03ca8SJohn Baldwin 43919e03ca8SJohn Baldwin /* 44019e03ca8SJohn Baldwin * The __sfoo macros are here so that we can 44119e03ca8SJohn Baldwin * define function versions in the C library. 44219e03ca8SJohn Baldwin */ 44319e03ca8SJohn Baldwin #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) 44419e03ca8SJohn Baldwin #if defined(__GNUC__) && defined(__STDC__) 44519e03ca8SJohn Baldwin static __inline int __sputc(int _c, FILE *_p) { 44619e03ca8SJohn Baldwin if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) 44719e03ca8SJohn Baldwin return (*_p->_p++ = _c); 44819e03ca8SJohn Baldwin else 44919e03ca8SJohn Baldwin return (__swbuf(_c, _p)); 45019e03ca8SJohn Baldwin } 45119e03ca8SJohn Baldwin #else 45219e03ca8SJohn Baldwin /* 45319e03ca8SJohn Baldwin * This has been tuned to generate reasonable code on the vax using pcc. 45419e03ca8SJohn Baldwin */ 45519e03ca8SJohn Baldwin #define __sputc(c, p) \ 45619e03ca8SJohn Baldwin (--(p)->_w < 0 ? \ 45719e03ca8SJohn Baldwin (p)->_w >= (p)->_lbfsize ? \ 45819e03ca8SJohn Baldwin (*(p)->_p = (c)), *(p)->_p != '\n' ? \ 45919e03ca8SJohn Baldwin (int)*(p)->_p++ : \ 46019e03ca8SJohn Baldwin __swbuf('\n', p) : \ 46119e03ca8SJohn Baldwin __swbuf((int)(c), p) : \ 46219e03ca8SJohn Baldwin (*(p)->_p = (c), (int)*(p)->_p++)) 46319e03ca8SJohn Baldwin #endif 464eb1f614bSDavid Chisnall 465eb1f614bSDavid Chisnall extern int __isthreaded; 466eb1f614bSDavid Chisnall 467c9e7ce2fSDavid Chisnall #ifndef __cplusplus 46819e03ca8SJohn Baldwin 46919e03ca8SJohn Baldwin #define __sfeof(p) (((p)->_flags & __SEOF) != 0) 47019e03ca8SJohn Baldwin #define __sferror(p) (((p)->_flags & __SERR) != 0) 47119e03ca8SJohn Baldwin #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) 47219e03ca8SJohn Baldwin #define __sfileno(p) ((p)->_file) 47319e03ca8SJohn Baldwin 47419e03ca8SJohn Baldwin 47519e03ca8SJohn Baldwin #define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p)) 47619e03ca8SJohn Baldwin #define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p)) 47719e03ca8SJohn Baldwin #define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p)) 47819e03ca8SJohn Baldwin 47919e03ca8SJohn Baldwin #if __POSIX_VISIBLE 48019e03ca8SJohn Baldwin #define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p)) 48119e03ca8SJohn Baldwin #endif 48219e03ca8SJohn Baldwin 48319e03ca8SJohn Baldwin #define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp)) 48419e03ca8SJohn Baldwin #define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp)) 48519e03ca8SJohn Baldwin 48619e03ca8SJohn Baldwin #define getchar() getc(stdin) 48719e03ca8SJohn Baldwin #define putchar(x) putc(x, stdout) 48819e03ca8SJohn Baldwin 48919e03ca8SJohn Baldwin #if __BSD_VISIBLE 49019e03ca8SJohn Baldwin /* 49119e03ca8SJohn Baldwin * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12 49219e03ca8SJohn Baldwin * B.8.2.7 for the rationale behind the *_unlocked() macros. 49319e03ca8SJohn Baldwin */ 49419e03ca8SJohn Baldwin #define feof_unlocked(p) __sfeof(p) 49519e03ca8SJohn Baldwin #define ferror_unlocked(p) __sferror(p) 49619e03ca8SJohn Baldwin #define clearerr_unlocked(p) __sclearerr(p) 49719e03ca8SJohn Baldwin #define fileno_unlocked(p) __sfileno(p) 49819e03ca8SJohn Baldwin #endif 49919e03ca8SJohn Baldwin #if __POSIX_VISIBLE >= 199506 50019e03ca8SJohn Baldwin #define getc_unlocked(fp) __sgetc(fp) 50119e03ca8SJohn Baldwin #define putc_unlocked(x, fp) __sputc(x, fp) 50219e03ca8SJohn Baldwin 50319e03ca8SJohn Baldwin #define getchar_unlocked() getc_unlocked(stdin) 50419e03ca8SJohn Baldwin #define putchar_unlocked(x) putc_unlocked(x, stdout) 50519e03ca8SJohn Baldwin #endif 506c9e7ce2fSDavid Chisnall #endif /* __cplusplus */ 50719e03ca8SJohn Baldwin 508702b2a72SGarrett Wollman __END_DECLS 50915aa51b0SBruce Evans #endif /* !_STDIO_H_ */ 510