stdio.h revision 1.70.8.2 1 1.70.8.2 kristerw /* $NetBSD: stdio.h,v 1.70.8.2 2007/08/02 21:49:10 kristerw Exp $ */
2 1.70.8.2 kristerw
3 1.70.8.2 kristerw /*-
4 1.70.8.2 kristerw * Copyright (c) 1990, 1993
5 1.70.8.2 kristerw * The Regents of the University of California. All rights reserved.
6 1.70.8.2 kristerw *
7 1.70.8.2 kristerw * This code is derived from software contributed to Berkeley by
8 1.70.8.2 kristerw * Chris Torek.
9 1.70.8.2 kristerw *
10 1.70.8.2 kristerw * Redistribution and use in source and binary forms, with or without
11 1.70.8.2 kristerw * modification, are permitted provided that the following conditions
12 1.70.8.2 kristerw * are met:
13 1.70.8.2 kristerw * 1. Redistributions of source code must retain the above copyright
14 1.70.8.2 kristerw * notice, this list of conditions and the following disclaimer.
15 1.70.8.2 kristerw * 2. Redistributions in binary form must reproduce the above copyright
16 1.70.8.2 kristerw * notice, this list of conditions and the following disclaimer in the
17 1.70.8.2 kristerw * documentation and/or other materials provided with the distribution.
18 1.70.8.2 kristerw * 3. Neither the name of the University nor the names of its contributors
19 1.70.8.2 kristerw * may be used to endorse or promote products derived from this software
20 1.70.8.2 kristerw * without specific prior written permission.
21 1.70.8.2 kristerw *
22 1.70.8.2 kristerw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.70.8.2 kristerw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.70.8.2 kristerw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.70.8.2 kristerw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.70.8.2 kristerw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.70.8.2 kristerw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.70.8.2 kristerw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.70.8.2 kristerw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.70.8.2 kristerw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.70.8.2 kristerw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.70.8.2 kristerw * SUCH DAMAGE.
33 1.70.8.2 kristerw *
34 1.70.8.2 kristerw * @(#)stdio.h 8.5 (Berkeley) 4/29/95
35 1.70.8.2 kristerw */
36 1.70.8.2 kristerw
37 1.70.8.2 kristerw #ifndef _STDIO_H_
38 1.70.8.2 kristerw #define _STDIO_H_
39 1.70.8.2 kristerw
40 1.70.8.2 kristerw #include <sys/cdefs.h>
41 1.70.8.2 kristerw #include <sys/featuretest.h>
42 1.70.8.2 kristerw #include <sys/ansi.h>
43 1.70.8.2 kristerw
44 1.70.8.2 kristerw #include <machine/ansi.h>
45 1.70.8.2 kristerw #ifdef _BSD_SIZE_T_
46 1.70.8.2 kristerw typedef _BSD_SIZE_T_ size_t;
47 1.70.8.2 kristerw #undef _BSD_SIZE_T_
48 1.70.8.2 kristerw #endif
49 1.70.8.2 kristerw
50 1.70.8.2 kristerw #include <sys/null.h>
51 1.70.8.2 kristerw
52 1.70.8.2 kristerw /*
53 1.70.8.2 kristerw * This is fairly grotesque, but pure ANSI code must not inspect the
54 1.70.8.2 kristerw * innards of an fpos_t anyway. The library internally uses off_t,
55 1.70.8.2 kristerw * which we assume is exactly as big as eight chars.
56 1.70.8.2 kristerw */
57 1.70.8.2 kristerw #if (!defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)) || defined(_LIBC)
58 1.70.8.2 kristerw typedef __off_t fpos_t;
59 1.70.8.2 kristerw #else
60 1.70.8.2 kristerw typedef struct __sfpos {
61 1.70.8.2 kristerw __off_t _pos;
62 1.70.8.2 kristerw } fpos_t;
63 1.70.8.2 kristerw #endif
64 1.70.8.2 kristerw
65 1.70.8.2 kristerw #define _FSTDIO /* Define for new stdio with functions. */
66 1.70.8.2 kristerw
67 1.70.8.2 kristerw /*
68 1.70.8.2 kristerw * NB: to fit things in six character monocase externals, the stdio
69 1.70.8.2 kristerw * code uses the prefix `__s' for stdio objects, typically followed
70 1.70.8.2 kristerw * by a three-character attempt at a mnemonic.
71 1.70.8.2 kristerw */
72 1.70.8.2 kristerw
73 1.70.8.2 kristerw /* stdio buffers */
74 1.70.8.2 kristerw struct __sbuf {
75 1.70.8.2 kristerw unsigned char *_base;
76 1.70.8.2 kristerw int _size;
77 1.70.8.2 kristerw };
78 1.70.8.2 kristerw
79 1.70.8.2 kristerw /*
80 1.70.8.2 kristerw * stdio state variables.
81 1.70.8.2 kristerw *
82 1.70.8.2 kristerw * The following always hold:
83 1.70.8.2 kristerw *
84 1.70.8.2 kristerw * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
85 1.70.8.2 kristerw * _lbfsize is -_bf._size, else _lbfsize is 0
86 1.70.8.2 kristerw * if _flags&__SRD, _w is 0
87 1.70.8.2 kristerw * if _flags&__SWR, _r is 0
88 1.70.8.2 kristerw *
89 1.70.8.2 kristerw * This ensures that the getc and putc macros (or inline functions) never
90 1.70.8.2 kristerw * try to write or read from a file that is in `read' or `write' mode.
91 1.70.8.2 kristerw * (Moreover, they can, and do, automatically switch from read mode to
92 1.70.8.2 kristerw * write mode, and back, on "r+" and "w+" files.)
93 1.70.8.2 kristerw *
94 1.70.8.2 kristerw * _lbfsize is used only to make the inline line-buffered output stream
95 1.70.8.2 kristerw * code as compact as possible.
96 1.70.8.2 kristerw *
97 1.70.8.2 kristerw * _ub, _up, and _ur are used when ungetc() pushes back more characters
98 1.70.8.2 kristerw * than fit in the current _bf, or when ungetc() pushes back a character
99 1.70.8.2 kristerw * that does not match the previous one in _bf. When this happens,
100 1.70.8.2 kristerw * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
101 1.70.8.2 kristerw * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
102 1.70.8.2 kristerw *
103 1.70.8.2 kristerw * NB: see WARNING above before changing the layout of this structure!
104 1.70.8.2 kristerw */
105 1.70.8.2 kristerw typedef struct __sFILE {
106 1.70.8.2 kristerw unsigned char *_p; /* current position in (some) buffer */
107 1.70.8.2 kristerw int _r; /* read space left for getc() */
108 1.70.8.2 kristerw int _w; /* write space left for putc() */
109 1.70.8.2 kristerw unsigned short _flags; /* flags, below; this FILE is free if 0 */
110 1.70.8.2 kristerw short _file; /* fileno, if Unix descriptor, else -1 */
111 1.70.8.2 kristerw struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
112 1.70.8.2 kristerw int _lbfsize; /* 0 or -_bf._size, for inline putc */
113 1.70.8.2 kristerw
114 1.70.8.2 kristerw /* operations */
115 1.70.8.2 kristerw void *_cookie; /* cookie passed to io functions */
116 1.70.8.2 kristerw int (*_close)(void *);
117 1.70.8.2 kristerw int (*_read) (void *, char *, int);
118 1.70.8.2 kristerw fpos_t (*_seek) (void *, fpos_t, int);
119 1.70.8.2 kristerw int (*_write)(void *, const char *, int);
120 1.70.8.2 kristerw
121 1.70.8.2 kristerw /* file extension */
122 1.70.8.2 kristerw struct __sbuf _ext;
123 1.70.8.2 kristerw
124 1.70.8.2 kristerw /* separate buffer for long sequences of ungetc() */
125 1.70.8.2 kristerw unsigned char *_up; /* saved _p when _p is doing ungetc data */
126 1.70.8.2 kristerw int _ur; /* saved _r when _r is counting ungetc data */
127 1.70.8.2 kristerw
128 1.70.8.2 kristerw /* tricks to meet minimum requirements even when malloc() fails */
129 1.70.8.2 kristerw unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
130 1.70.8.2 kristerw unsigned char _nbuf[1]; /* guarantee a getc() buffer */
131 1.70.8.2 kristerw
132 1.70.8.2 kristerw /* separate buffer for fgetln() when line crosses buffer boundary */
133 1.70.8.2 kristerw struct __sbuf _lb; /* buffer for fgetln() */
134 1.70.8.2 kristerw
135 1.70.8.2 kristerw /* Unix stdio files get aligned to block boundaries on fseek() */
136 1.70.8.2 kristerw int _blksize; /* stat.st_blksize (may be != _bf._size) */
137 1.70.8.2 kristerw fpos_t _offset; /* current lseek offset */
138 1.70.8.2 kristerw } FILE;
139 1.70.8.2 kristerw
140 1.70.8.2 kristerw __BEGIN_DECLS
141 1.70.8.2 kristerw extern FILE __sF[];
142 1.70.8.2 kristerw __END_DECLS
143 1.70.8.2 kristerw
144 1.70.8.2 kristerw #define __SLBF 0x0001 /* line buffered */
145 1.70.8.2 kristerw #define __SNBF 0x0002 /* unbuffered */
146 1.70.8.2 kristerw #define __SRD 0x0004 /* OK to read */
147 1.70.8.2 kristerw #define __SWR 0x0008 /* OK to write */
148 1.70.8.2 kristerw /* RD and WR are never simultaneously asserted */
149 1.70.8.2 kristerw #define __SRW 0x0010 /* open for reading & writing */
150 1.70.8.2 kristerw #define __SEOF 0x0020 /* found EOF */
151 1.70.8.2 kristerw #define __SERR 0x0040 /* found error */
152 1.70.8.2 kristerw #define __SMBF 0x0080 /* _buf is from malloc */
153 1.70.8.2 kristerw #define __SAPP 0x0100 /* fdopen()ed in append mode */
154 1.70.8.2 kristerw #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
155 1.70.8.2 kristerw #define __SOPT 0x0400 /* do fseek() optimization */
156 1.70.8.2 kristerw #define __SNPT 0x0800 /* do not do fseek() optimization */
157 1.70.8.2 kristerw #define __SOFF 0x1000 /* set iff _offset is in fact correct */
158 1.70.8.2 kristerw #define __SMOD 0x2000 /* true => fgetln modified _p text */
159 1.70.8.2 kristerw #define __SALC 0x4000 /* allocate string space dynamically */
160 1.70.8.2 kristerw
161 1.70.8.2 kristerw /*
162 1.70.8.2 kristerw * The following three definitions are for ANSI C, which took them
163 1.70.8.2 kristerw * from System V, which brilliantly took internal interface macros and
164 1.70.8.2 kristerw * made them official arguments to setvbuf(), without renaming them.
165 1.70.8.2 kristerw * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
166 1.70.8.2 kristerw *
167 1.70.8.2 kristerw * Although numbered as their counterparts above, the implementation
168 1.70.8.2 kristerw * does not rely on this.
169 1.70.8.2 kristerw */
170 1.70.8.2 kristerw #define _IOFBF 0 /* setvbuf should set fully buffered */
171 1.70.8.2 kristerw #define _IOLBF 1 /* setvbuf should set line buffered */
172 1.70.8.2 kristerw #define _IONBF 2 /* setvbuf should set unbuffered */
173 1.70.8.2 kristerw
174 1.70.8.2 kristerw #define BUFSIZ 1024 /* size of buffer used by setbuf */
175 1.70.8.2 kristerw #define EOF (-1)
176 1.70.8.2 kristerw
177 1.70.8.2 kristerw /*
178 1.70.8.2 kristerw * FOPEN_MAX is a minimum maximum, and is the number of streams that
179 1.70.8.2 kristerw * stdio can provide without attempting to allocate further resources
180 1.70.8.2 kristerw * (which could fail). Do not use this for anything.
181 1.70.8.2 kristerw */
182 1.70.8.2 kristerw /* must be == _POSIX_STREAM_MAX <limits.h> */
183 1.70.8.2 kristerw #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */
184 1.70.8.2 kristerw #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */
185 1.70.8.2 kristerw
186 1.70.8.2 kristerw /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
187 1.70.8.2 kristerw #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
188 1.70.8.2 kristerw #define P_tmpdir "/var/tmp/"
189 1.70.8.2 kristerw #endif
190 1.70.8.2 kristerw #define L_tmpnam 1024 /* XXX must be == PATH_MAX */
191 1.70.8.2 kristerw /* Always ensure that this is consistent with <limits.h> */
192 1.70.8.2 kristerw #ifndef TMP_MAX
193 1.70.8.2 kristerw #define TMP_MAX 308915776 /* Legacy */
194 1.70.8.2 kristerw #endif
195 1.70.8.2 kristerw
196 1.70.8.2 kristerw /* Always ensure that these are consistent with <fcntl.h> and <unistd.h>! */
197 1.70.8.2 kristerw #ifndef SEEK_SET
198 1.70.8.2 kristerw #define SEEK_SET 0 /* set file offset to offset */
199 1.70.8.2 kristerw #endif
200 1.70.8.2 kristerw #ifndef SEEK_CUR
201 1.70.8.2 kristerw #define SEEK_CUR 1 /* set file offset to current plus offset */
202 1.70.8.2 kristerw #endif
203 1.70.8.2 kristerw #ifndef SEEK_END
204 1.70.8.2 kristerw #define SEEK_END 2 /* set file offset to EOF plus offset */
205 1.70.8.2 kristerw #endif
206 1.70.8.2 kristerw
207 1.70.8.2 kristerw #define stdin (&__sF[0])
208 1.70.8.2 kristerw #define stdout (&__sF[1])
209 1.70.8.2 kristerw #define stderr (&__sF[2])
210 1.70.8.2 kristerw
211 1.70.8.2 kristerw /*
212 1.70.8.2 kristerw * Functions defined in ANSI C standard.
213 1.70.8.2 kristerw */
214 1.70.8.2 kristerw __BEGIN_DECLS
215 1.70.8.2 kristerw void clearerr(FILE *);
216 1.70.8.2 kristerw int fclose(FILE *);
217 1.70.8.2 kristerw int feof(FILE *);
218 1.70.8.2 kristerw int ferror(FILE *);
219 1.70.8.2 kristerw int fflush(FILE *);
220 1.70.8.2 kristerw int fgetc(FILE *);
221 1.70.8.2 kristerw int fgetpos(FILE * __restrict, fpos_t * __restrict);
222 1.70.8.2 kristerw char *fgets(char * __restrict, int, FILE * __restrict);
223 1.70.8.2 kristerw FILE *fopen(const char * __restrict , const char * __restrict);
224 1.70.8.2 kristerw int fprintf(FILE * __restrict , const char * __restrict, ...);
225 1.70.8.2 kristerw int fputc(int, FILE *);
226 1.70.8.2 kristerw int fputs(const char * __restrict, FILE * __restrict);
227 1.70.8.2 kristerw size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
228 1.70.8.2 kristerw FILE *freopen(const char * __restrict, const char * __restrict,
229 1.70.8.2 kristerw FILE * __restrict);
230 1.70.8.2 kristerw int fscanf(FILE * __restrict, const char * __restrict, ...);
231 1.70.8.2 kristerw int fseek(FILE *, long, int);
232 1.70.8.2 kristerw int fsetpos(FILE *, const fpos_t *);
233 1.70.8.2 kristerw long ftell(FILE *);
234 1.70.8.2 kristerw size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
235 1.70.8.2 kristerw int getc(FILE *);
236 1.70.8.2 kristerw int getchar(void);
237 1.70.8.2 kristerw void perror(const char *);
238 1.70.8.2 kristerw int printf(const char * __restrict, ...);
239 1.70.8.2 kristerw int putc(int, FILE *);
240 1.70.8.2 kristerw int putchar(int);
241 1.70.8.2 kristerw int puts(const char *);
242 1.70.8.2 kristerw int remove(const char *);
243 1.70.8.2 kristerw void rewind(FILE *);
244 1.70.8.2 kristerw int scanf(const char * __restrict, ...);
245 1.70.8.2 kristerw void setbuf(FILE * __restrict, char * __restrict);
246 1.70.8.2 kristerw int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
247 1.70.8.2 kristerw int sscanf(const char * __restrict, const char * __restrict, ...);
248 1.70.8.2 kristerw FILE *tmpfile(void);
249 1.70.8.2 kristerw int ungetc(int, FILE *);
250 1.70.8.2 kristerw int vfprintf(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_);
251 1.70.8.2 kristerw int vprintf(const char * __restrict, _BSD_VA_LIST_);
252 1.70.8.2 kristerw
253 1.70.8.2 kristerw #ifndef __AUDIT__
254 1.70.8.2 kristerw char *gets(char *);
255 1.70.8.2 kristerw int sprintf(char * __restrict, const char * __restrict, ...);
256 1.70.8.2 kristerw char *tmpnam(char *);
257 1.70.8.2 kristerw int vsprintf(char * __restrict, const char * __restrict,
258 1.70.8.2 kristerw _BSD_VA_LIST_);
259 1.70.8.2 kristerw #endif
260 1.70.8.2 kristerw
261 1.70.8.2 kristerw #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
262 1.70.8.2 kristerw int rename (const char *, const char *) __RENAME(__posix_rename);
263 1.70.8.2 kristerw #else
264 1.70.8.2 kristerw int rename (const char *, const char *);
265 1.70.8.2 kristerw #endif
266 1.70.8.2 kristerw __END_DECLS
267 1.70.8.2 kristerw
268 1.70.8.2 kristerw /*
269 1.70.8.2 kristerw * IEEE Std 1003.1-90
270 1.70.8.2 kristerw */
271 1.70.8.2 kristerw #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
272 1.70.8.2 kristerw defined(_NETBSD_SOURCE)
273 1.70.8.2 kristerw #define L_ctermid 1024 /* size for ctermid(); PATH_MAX */
274 1.70.8.2 kristerw #define L_cuserid 9 /* size for cuserid(); UT_NAMESIZE + 1 */
275 1.70.8.2 kristerw
276 1.70.8.2 kristerw __BEGIN_DECLS
277 1.70.8.2 kristerw char *ctermid(char *);
278 1.70.8.2 kristerw #ifndef __CUSERID_DECLARED
279 1.70.8.2 kristerw #define __CUSERID_DECLARED
280 1.70.8.2 kristerw /* also declared in unistd.h */
281 1.70.8.2 kristerw char *cuserid(char *);
282 1.70.8.2 kristerw #endif /* __CUSERID_DECLARED */
283 1.70.8.2 kristerw FILE *fdopen(int, const char *);
284 1.70.8.2 kristerw int fileno(FILE *);
285 1.70.8.2 kristerw __END_DECLS
286 1.70.8.2 kristerw #endif /* not ANSI */
287 1.70.8.2 kristerw
288 1.70.8.2 kristerw /*
289 1.70.8.2 kristerw * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
290 1.70.8.2 kristerw */
291 1.70.8.2 kristerw #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
292 1.70.8.2 kristerw defined(_REENTRANT) || defined(_NETBSD_SOURCE)
293 1.70.8.2 kristerw __BEGIN_DECLS
294 1.70.8.2 kristerw void flockfile(FILE *);
295 1.70.8.2 kristerw int ftrylockfile(FILE *);
296 1.70.8.2 kristerw void funlockfile(FILE *);
297 1.70.8.2 kristerw int getc_unlocked(FILE *);
298 1.70.8.2 kristerw int getchar_unlocked(void);
299 1.70.8.2 kristerw int putc_unlocked(int, FILE *);
300 1.70.8.2 kristerw int putchar_unlocked(int);
301 1.70.8.2 kristerw __END_DECLS
302 1.70.8.2 kristerw #endif /* _POSIX_C_SOURCE >= 1995056 || _XOPEN_SOURCE >= 500 || ... */
303 1.70.8.2 kristerw
304 1.70.8.2 kristerw /*
305 1.70.8.2 kristerw * Functions defined in POSIX 1003.2 and XPG2 or later.
306 1.70.8.2 kristerw */
307 1.70.8.2 kristerw #if (_POSIX_C_SOURCE - 0) >= 2 || (_XOPEN_SOURCE - 0) >= 2 || \
308 1.70.8.2 kristerw defined(_NETBSD_SOURCE)
309 1.70.8.2 kristerw __BEGIN_DECLS
310 1.70.8.2 kristerw int pclose(FILE *);
311 1.70.8.2 kristerw FILE *popen(const char *, const char *);
312 1.70.8.2 kristerw __END_DECLS
313 1.70.8.2 kristerw #endif
314 1.70.8.2 kristerw
315 1.70.8.2 kristerw /*
316 1.70.8.2 kristerw * Functions defined in ISO XPG4.2, ISO C99, POSIX 1003.1-2001 or later.
317 1.70.8.2 kristerw */
318 1.70.8.2 kristerw #if ((__STDC_VERSION__ - 0) >= 199901L) || \
319 1.70.8.2 kristerw ((_POSIX_C_SOURCE - 0) >= 200112L) || \
320 1.70.8.2 kristerw (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
321 1.70.8.2 kristerw ((_XOPEN_SOURCE - 0) >= 500) || \
322 1.70.8.2 kristerw defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
323 1.70.8.2 kristerw __BEGIN_DECLS
324 1.70.8.2 kristerw int snprintf(char * __restrict, size_t, const char * __restrict, ...)
325 1.70.8.2 kristerw __attribute__((__format__(__printf__, 3, 4)));
326 1.70.8.2 kristerw int vsnprintf(char * __restrict, size_t, const char * __restrict,
327 1.70.8.2 kristerw _BSD_VA_LIST_)
328 1.70.8.2 kristerw __attribute__((__format__(__printf__, 3, 0)));
329 1.70.8.2 kristerw __END_DECLS
330 1.70.8.2 kristerw #endif
331 1.70.8.2 kristerw
332 1.70.8.2 kristerw /*
333 1.70.8.2 kristerw * Functions defined in XPG4.2.
334 1.70.8.2 kristerw */
335 1.70.8.2 kristerw #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
336 1.70.8.2 kristerw __BEGIN_DECLS
337 1.70.8.2 kristerw int getw(FILE *);
338 1.70.8.2 kristerw int putw(int, FILE *);
339 1.70.8.2 kristerw
340 1.70.8.2 kristerw #ifndef __AUDIT__
341 1.70.8.2 kristerw char *tempnam(const char *, const char *);
342 1.70.8.2 kristerw #endif
343 1.70.8.2 kristerw __END_DECLS
344 1.70.8.2 kristerw #endif
345 1.70.8.2 kristerw
346 1.70.8.2 kristerw /*
347 1.70.8.2 kristerw * X/Open CAE Specification Issue 5 Version 2
348 1.70.8.2 kristerw */
349 1.70.8.2 kristerw #if (_XOPEN_SOURCE - 0) >= 500 || defined(_LARGEFILE_SOURCE) || \
350 1.70.8.2 kristerw defined(_NETBSD_SOURCE)
351 1.70.8.2 kristerw #ifndef off_t
352 1.70.8.2 kristerw typedef __off_t off_t;
353 1.70.8.2 kristerw #define off_t __off_t
354 1.70.8.2 kristerw #endif /* off_t */
355 1.70.8.2 kristerw
356 1.70.8.2 kristerw __BEGIN_DECLS
357 1.70.8.2 kristerw int fseeko(FILE *, off_t, int);
358 1.70.8.2 kristerw off_t ftello(FILE *);
359 1.70.8.2 kristerw __END_DECLS
360 1.70.8.2 kristerw #endif /* _XOPEN_SOURCE >= 500 || _LARGEFILE_SOURCE || _NETBSD_SOURCE */
361 1.70.8.2 kristerw
362 1.70.8.2 kristerw /*
363 1.70.8.2 kristerw * Routines that are purely local.
364 1.70.8.2 kristerw */
365 1.70.8.2 kristerw #if defined(_NETBSD_SOURCE)
366 1.70.8.2 kristerw
367 1.70.8.2 kristerw #define FPARSELN_UNESCESC 0x01
368 1.70.8.2 kristerw #define FPARSELN_UNESCCONT 0x02
369 1.70.8.2 kristerw #define FPARSELN_UNESCCOMM 0x04
370 1.70.8.2 kristerw #define FPARSELN_UNESCREST 0x08
371 1.70.8.2 kristerw #define FPARSELN_UNESCALL 0x0f
372 1.70.8.2 kristerw
373 1.70.8.2 kristerw __BEGIN_DECLS
374 1.70.8.2 kristerw int asprintf(char ** __restrict, const char * __restrict, ...)
375 1.70.8.2 kristerw __attribute__((__format__(__printf__, 2, 3)));
376 1.70.8.2 kristerw char *fgetln(FILE * __restrict, size_t * __restrict);
377 1.70.8.2 kristerw char *fparseln(FILE *, size_t *, size_t *, const char[3], int);
378 1.70.8.2 kristerw int fpurge(FILE *);
379 1.70.8.2 kristerw void setbuffer(FILE *, char *, int);
380 1.70.8.2 kristerw int setlinebuf(FILE *);
381 1.70.8.2 kristerw int vasprintf(char ** __restrict, const char * __restrict,
382 1.70.8.2 kristerw _BSD_VA_LIST_)
383 1.70.8.2 kristerw __attribute__((__format__(__printf__, 2, 0)));
384 1.70.8.2 kristerw int vscanf(const char * __restrict, _BSD_VA_LIST_)
385 1.70.8.2 kristerw __attribute__((__format__(__scanf__, 1, 0)));
386 1.70.8.2 kristerw int vfscanf(FILE * __restrict, const char * __restrict,
387 1.70.8.2 kristerw _BSD_VA_LIST_)
388 1.70.8.2 kristerw __attribute__((__format__(__scanf__, 2, 0)));
389 1.70.8.2 kristerw int vsscanf(const char * __restrict, const char * __restrict,
390 1.70.8.2 kristerw _BSD_VA_LIST_)
391 1.70.8.2 kristerw __attribute__((__format__(__scanf__, 2, 0)));
392 1.70.8.2 kristerw const char *fmtcheck(const char *, const char *)
393 1.70.8.2 kristerw __attribute__((__format_arg__(2)));
394 1.70.8.2 kristerw __END_DECLS
395 1.70.8.2 kristerw
396 1.70.8.2 kristerw /*
397 1.70.8.2 kristerw * Stdio function-access interface.
398 1.70.8.2 kristerw */
399 1.70.8.2 kristerw __BEGIN_DECLS
400 1.70.8.2 kristerw FILE *funopen(const void *,
401 1.70.8.2 kristerw int (*)(void *, char *, int),
402 1.70.8.2 kristerw int (*)(void *, const char *, int),
403 1.70.8.2 kristerw fpos_t (*)(void *, fpos_t, int),
404 1.70.8.2 kristerw int (*)(void *));
405 1.70.8.2 kristerw __END_DECLS
406 1.70.8.2 kristerw #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
407 1.70.8.2 kristerw #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
408 1.70.8.2 kristerw #endif /* _NETBSD_SOURCE */
409 1.70.8.2 kristerw
410 1.70.8.2 kristerw /*
411 1.70.8.2 kristerw * Functions internal to the implementation.
412 1.70.8.2 kristerw */
413 1.70.8.2 kristerw __BEGIN_DECLS
414 1.70.8.2 kristerw int __srget(FILE *);
415 1.70.8.2 kristerw int __swbuf(int, FILE *);
416 1.70.8.2 kristerw __END_DECLS
417 1.70.8.2 kristerw
418 1.70.8.2 kristerw /*
419 1.70.8.2 kristerw * The __sfoo macros are here so that we can
420 1.70.8.2 kristerw * define function versions in the C library.
421 1.70.8.2 kristerw */
422 1.70.8.2 kristerw #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
423 1.70.8.2 kristerw #if defined(__GNUC__) && defined(__STDC__)
424 1.70.8.2 kristerw static __inline int __sputc(int _c, FILE *_p) {
425 1.70.8.2 kristerw if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
426 1.70.8.2 kristerw return (*_p->_p++ = _c);
427 1.70.8.2 kristerw else
428 1.70.8.2 kristerw return (__swbuf(_c, _p));
429 1.70.8.2 kristerw }
430 1.70.8.2 kristerw #else
431 1.70.8.2 kristerw /*
432 1.70.8.2 kristerw * This has been tuned to generate reasonable code on the vax using pcc.
433 1.70.8.2 kristerw */
434 1.70.8.2 kristerw #define __sputc(c, p) \
435 1.70.8.2 kristerw (--(p)->_w < 0 ? \
436 1.70.8.2 kristerw (p)->_w >= (p)->_lbfsize ? \
437 1.70.8.2 kristerw (*(p)->_p = (c)), *(p)->_p != '\n' ? \
438 1.70.8.2 kristerw (int)*(p)->_p++ : \
439 1.70.8.2 kristerw __swbuf('\n', p) : \
440 1.70.8.2 kristerw __swbuf((int)(c), p) : \
441 1.70.8.2 kristerw (*(p)->_p = (c), (int)*(p)->_p++))
442 1.70.8.2 kristerw #endif
443 1.70.8.2 kristerw
444 1.70.8.2 kristerw #define __sfeof(p) (((p)->_flags & __SEOF) != 0)
445 1.70.8.2 kristerw #define __sferror(p) (((p)->_flags & __SERR) != 0)
446 1.70.8.2 kristerw #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
447 1.70.8.2 kristerw #define __sfileno(p) ((p)->_file)
448 1.70.8.2 kristerw
449 1.70.8.2 kristerw #ifndef __lint__
450 1.70.8.2 kristerw #if !defined(_REENTRANT) && !defined(_PTHREADS)
451 1.70.8.2 kristerw #define feof(p) __sfeof(p)
452 1.70.8.2 kristerw #define ferror(p) __sferror(p)
453 1.70.8.2 kristerw #define clearerr(p) __sclearerr(p)
454 1.70.8.2 kristerw
455 1.70.8.2 kristerw #define getc(fp) __sgetc(fp)
456 1.70.8.2 kristerw #define putc(x, fp) __sputc(x, fp)
457 1.70.8.2 kristerw #endif /* !_REENTRANT && !_PTHREADS */
458 1.70.8.2 kristerw #endif /* __lint__ */
459 1.70.8.2 kristerw
460 1.70.8.2 kristerw #define getchar() getc(stdin)
461 1.70.8.2 kristerw #define putchar(x) putc(x, stdout)
462 1.70.8.2 kristerw
463 1.70.8.2 kristerw #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
464 1.70.8.2 kristerw defined(_NETBSD_SOURCE)
465 1.70.8.2 kristerw #if !defined(_REENTRANT) && !defined(_PTHREADS)
466 1.70.8.2 kristerw #define fileno(p) __sfileno(p)
467 1.70.8.2 kristerw #endif /* !_REENTRANT && !_PTHREADS */
468 1.70.8.2 kristerw #endif /* !_ANSI_SOURCE */
469 1.70.8.2 kristerw
470 1.70.8.2 kristerw #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
471 1.70.8.2 kristerw defined(_REENTRANT) || defined(_NETBSD_SOURCE)
472 1.70.8.2 kristerw #define getc_unlocked(fp) __sgetc(fp)
473 1.70.8.2 kristerw #define putc_unlocked(x, fp) __sputc(x, fp)
474 1.70.8.2 kristerw
475 1.70.8.2 kristerw #define getchar_unlocked() getc_unlocked(stdin)
476 1.70.8.2 kristerw #define putchar_unlocked(x) putc_unlocked(x, stdout)
477 1.70.8.2 kristerw #endif /* _POSIX_C_SOURCE >= 199506 || _XOPEN_SOURCE >= 500 || _REENTRANT... */
478 1.70.8.2 kristerw
479 1.70.8.2 kristerw #if _FORTIFY_SOURCE > 0
480 1.70.8.2 kristerw #include <ssp/stdio.h>
481 1.70.8.2 kristerw #endif
482 1.70.8.2 kristerw
483 1.70.8.2 kristerw #endif /* _STDIO_H_ */
484