1*4a5d661aSToomas Soome /*-
2*4a5d661aSToomas Soome * Copyright (c) 1990, 1993
3*4a5d661aSToomas Soome * The Regents of the University of California. All rights reserved.
4*4a5d661aSToomas Soome *
5*4a5d661aSToomas Soome * This code is derived from software contributed to Berkeley by
6*4a5d661aSToomas Soome * Chris Torek.
7*4a5d661aSToomas Soome *
8*4a5d661aSToomas Soome * Redistribution and use in source and binary forms, with or without
9*4a5d661aSToomas Soome * modification, are permitted provided that the following conditions
10*4a5d661aSToomas Soome * are met:
11*4a5d661aSToomas Soome * 1. Redistributions of source code must retain the above copyright
12*4a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer.
13*4a5d661aSToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
14*4a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer in the
15*4a5d661aSToomas Soome * documentation and/or other materials provided with the distribution.
16*4a5d661aSToomas Soome * 3. Neither the name of the University nor the names of its contributors
17*4a5d661aSToomas Soome * may be used to endorse or promote products derived from this software
18*4a5d661aSToomas Soome * without specific prior written permission.
19*4a5d661aSToomas Soome *
20*4a5d661aSToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21*4a5d661aSToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*4a5d661aSToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*4a5d661aSToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24*4a5d661aSToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*4a5d661aSToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*4a5d661aSToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*4a5d661aSToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*4a5d661aSToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*4a5d661aSToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*4a5d661aSToomas Soome * SUCH DAMAGE.
31*4a5d661aSToomas Soome *
32*4a5d661aSToomas Soome * @(#)stdio.h 8.5 (Berkeley) 4/29/95
33*4a5d661aSToomas Soome * $FreeBSD$
34*4a5d661aSToomas Soome */
35*4a5d661aSToomas Soome
36*4a5d661aSToomas Soome #ifndef _STDIO_H_
37*4a5d661aSToomas Soome #define _STDIO_H_
38*4a5d661aSToomas Soome
39*4a5d661aSToomas Soome #include <sys/cdefs.h>
40*4a5d661aSToomas Soome #include <sys/_null.h>
41*4a5d661aSToomas Soome #include <sys/_types.h>
42*4a5d661aSToomas Soome
43*4a5d661aSToomas Soome typedef __off_t fpos_t;
44*4a5d661aSToomas Soome
45*4a5d661aSToomas Soome #ifndef _SIZE_T_DECLARED
46*4a5d661aSToomas Soome typedef __size_t size_t;
47*4a5d661aSToomas Soome #define _SIZE_T_DECLARED
48*4a5d661aSToomas Soome #endif
49*4a5d661aSToomas Soome
50*4a5d661aSToomas Soome #if __POSIX_VISIBLE >= 200809
51*4a5d661aSToomas Soome #ifndef _OFF_T_DECLARED
52*4a5d661aSToomas Soome #define _OFF_T_DECLARED
53*4a5d661aSToomas Soome typedef __off_t off_t;
54*4a5d661aSToomas Soome #endif
55*4a5d661aSToomas Soome #ifndef _SSIZE_T_DECLARED
56*4a5d661aSToomas Soome #define _SSIZE_T_DECLARED
57*4a5d661aSToomas Soome typedef __ssize_t ssize_t;
58*4a5d661aSToomas Soome #endif
59*4a5d661aSToomas Soome #endif
60*4a5d661aSToomas Soome
61*4a5d661aSToomas Soome #if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
62*4a5d661aSToomas Soome #ifndef _VA_LIST_DECLARED
63*4a5d661aSToomas Soome typedef __va_list va_list;
64*4a5d661aSToomas Soome #define _VA_LIST_DECLARED
65*4a5d661aSToomas Soome #endif
66*4a5d661aSToomas Soome #endif
67*4a5d661aSToomas Soome
68*4a5d661aSToomas Soome #define _FSTDIO /* Define for new stdio with functions. */
69*4a5d661aSToomas Soome
70*4a5d661aSToomas Soome /*
71*4a5d661aSToomas Soome * NB: to fit things in six character monocase externals, the stdio
72*4a5d661aSToomas Soome * code uses the prefix `__s' for stdio objects, typically followed
73*4a5d661aSToomas Soome * by a three-character attempt at a mnemonic.
74*4a5d661aSToomas Soome */
75*4a5d661aSToomas Soome
76*4a5d661aSToomas Soome /* stdio buffers */
77*4a5d661aSToomas Soome struct __sbuf {
78*4a5d661aSToomas Soome unsigned char *_base;
79*4a5d661aSToomas Soome int _size;
80*4a5d661aSToomas Soome };
81*4a5d661aSToomas Soome
82*4a5d661aSToomas Soome /*
83*4a5d661aSToomas Soome * stdio state variables.
84*4a5d661aSToomas Soome *
85*4a5d661aSToomas Soome * The following always hold:
86*4a5d661aSToomas Soome *
87*4a5d661aSToomas Soome * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
88*4a5d661aSToomas Soome * _lbfsize is -_bf._size, else _lbfsize is 0
89*4a5d661aSToomas Soome * if _flags&__SRD, _w is 0
90*4a5d661aSToomas Soome * if _flags&__SWR, _r is 0
91*4a5d661aSToomas Soome *
92*4a5d661aSToomas Soome * This ensures that the getc and putc macros (or inline functions) never
93*4a5d661aSToomas Soome * try to write or read from a file that is in `read' or `write' mode.
94*4a5d661aSToomas Soome * (Moreover, they can, and do, automatically switch from read mode to
95*4a5d661aSToomas Soome * write mode, and back, on "r+" and "w+" files.)
96*4a5d661aSToomas Soome *
97*4a5d661aSToomas Soome * _lbfsize is used only to make the inline line-buffered output stream
98*4a5d661aSToomas Soome * code as compact as possible.
99*4a5d661aSToomas Soome *
100*4a5d661aSToomas Soome * _ub, _up, and _ur are used when ungetc() pushes back more characters
101*4a5d661aSToomas Soome * than fit in the current _bf, or when ungetc() pushes back a character
102*4a5d661aSToomas Soome * that does not match the previous one in _bf. When this happens,
103*4a5d661aSToomas Soome * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
104*4a5d661aSToomas Soome * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
105*4a5d661aSToomas Soome *
106*4a5d661aSToomas Soome * Certain members of __sFILE are accessed directly via macros or
107*4a5d661aSToomas Soome * inline functions. To preserve ABI compat, these members must not
108*4a5d661aSToomas Soome * be disturbed. These members are marked below with (*).
109*4a5d661aSToomas Soome */
110*4a5d661aSToomas Soome struct __sFILE {
111*4a5d661aSToomas Soome unsigned char *_p; /* (*) current position in (some) buffer */
112*4a5d661aSToomas Soome int _r; /* (*) read space left for getc() */
113*4a5d661aSToomas Soome int _w; /* (*) write space left for putc() */
114*4a5d661aSToomas Soome short _flags; /* (*) flags, below; this FILE is free if 0 */
115*4a5d661aSToomas Soome short _file; /* (*) fileno, if Unix descriptor, else -1 */
116*4a5d661aSToomas Soome struct __sbuf _bf; /* (*) the buffer (at least 1 byte, if !NULL) */
117*4a5d661aSToomas Soome int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */
118*4a5d661aSToomas Soome
119*4a5d661aSToomas Soome /* operations */
120*4a5d661aSToomas Soome void *_cookie; /* (*) cookie passed to io functions */
121*4a5d661aSToomas Soome int (*_close)(void *);
122*4a5d661aSToomas Soome int (*_read)(void *, char *, int);
123*4a5d661aSToomas Soome fpos_t (*_seek)(void *, fpos_t, int);
124*4a5d661aSToomas Soome int (*_write)(void *, const char *, int);
125*4a5d661aSToomas Soome
126*4a5d661aSToomas Soome /* separate buffer for long sequences of ungetc() */
127*4a5d661aSToomas Soome struct __sbuf _ub; /* ungetc buffer */
128*4a5d661aSToomas Soome unsigned char *_up; /* saved _p when _p is doing ungetc data */
129*4a5d661aSToomas Soome int _ur; /* saved _r when _r is counting ungetc data */
130*4a5d661aSToomas Soome
131*4a5d661aSToomas Soome /* tricks to meet minimum requirements even when malloc() fails */
132*4a5d661aSToomas Soome unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
133*4a5d661aSToomas Soome unsigned char _nbuf[1]; /* guarantee a getc() buffer */
134*4a5d661aSToomas Soome
135*4a5d661aSToomas Soome /* separate buffer for fgetln() when line crosses buffer boundary */
136*4a5d661aSToomas Soome struct __sbuf _lb; /* buffer for fgetln() */
137*4a5d661aSToomas Soome
138*4a5d661aSToomas Soome /* Unix stdio files get aligned to block boundaries on fseek() */
139*4a5d661aSToomas Soome int _blksize; /* stat.st_blksize (may be != _bf._size) */
140*4a5d661aSToomas Soome fpos_t _offset; /* current lseek offset */
141*4a5d661aSToomas Soome
142*4a5d661aSToomas Soome struct pthread_mutex *_fl_mutex; /* used for MT-safety */
143*4a5d661aSToomas Soome struct pthread *_fl_owner; /* current owner */
144*4a5d661aSToomas Soome int _fl_count; /* recursive lock count */
145*4a5d661aSToomas Soome int _orientation; /* orientation for fwide() */
146*4a5d661aSToomas Soome __mbstate_t _mbstate; /* multibyte conversion state */
147*4a5d661aSToomas Soome int _flags2; /* additional flags */
148*4a5d661aSToomas Soome };
149*4a5d661aSToomas Soome #ifndef _STDFILE_DECLARED
150*4a5d661aSToomas Soome #define _STDFILE_DECLARED
151*4a5d661aSToomas Soome typedef struct __sFILE FILE;
152*4a5d661aSToomas Soome #endif
153*4a5d661aSToomas Soome #ifndef _STDSTREAM_DECLARED
154*4a5d661aSToomas Soome __BEGIN_DECLS
155*4a5d661aSToomas Soome extern FILE *__stdinp;
156*4a5d661aSToomas Soome extern FILE *__stdoutp;
157*4a5d661aSToomas Soome extern FILE *__stderrp;
158*4a5d661aSToomas Soome __END_DECLS
159*4a5d661aSToomas Soome #define _STDSTREAM_DECLARED
160*4a5d661aSToomas Soome #endif
161*4a5d661aSToomas Soome
162*4a5d661aSToomas Soome #define __SLBF 0x0001 /* line buffered */
163*4a5d661aSToomas Soome #define __SNBF 0x0002 /* unbuffered */
164*4a5d661aSToomas Soome #define __SRD 0x0004 /* OK to read */
165*4a5d661aSToomas Soome #define __SWR 0x0008 /* OK to write */
166*4a5d661aSToomas Soome /* RD and WR are never simultaneously asserted */
167*4a5d661aSToomas Soome #define __SRW 0x0010 /* open for reading & writing */
168*4a5d661aSToomas Soome #define __SEOF 0x0020 /* found EOF */
169*4a5d661aSToomas Soome #define __SERR 0x0040 /* found error */
170*4a5d661aSToomas Soome #define __SMBF 0x0080 /* _bf._base is from malloc */
171*4a5d661aSToomas Soome #define __SAPP 0x0100 /* fdopen()ed in append mode */
172*4a5d661aSToomas Soome #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
173*4a5d661aSToomas Soome #define __SOPT 0x0400 /* do fseek() optimization */
174*4a5d661aSToomas Soome #define __SNPT 0x0800 /* do not do fseek() optimization */
175*4a5d661aSToomas Soome #define __SOFF 0x1000 /* set iff _offset is in fact correct */
176*4a5d661aSToomas Soome #define __SMOD 0x2000 /* true => fgetln modified _p text */
177*4a5d661aSToomas Soome #define __SALC 0x4000 /* allocate string space dynamically */
178*4a5d661aSToomas Soome #define __SIGN 0x8000 /* ignore this file in _fwalk */
179*4a5d661aSToomas Soome
180*4a5d661aSToomas Soome #define __S2OAP 0x0001 /* O_APPEND mode is set */
181*4a5d661aSToomas Soome
182*4a5d661aSToomas Soome /*
183*4a5d661aSToomas Soome * The following three definitions are for ANSI C, which took them
184*4a5d661aSToomas Soome * from System V, which brilliantly took internal interface macros and
185*4a5d661aSToomas Soome * made them official arguments to setvbuf(), without renaming them.
186*4a5d661aSToomas Soome * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
187*4a5d661aSToomas Soome *
188*4a5d661aSToomas Soome * Although numbered as their counterparts above, the implementation
189*4a5d661aSToomas Soome * does not rely on this.
190*4a5d661aSToomas Soome */
191*4a5d661aSToomas Soome #define _IOFBF 0 /* setvbuf should set fully buffered */
192*4a5d661aSToomas Soome #define _IOLBF 1 /* setvbuf should set line buffered */
193*4a5d661aSToomas Soome #define _IONBF 2 /* setvbuf should set unbuffered */
194*4a5d661aSToomas Soome
195*4a5d661aSToomas Soome #define BUFSIZ 1024 /* size of buffer used by setbuf */
196*4a5d661aSToomas Soome #define EOF (-1)
197*4a5d661aSToomas Soome
198*4a5d661aSToomas Soome /*
199*4a5d661aSToomas Soome * FOPEN_MAX is a minimum maximum, and is the number of streams that
200*4a5d661aSToomas Soome * stdio can provide without attempting to allocate further resources
201*4a5d661aSToomas Soome * (which could fail). Do not use this for anything.
202*4a5d661aSToomas Soome */
203*4a5d661aSToomas Soome /* must be == _POSIX_STREAM_MAX <limits.h> */
204*4a5d661aSToomas Soome #ifndef FOPEN_MAX
205*4a5d661aSToomas Soome #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */
206*4a5d661aSToomas Soome #endif
207*4a5d661aSToomas Soome #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */
208*4a5d661aSToomas Soome
209*4a5d661aSToomas Soome /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
210*4a5d661aSToomas Soome #if __XSI_VISIBLE
211*4a5d661aSToomas Soome #define P_tmpdir "/tmp/"
212*4a5d661aSToomas Soome #endif
213*4a5d661aSToomas Soome #define L_tmpnam 1024 /* XXX must be == PATH_MAX */
214*4a5d661aSToomas Soome #define TMP_MAX 308915776
215*4a5d661aSToomas Soome
216*4a5d661aSToomas Soome #ifndef SEEK_SET
217*4a5d661aSToomas Soome #define SEEK_SET 0 /* set file offset to offset */
218*4a5d661aSToomas Soome #endif
219*4a5d661aSToomas Soome #ifndef SEEK_CUR
220*4a5d661aSToomas Soome #define SEEK_CUR 1 /* set file offset to current plus offset */
221*4a5d661aSToomas Soome #endif
222*4a5d661aSToomas Soome #ifndef SEEK_END
223*4a5d661aSToomas Soome #define SEEK_END 2 /* set file offset to EOF plus offset */
224*4a5d661aSToomas Soome #endif
225*4a5d661aSToomas Soome
226*4a5d661aSToomas Soome #define stdin __stdinp
227*4a5d661aSToomas Soome #define stdout __stdoutp
228*4a5d661aSToomas Soome #define stderr __stderrp
229*4a5d661aSToomas Soome
230*4a5d661aSToomas Soome __BEGIN_DECLS
231*4a5d661aSToomas Soome #ifdef _XLOCALE_H_
232*4a5d661aSToomas Soome #include <xlocale/_stdio.h>
233*4a5d661aSToomas Soome #endif
234*4a5d661aSToomas Soome /*
235*4a5d661aSToomas Soome * Functions defined in ANSI C standard.
236*4a5d661aSToomas Soome */
237*4a5d661aSToomas Soome void clearerr(FILE *);
238*4a5d661aSToomas Soome int fclose(FILE *);
239*4a5d661aSToomas Soome int feof(FILE *);
240*4a5d661aSToomas Soome int ferror(FILE *);
241*4a5d661aSToomas Soome int fflush(FILE *);
242*4a5d661aSToomas Soome int fgetc(FILE *);
243*4a5d661aSToomas Soome int fgetpos(FILE * __restrict, fpos_t * __restrict);
244*4a5d661aSToomas Soome char *fgets(char * __restrict, int, FILE * __restrict);
245*4a5d661aSToomas Soome FILE *fopen(const char * __restrict, const char * __restrict);
246*4a5d661aSToomas Soome int fprintf(FILE * __restrict, const char * __restrict, ...);
247*4a5d661aSToomas Soome int fputc(int, FILE *);
248*4a5d661aSToomas Soome int fputs(const char * __restrict, FILE * __restrict);
249*4a5d661aSToomas Soome size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
250*4a5d661aSToomas Soome FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict);
251*4a5d661aSToomas Soome int fscanf(FILE * __restrict, const char * __restrict, ...);
252*4a5d661aSToomas Soome int fseek(FILE *, long, int);
253*4a5d661aSToomas Soome int fsetpos(FILE *, const fpos_t *);
254*4a5d661aSToomas Soome long ftell(FILE *);
255*4a5d661aSToomas Soome size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
256*4a5d661aSToomas Soome int getc(FILE *);
257*4a5d661aSToomas Soome int getchar(void);
258*4a5d661aSToomas Soome char *gets(char *);
259*4a5d661aSToomas Soome void perror(const char *);
260*4a5d661aSToomas Soome int printf(const char * __restrict, ...);
261*4a5d661aSToomas Soome int putc(int, FILE *);
262*4a5d661aSToomas Soome int putchar(int);
263*4a5d661aSToomas Soome int puts(const char *);
264*4a5d661aSToomas Soome int remove(const char *);
265*4a5d661aSToomas Soome int rename(const char *, const char *);
266*4a5d661aSToomas Soome void rewind(FILE *);
267*4a5d661aSToomas Soome int scanf(const char * __restrict, ...);
268*4a5d661aSToomas Soome void setbuf(FILE * __restrict, char * __restrict);
269*4a5d661aSToomas Soome int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
270*4a5d661aSToomas Soome int sprintf(char * __restrict, const char * __restrict, ...);
271*4a5d661aSToomas Soome int sscanf(const char * __restrict, const char * __restrict, ...);
272*4a5d661aSToomas Soome FILE *tmpfile(void);
273*4a5d661aSToomas Soome char *tmpnam(char *);
274*4a5d661aSToomas Soome int ungetc(int, FILE *);
275*4a5d661aSToomas Soome int vfprintf(FILE * __restrict, const char * __restrict,
276*4a5d661aSToomas Soome __va_list);
277*4a5d661aSToomas Soome int vprintf(const char * __restrict, __va_list);
278*4a5d661aSToomas Soome int vsprintf(char * __restrict, const char * __restrict,
279*4a5d661aSToomas Soome __va_list);
280*4a5d661aSToomas Soome
281*4a5d661aSToomas Soome #if __ISO_C_VISIBLE >= 1999
282*4a5d661aSToomas Soome int snprintf(char * __restrict, size_t, const char * __restrict,
283*4a5d661aSToomas Soome ...) __printflike(3, 4);
284*4a5d661aSToomas Soome int vfscanf(FILE * __restrict, const char * __restrict, __va_list)
285*4a5d661aSToomas Soome __scanflike(2, 0);
286*4a5d661aSToomas Soome int vscanf(const char * __restrict, __va_list) __scanflike(1, 0);
287*4a5d661aSToomas Soome int vsnprintf(char * __restrict, size_t, const char * __restrict,
288*4a5d661aSToomas Soome __va_list) __printflike(3, 0);
289*4a5d661aSToomas Soome int vsscanf(const char * __restrict, const char * __restrict, __va_list)
290*4a5d661aSToomas Soome __scanflike(2, 0);
291*4a5d661aSToomas Soome #endif
292*4a5d661aSToomas Soome
293*4a5d661aSToomas Soome /*
294*4a5d661aSToomas Soome * Functions defined in all versions of POSIX 1003.1.
295*4a5d661aSToomas Soome */
296*4a5d661aSToomas Soome #if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 199506)
297*4a5d661aSToomas Soome #define L_cuserid 17 /* size for cuserid(3); MAXLOGNAME, legacy */
298*4a5d661aSToomas Soome #endif
299*4a5d661aSToomas Soome
300*4a5d661aSToomas Soome #if __POSIX_VISIBLE
301*4a5d661aSToomas Soome #define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */
302*4a5d661aSToomas Soome
303*4a5d661aSToomas Soome char *ctermid(char *);
304*4a5d661aSToomas Soome FILE *fdopen(int, const char *);
305*4a5d661aSToomas Soome int fileno(FILE *);
306*4a5d661aSToomas Soome #endif /* __POSIX_VISIBLE */
307*4a5d661aSToomas Soome
308*4a5d661aSToomas Soome #if __POSIX_VISIBLE >= 199209
309*4a5d661aSToomas Soome int pclose(FILE *);
310*4a5d661aSToomas Soome FILE *popen(const char *, const char *);
311*4a5d661aSToomas Soome #endif
312*4a5d661aSToomas Soome
313*4a5d661aSToomas Soome #if __POSIX_VISIBLE >= 199506
314*4a5d661aSToomas Soome int ftrylockfile(FILE *);
315*4a5d661aSToomas Soome void flockfile(FILE *);
316*4a5d661aSToomas Soome void funlockfile(FILE *);
317*4a5d661aSToomas Soome
318*4a5d661aSToomas Soome /*
319*4a5d661aSToomas Soome * These are normally used through macros as defined below, but POSIX
320*4a5d661aSToomas Soome * requires functions as well.
321*4a5d661aSToomas Soome */
322*4a5d661aSToomas Soome int getc_unlocked(FILE *);
323*4a5d661aSToomas Soome int getchar_unlocked(void);
324*4a5d661aSToomas Soome int putc_unlocked(int, FILE *);
325*4a5d661aSToomas Soome int putchar_unlocked(int);
326*4a5d661aSToomas Soome #endif
327*4a5d661aSToomas Soome #if __BSD_VISIBLE
328*4a5d661aSToomas Soome void clearerr_unlocked(FILE *);
329*4a5d661aSToomas Soome int feof_unlocked(FILE *);
330*4a5d661aSToomas Soome int ferror_unlocked(FILE *);
331*4a5d661aSToomas Soome int fileno_unlocked(FILE *);
332*4a5d661aSToomas Soome #endif
333*4a5d661aSToomas Soome
334*4a5d661aSToomas Soome #if __POSIX_VISIBLE >= 200112
335*4a5d661aSToomas Soome int fseeko(FILE *, __off_t, int);
336*4a5d661aSToomas Soome __off_t ftello(FILE *);
337*4a5d661aSToomas Soome #endif
338*4a5d661aSToomas Soome
339*4a5d661aSToomas Soome #if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600
340*4a5d661aSToomas Soome int getw(FILE *);
341*4a5d661aSToomas Soome int putw(int, FILE *);
342*4a5d661aSToomas Soome #endif /* BSD or X/Open before issue 6 */
343*4a5d661aSToomas Soome
344*4a5d661aSToomas Soome #if __XSI_VISIBLE
345*4a5d661aSToomas Soome char *tempnam(const char *, const char *);
346*4a5d661aSToomas Soome #endif
347*4a5d661aSToomas Soome
348*4a5d661aSToomas Soome #if __POSIX_VISIBLE >= 200809
349*4a5d661aSToomas Soome FILE *fmemopen(void * __restrict, size_t, const char * __restrict);
350*4a5d661aSToomas Soome ssize_t getdelim(char ** __restrict, size_t * __restrict, int,
351*4a5d661aSToomas Soome FILE * __restrict);
352*4a5d661aSToomas Soome FILE *open_memstream(char **, size_t *);
353*4a5d661aSToomas Soome int renameat(int, const char *, int, const char *);
354*4a5d661aSToomas Soome int vdprintf(int, const char * __restrict, __va_list);
355*4a5d661aSToomas Soome
356*4a5d661aSToomas Soome /*
357*4a5d661aSToomas Soome * Every programmer and his dog wrote functions called getline() and dprintf()
358*4a5d661aSToomas Soome * before POSIX.1-2008 came along and decided to usurp the names, so we
359*4a5d661aSToomas Soome * don't prototype them by default unless one of the following is true:
360*4a5d661aSToomas Soome * a) the app has requested them specifically by defining _WITH_GETLINE or
361*4a5d661aSToomas Soome * _WITH_DPRINTF, respectively
362*4a5d661aSToomas Soome * b) the app has requested a POSIX.1-2008 environment via _POSIX_C_SOURCE
363*4a5d661aSToomas Soome * c) the app defines a GNUism such as _BSD_SOURCE or _GNU_SOURCE
364*4a5d661aSToomas Soome */
365*4a5d661aSToomas Soome #ifndef _WITH_GETLINE
366*4a5d661aSToomas Soome #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
367*4a5d661aSToomas Soome #define _WITH_GETLINE
368*4a5d661aSToomas Soome #elif defined(_POSIX_C_SOURCE)
369*4a5d661aSToomas Soome #if _POSIX_C_SOURCE >= 200809
370*4a5d661aSToomas Soome #define _WITH_GETLINE
371*4a5d661aSToomas Soome #endif
372*4a5d661aSToomas Soome #endif
373*4a5d661aSToomas Soome #endif
374*4a5d661aSToomas Soome
375*4a5d661aSToomas Soome #ifdef _WITH_GETLINE
376*4a5d661aSToomas Soome ssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict);
377*4a5d661aSToomas Soome #endif
378*4a5d661aSToomas Soome
379*4a5d661aSToomas Soome #ifndef _WITH_DPRINTF
380*4a5d661aSToomas Soome #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
381*4a5d661aSToomas Soome #define _WITH_DPRINTF
382*4a5d661aSToomas Soome #elif defined(_POSIX_C_SOURCE)
383*4a5d661aSToomas Soome #if _POSIX_C_SOURCE >= 200809
384*4a5d661aSToomas Soome #define _WITH_DPRINTF
385*4a5d661aSToomas Soome #endif
386*4a5d661aSToomas Soome #endif
387*4a5d661aSToomas Soome #endif
388*4a5d661aSToomas Soome
389*4a5d661aSToomas Soome #ifdef _WITH_DPRINTF
390*4a5d661aSToomas Soome int (dprintf)(int, const char * __restrict, ...);
391*4a5d661aSToomas Soome #endif
392*4a5d661aSToomas Soome
393*4a5d661aSToomas Soome #endif /* __POSIX_VISIBLE >= 200809 */
394*4a5d661aSToomas Soome
395*4a5d661aSToomas Soome /*
396*4a5d661aSToomas Soome * Routines that are purely local.
397*4a5d661aSToomas Soome */
398*4a5d661aSToomas Soome #if __BSD_VISIBLE
399*4a5d661aSToomas Soome int asprintf(char **, const char *, ...) __printflike(2, 3);
400*4a5d661aSToomas Soome char *ctermid_r(char *);
401*4a5d661aSToomas Soome void fcloseall(void);
402*4a5d661aSToomas Soome int fdclose(FILE *, int *);
403*4a5d661aSToomas Soome char *fgetln(FILE *, size_t *);
404*4a5d661aSToomas Soome const char *fmtcheck(const char *, const char *) __format_arg(2);
405*4a5d661aSToomas Soome int fpurge(FILE *);
406*4a5d661aSToomas Soome void setbuffer(FILE *, char *, int);
407*4a5d661aSToomas Soome int setlinebuf(FILE *);
408*4a5d661aSToomas Soome int vasprintf(char **, const char *, __va_list)
409*4a5d661aSToomas Soome __printflike(2, 0);
410*4a5d661aSToomas Soome
411*4a5d661aSToomas Soome /*
412*4a5d661aSToomas Soome * The system error table contains messages for the first sys_nerr
413*4a5d661aSToomas Soome * positive errno values. Use strerror() or strerror_r() from <string.h>
414*4a5d661aSToomas Soome * instead.
415*4a5d661aSToomas Soome */
416*4a5d661aSToomas Soome extern const int sys_nerr;
417*4a5d661aSToomas Soome extern const char * const sys_errlist[];
418*4a5d661aSToomas Soome
419*4a5d661aSToomas Soome /*
420*4a5d661aSToomas Soome * Stdio function-access interface.
421*4a5d661aSToomas Soome */
422*4a5d661aSToomas Soome FILE *funopen(const void *,
423*4a5d661aSToomas Soome int (*)(void *, char *, int),
424*4a5d661aSToomas Soome int (*)(void *, const char *, int),
425*4a5d661aSToomas Soome fpos_t (*)(void *, fpos_t, int),
426*4a5d661aSToomas Soome int (*)(void *));
427*4a5d661aSToomas Soome #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
428*4a5d661aSToomas Soome #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
429*4a5d661aSToomas Soome
430*4a5d661aSToomas Soome /*
431*4a5d661aSToomas Soome * Portability hacks. See <sys/types.h>.
432*4a5d661aSToomas Soome */
433*4a5d661aSToomas Soome #ifndef _FTRUNCATE_DECLARED
434*4a5d661aSToomas Soome #define _FTRUNCATE_DECLARED
435*4a5d661aSToomas Soome int ftruncate(int, __off_t);
436*4a5d661aSToomas Soome #endif
437*4a5d661aSToomas Soome #ifndef _LSEEK_DECLARED
438*4a5d661aSToomas Soome #define _LSEEK_DECLARED
439*4a5d661aSToomas Soome __off_t lseek(int, __off_t, int);
440*4a5d661aSToomas Soome #endif
441*4a5d661aSToomas Soome #ifndef _MMAP_DECLARED
442*4a5d661aSToomas Soome #define _MMAP_DECLARED
443*4a5d661aSToomas Soome void *mmap(void *, size_t, int, int, int, __off_t);
444*4a5d661aSToomas Soome #endif
445*4a5d661aSToomas Soome #ifndef _TRUNCATE_DECLARED
446*4a5d661aSToomas Soome #define _TRUNCATE_DECLARED
447*4a5d661aSToomas Soome int truncate(const char *, __off_t);
448*4a5d661aSToomas Soome #endif
449*4a5d661aSToomas Soome #endif /* __BSD_VISIBLE */
450*4a5d661aSToomas Soome
451*4a5d661aSToomas Soome /*
452*4a5d661aSToomas Soome * Functions internal to the implementation.
453*4a5d661aSToomas Soome */
454*4a5d661aSToomas Soome int __srget(FILE *);
455*4a5d661aSToomas Soome int __swbuf(int, FILE *);
456*4a5d661aSToomas Soome
457*4a5d661aSToomas Soome /*
458*4a5d661aSToomas Soome * The __sfoo macros are here so that we can
459*4a5d661aSToomas Soome * define function versions in the C library.
460*4a5d661aSToomas Soome */
461*4a5d661aSToomas Soome #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
462*4a5d661aSToomas Soome #if defined(__GNUC__) && defined(__STDC__)
__sputc(int _c,FILE * _p)463*4a5d661aSToomas Soome static __inline int __sputc(int _c, FILE *_p) {
464*4a5d661aSToomas Soome if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
465*4a5d661aSToomas Soome return (*_p->_p++ = _c);
466*4a5d661aSToomas Soome else
467*4a5d661aSToomas Soome return (__swbuf(_c, _p));
468*4a5d661aSToomas Soome }
469*4a5d661aSToomas Soome #else
470*4a5d661aSToomas Soome /*
471*4a5d661aSToomas Soome * This has been tuned to generate reasonable code on the vax using pcc.
472*4a5d661aSToomas Soome */
473*4a5d661aSToomas Soome #define __sputc(c, p) \
474*4a5d661aSToomas Soome (--(p)->_w < 0 ? \
475*4a5d661aSToomas Soome (p)->_w >= (p)->_lbfsize ? \
476*4a5d661aSToomas Soome (*(p)->_p = (c)), *(p)->_p != '\n' ? \
477*4a5d661aSToomas Soome (int)*(p)->_p++ : \
478*4a5d661aSToomas Soome __swbuf('\n', p) : \
479*4a5d661aSToomas Soome __swbuf((int)(c), p) : \
480*4a5d661aSToomas Soome (*(p)->_p = (c), (int)*(p)->_p++))
481*4a5d661aSToomas Soome #endif
482*4a5d661aSToomas Soome
483*4a5d661aSToomas Soome extern int __isthreaded;
484*4a5d661aSToomas Soome
485*4a5d661aSToomas Soome #ifndef __cplusplus
486*4a5d661aSToomas Soome
487*4a5d661aSToomas Soome #define __sfeof(p) (((p)->_flags & __SEOF) != 0)
488*4a5d661aSToomas Soome #define __sferror(p) (((p)->_flags & __SERR) != 0)
489*4a5d661aSToomas Soome #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
490*4a5d661aSToomas Soome #define __sfileno(p) ((p)->_file)
491*4a5d661aSToomas Soome
492*4a5d661aSToomas Soome
493*4a5d661aSToomas Soome #define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p))
494*4a5d661aSToomas Soome #define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p))
495*4a5d661aSToomas Soome #define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p))
496*4a5d661aSToomas Soome
497*4a5d661aSToomas Soome #if __POSIX_VISIBLE
498*4a5d661aSToomas Soome #define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p))
499*4a5d661aSToomas Soome #endif
500*4a5d661aSToomas Soome
501*4a5d661aSToomas Soome #define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp))
502*4a5d661aSToomas Soome #define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp))
503*4a5d661aSToomas Soome
504*4a5d661aSToomas Soome #define getchar() getc(stdin)
505*4a5d661aSToomas Soome #define putchar(x) putc(x, stdout)
506*4a5d661aSToomas Soome
507*4a5d661aSToomas Soome #if __BSD_VISIBLE
508*4a5d661aSToomas Soome /*
509*4a5d661aSToomas Soome * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12
510*4a5d661aSToomas Soome * B.8.2.7 for the rationale behind the *_unlocked() macros.
511*4a5d661aSToomas Soome */
512*4a5d661aSToomas Soome #define feof_unlocked(p) __sfeof(p)
513*4a5d661aSToomas Soome #define ferror_unlocked(p) __sferror(p)
514*4a5d661aSToomas Soome #define clearerr_unlocked(p) __sclearerr(p)
515*4a5d661aSToomas Soome #define fileno_unlocked(p) __sfileno(p)
516*4a5d661aSToomas Soome #endif
517*4a5d661aSToomas Soome #if __POSIX_VISIBLE >= 199506
518*4a5d661aSToomas Soome #define getc_unlocked(fp) __sgetc(fp)
519*4a5d661aSToomas Soome #define putc_unlocked(x, fp) __sputc(x, fp)
520*4a5d661aSToomas Soome
521*4a5d661aSToomas Soome #define getchar_unlocked() getc_unlocked(stdin)
522*4a5d661aSToomas Soome #define putchar_unlocked(x) putc_unlocked(x, stdout)
523*4a5d661aSToomas Soome #endif
524*4a5d661aSToomas Soome #endif /* __cplusplus */
525*4a5d661aSToomas Soome
526*4a5d661aSToomas Soome __END_DECLS
527*4a5d661aSToomas Soome #endif /* !_STDIO_H_ */
528