1 | /*␊ |
2 | * Copyright (c) 2000, 2005, 2007, 2009, 2010 Apple Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | *␊ |
6 | * This file contains Original Code and/or Modifications of Original Code␊ |
7 | * as defined in and that are subject to the Apple Public Source License␊ |
8 | * Version 2.0 (the 'License'). You may not use this file except in␊ |
9 | * compliance with the License. Please obtain a copy of the License at␊ |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this␊ |
11 | * file.␊ |
12 | *␊ |
13 | * The Original Code and all software distributed under the License are␊ |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.␊ |
18 | * Please see the License for the specific language governing rights and␊ |
19 | * limitations under the License.␊ |
20 | *␊ |
21 | * @APPLE_LICENSE_HEADER_END@␊ |
22 | */␊ |
23 | /*-␊ |
24 | * Copyright (c) 1990, 1993␊ |
25 | *␉The Regents of the University of California. All rights reserved.␊ |
26 | *␊ |
27 | * This code is derived from software contributed to Berkeley by␊ |
28 | * Chris Torek.␊ |
29 | *␊ |
30 | * Redistribution and use in source and binary forms, with or without␊ |
31 | * modification, are permitted provided that the following conditions␊ |
32 | * are met:␊ |
33 | * 1. Redistributions of source code must retain the above copyright␊ |
34 | * notice, this list of conditions and the following disclaimer.␊ |
35 | * 2. Redistributions in binary form must reproduce the above copyright␊ |
36 | * notice, this list of conditions and the following disclaimer in the␊ |
37 | * documentation and/or other materials provided with the distribution.␊ |
38 | * 3. All advertising materials mentioning features or use of this software␊ |
39 | * must display the following acknowledgement:␊ |
40 | *␉This product includes software developed by the University of␊ |
41 | *␉California, Berkeley and its contributors.␊ |
42 | * 4. Neither the name of the University nor the names of its contributors␊ |
43 | * may be used to endorse or promote products derived from this software␊ |
44 | * without specific prior written permission.␊ |
45 | *␊ |
46 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND␊ |
47 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE␊ |
48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE␊ |
49 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE␊ |
50 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL␊ |
51 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS␊ |
52 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)␊ |
53 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT␊ |
54 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY␊ |
55 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF␊ |
56 | * SUCH DAMAGE.␊ |
57 | *␊ |
58 | *␉@(#)stdio.h␉8.5 (Berkeley) 4/29/95␊ |
59 | */␊ |
60 | ␊ |
61 | #ifndef␉_STDIO_H_␊ |
62 | #define␉_STDIO_H_␊ |
63 | ␊ |
64 | #include <sys/types.h>␊ |
65 | #include <sys/cdefs.h>␊ |
66 | #include <Availability.h>␊ |
67 | ␊ |
68 | #include <_types.h>␊ |
69 | ␊ |
70 | #ifndef _VA_LIST␊ |
71 | #define _VA_LIST␊ |
72 | /* DO NOT REMOVE THIS COMMENT: fixincludes needs to see:␊ |
73 | * __gnuc_va_list and include <stdarg.h> */␊ |
74 | typedef __darwin_va_list␉va_list;␊ |
75 | #endif␊ |
76 | ␊ |
77 | #ifndef␉_SIZE_T␊ |
78 | #define␉_SIZE_T␊ |
79 | typedef␉__darwin_size_t␉␉size_t;␊ |
80 | #endif␊ |
81 | ␊ |
82 | #ifndef NULL␊ |
83 | #define NULL __DARWIN_NULL␊ |
84 | #endif /* ! NULL */␊ |
85 | ␊ |
86 | typedef __darwin_off_t␉␉fpos_t;␊ |
87 | ␊ |
88 | #define␉_FSTDIO␉␉␉/* Define for new stdio with functions. */␊ |
89 | ␊ |
90 | /*␊ |
91 | * NB: to fit things in six character monocase externals, the stdio␊ |
92 | * code uses the prefix `__s' for stdio objects, typically followed␊ |
93 | * by a three-character attempt at a mnemonic.␊ |
94 | */␊ |
95 | ␊ |
96 | /* stdio buffers */␊ |
97 | struct __sbuf {␊ |
98 | ␉unsigned char␉*_base;␊ |
99 | ␉int␉␉_size;␊ |
100 | };␊ |
101 | ␊ |
102 | /* hold a buncha junk that would grow the ABI */␊ |
103 | struct __sFILEX;␊ |
104 | ␊ |
105 | /*␊ |
106 | * stdio state variables.␊ |
107 | *␊ |
108 | * The following always hold:␊ |
109 | *␊ |
110 | *␉if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),␊ |
111 | *␉␉_lbfsize is -_bf._size, else _lbfsize is 0␊ |
112 | *␉if _flags&__SRD, _w is 0␊ |
113 | *␉if _flags&__SWR, _r is 0␊ |
114 | *␊ |
115 | * This ensures that the getc and putc macros (or inline functions) never␊ |
116 | * try to write or read from a file that is in `read' or `write' mode.␊ |
117 | * (Moreover, they can, and do, automatically switch from read mode to␊ |
118 | * write mode, and back, on "r+" and "w+" files.)␊ |
119 | *␊ |
120 | * _lbfsize is used only to make the inline line-buffered output stream␊ |
121 | * code as compact as possible.␊ |
122 | *␊ |
123 | * _ub, _up, and _ur are used when ungetc() pushes back more characters␊ |
124 | * than fit in the current _bf, or when ungetc() pushes back a character␊ |
125 | * that does not match the previous one in _bf. When this happens,␊ |
126 | * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff␊ |
127 | * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.␊ |
128 | *␊ |
129 | * NB: see WARNING above before changing the layout of this structure!␊ |
130 | */␊ |
131 | typedef␉struct __sFILE {␊ |
132 | ␉unsigned char *_p;␉/* current position in (some) buffer */␊ |
133 | ␉int␉_r;␉␉/* read space left for getc() */␊ |
134 | ␉int␉_w;␉␉/* write space left for putc() */␊ |
135 | ␉short␉_flags;␉␉/* flags, below; this FILE is free if 0 */␊ |
136 | ␉short␉_file;␉␉/* fileno, if Unix descriptor, else -1 */␊ |
137 | ␉struct␉__sbuf _bf;␉/* the buffer (at least 1 byte, if !NULL) */␊ |
138 | ␉int␉_lbfsize;␉/* 0 or -_bf._size, for inline putc */␊ |
139 | ␉␊ |
140 | ␉/* operations */␊ |
141 | ␉void␉*_cookie;␉/* cookie passed to io functions */␊ |
142 | ␉int␉(*_close)(void *);␊ |
143 | ␉int␉(*_read) (void *, char *, int);␊ |
144 | ␉fpos_t␉(*_seek) (void *, fpos_t, int);␊ |
145 | ␉int␉(*_write)(void *, const char *, int);␊ |
146 | ␉␊ |
147 | ␉/* separate buffer for long sequences of ungetc() */␊ |
148 | ␉struct␉__sbuf _ub;␉/* ungetc buffer */␊ |
149 | ␉struct __sFILEX *_extra; /* additions to FILE to not break ABI */␊ |
150 | ␉int␉_ur;␉␉/* saved _r when _r is counting ungetc data */␊ |
151 | ␉␊ |
152 | ␉/* tricks to meet minimum requirements even when malloc() fails */␊ |
153 | ␉unsigned char _ubuf[3];␉/* guarantee an ungetc() buffer */␊ |
154 | ␉unsigned char _nbuf[1];␉/* guarantee a getc() buffer */␊ |
155 | ␉␊ |
156 | ␉/* separate buffer for fgetln() when line crosses buffer boundary */␊ |
157 | ␉struct␉__sbuf _lb;␉/* buffer for fgetln() */␊ |
158 | ␉␊ |
159 | ␉/* Unix stdio files get aligned to block boundaries on fseek() */␊ |
160 | ␉int␉_blksize;␉/* stat.st_blksize (may be != _bf._size) */␊ |
161 | ␉fpos_t␉_offset;␉/* current lseek offset (see WARNING) */␊ |
162 | } FILE;␊ |
163 | ␊ |
164 | __BEGIN_DECLS␊ |
165 | extern FILE *__stdinp;␊ |
166 | extern FILE *__stdoutp;␊ |
167 | extern FILE *__stderrp;␊ |
168 | __END_DECLS␊ |
169 | ␊ |
170 | #define␉__SLBF␉0x0001␉␉/* line buffered */␊ |
171 | #define␉__SNBF␉0x0002␉␉/* unbuffered */␊ |
172 | #define␉__SRD␉0x0004␉␉/* OK to read */␊ |
173 | #define␉__SWR␉0x0008␉␉/* OK to write */␊ |
174 | /* RD and WR are never simultaneously asserted */␊ |
175 | #define␉__SRW␉0x0010␉␉/* open for reading & writing */␊ |
176 | #define␉__SEOF␉0x0020␉␉/* found EOF */␊ |
177 | #define␉__SERR␉0x0040␉␉/* found error */␊ |
178 | #define␉__SMBF␉0x0080␉␉/* _buf is from malloc */␊ |
179 | #define␉__SAPP␉0x0100␉␉/* fdopen()ed in append mode */␊ |
180 | #define␉__SSTR␉0x0200␉␉/* this is an sprintf/snprintf string */␊ |
181 | #define␉__SOPT␉0x0400␉␉/* do fseek() optimisation */␊ |
182 | #define␉__SNPT␉0x0800␉␉/* do not do fseek() optimisation */␊ |
183 | #define␉__SOFF␉0x1000␉␉/* set iff _offset is in fact correct */␊ |
184 | #define␉__SMOD␉0x2000␉␉/* true => fgetln modified _p text */␊ |
185 | #define __SALC 0x4000␉␉/* allocate string space dynamically */␊ |
186 | #define __SIGN 0x8000␉␉/* ignore this file in _fwalk */␊ |
187 | ␊ |
188 | /*␊ |
189 | * The following three definitions are for ANSI C, which took them␊ |
190 | * from System V, which brilliantly took internal interface macros and␊ |
191 | * made them official arguments to setvbuf(), without renaming them.␊ |
192 | * Hence, these ugly _IOxxx names are *supposed* to appear in user code.␊ |
193 | *␊ |
194 | * Although numbered as their counterparts above, the implementation␊ |
195 | * does not rely on this.␊ |
196 | */␊ |
197 | #define␉_IOFBF␉0␉␉/* setvbuf should set fully buffered */␊ |
198 | #define␉_IOLBF␉1␉␉/* setvbuf should set line buffered */␊ |
199 | #define␉_IONBF␉2␉␉/* setvbuf should set unbuffered */␊ |
200 | ␊ |
201 | #define␉BUFSIZ␉1024␉␉/* size of buffer used by setbuf */␊ |
202 | #define␉EOF␉(-1)␊ |
203 | ␊ |
204 | /* must be == _POSIX_STREAM_MAX <limits.h> */␊ |
205 | #define␉FOPEN_MAX␉20␉/* must be <= OPEN_MAX <sys/syslimits.h> */␊ |
206 | #define␉FILENAME_MAX␉1024␉/* must be <= PATH_MAX <sys/syslimits.h> */␊ |
207 | ␊ |
208 | /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */␊ |
209 | #ifndef _ANSI_SOURCE␊ |
210 | #define␉P_tmpdir␉"/var/tmp/"␊ |
211 | #endif␊ |
212 | #define␉L_tmpnam␉1024␉/* XXX must be == PATH_MAX */␊ |
213 | #define␉TMP_MAX␉␉308915776␊ |
214 | ␊ |
215 | #ifndef SEEK_SET␊ |
216 | #define␉SEEK_SET␉0␉/* set file offset to offset */␊ |
217 | #endif␊ |
218 | #ifndef SEEK_CUR␊ |
219 | #define␉SEEK_CUR␉1␉/* set file offset to current plus offset */␊ |
220 | #endif␊ |
221 | #ifndef SEEK_END␊ |
222 | #define␉SEEK_END␉2␉/* set file offset to EOF plus offset */␊ |
223 | #endif␊ |
224 | ␊ |
225 | #define␉stdin␉__stdinp␊ |
226 | #define␉stdout␉__stdoutp␊ |
227 | #define␉stderr␉__stderrp␊ |
228 | ␊ |
229 | #ifdef _DARWIN_UNLIMITED_STREAMS␊ |
230 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_2␊ |
231 | #error "_DARWIN_UNLIMITED_STREAMS specified, but -miphoneos-version-min version does not support it."␊ |
232 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_6␊ |
233 | #error "_DARWIN_UNLIMITED_STREAMS specified, but -mmacosx-version-min version does not support it."␊ |
234 | #endif␊ |
235 | #endif␊ |
236 | ␊ |
237 | /* ANSI-C */␊ |
238 | ␊ |
239 | __BEGIN_DECLS␊ |
240 | int␉ fclose(FILE *);␊ |
241 | int␉ feof(FILE *);␊ |
242 | int␉ ferror(FILE *);␊ |
243 | int␉ fflush(FILE *);␊ |
244 | int␉ fgetc(FILE *);␊ |
245 | int␉ fgetpos(FILE * __restrict, fpos_t *);␊ |
246 | char *fgets(char * __restrict, int, FILE *);␊ |
247 | FILE␉*fopen(const char * __restrict, const char * __restrict) ;␊ |
248 | int␉ fprintf(FILE * __restrict, const char * __restrict, ...);␊ |
249 | int␉ fputc(int, FILE *);␊ |
250 | int␉ fputs(const char * __restrict, FILE * __restrict);␊ |
251 | size_t␉ fread(void * __restrict, size_t, size_t, FILE * __restrict);␊ |
252 | FILE␉*fdopen(int, const char *);␊ |
253 | ␊ |
254 | int␉ fscanf(FILE * __restrict, const char * __restrict, ...) __scanflike(2, 3);␊ |
255 | int␉ fseek(FILE *, long, int);␊ |
256 | int␉ fsetpos(FILE *, const fpos_t *);␊ |
257 | long␉ ftell(FILE *);␊ |
258 | size_t␉ fwrite(const void * __restrict, size_t, size_t, FILE * __restrict) ;␊ |
259 | ␊ |
260 | int␉ printf(const char * __restrict, ...) __printflike(1, 2);␊ |
261 | int␉ putc(int, FILE *);␊ |
262 | int putchar(int);␊ |
263 | void puts(const char *);␊ |
264 | int ungetc(int , FILE *);␊ |
265 | int ungetchar(int );␊ |
266 | int␉ sprintf(char * __restrict, const char * __restrict, ...) __printflike(2, 3);␊ |
267 | int␉ ungetc(int, FILE *);␊ |
268 | int␉ vfprintf(FILE * __restrict, const char * __restrict, va_list) __printflike(2, 0);␊ |
269 | __END_DECLS␊ |
270 | ␊ |
271 | /* Additional functionality provided by:␊ |
272 | * POSIX.1-1988␊ |
273 | */␊ |
274 | #if __DARWIN_C_LEVEL >= 198808L␊ |
275 | __BEGIN_DECLS␊ |
276 | int␉ fileno(FILE *);␊ |
277 | __END_DECLS␊ |
278 | #endif /* __DARWIN_C_LEVEL >= 198808L */␊ |
279 | ␊ |
280 | ␊ |
281 | /* Additional functionality provided by:␊ |
282 | * POSIX.1c-1995,␊ |
283 | * POSIX.1i-1995,␊ |
284 | * and the omnibus ISO/IEC 9945-1: 1996␊ |
285 | */␊ |
286 | ␊ |
287 | #if __DARWIN_C_LEVEL >= 199506L␊ |
288 | #define␉__sfeof(p)␉(((p)->_flags & __SEOF) != 0)␊ |
289 | #define␉__sferror(p)␉(((p)->_flags & __SERR) != 0)␊ |
290 | #define␉__sclearerr(p)␉((void)((p)->_flags &= ~(__SERR|__SEOF)))␊ |
291 | #define␉__sfileno(p)␉((p)->_file)␊ |
292 | #endif /* __DARWIN_C_LEVEL >= 199506L */␊ |
293 | ␊ |
294 | ␊ |
295 | ␊ |
296 | /* Additional functionality provided by:␊ |
297 | * POSIX.1-2001␊ |
298 | * ISO C99␊ |
299 | */␊ |
300 | ␊ |
301 | #if __DARWIN_C_LEVEL >= 200112L␊ |
302 | #ifndef␉_OFF_T␊ |
303 | #define␉_OFF_T␊ |
304 | typedef␉__darwin_off_t␉␉off_t;␊ |
305 | #endif␊ |
306 | ␊ |
307 | __BEGIN_DECLS␊ |
308 | int␉ fseeko(FILE *, off_t, int);␊ |
309 | off_t␉ ftello(FILE *);␊ |
310 | __END_DECLS␊ |
311 | #endif /* __DARWIN_C_LEVEL >= 200112L */␊ |
312 | ␊ |
313 | #if __DARWIN_C_LEVEL >= 200112L || defined(_C99_SOURCE) || defined(__cplusplus)␊ |
314 | __BEGIN_DECLS␊ |
315 | int␉ snprintf(char * __restrict, size_t, const char * __restrict, ...) __printflike(3, 4);␊ |
316 | int␉ vsnprintf(char * __restrict, size_t, const char * __restrict, va_list) __printflike(3, 0);␊ |
317 | __END_DECLS␊ |
318 | #endif /* __DARWIN_C_LEVEL >= 200112L || defined(_C99_SOURCE) || defined(__cplusplus) */␊ |
319 | ␊ |
320 | /* Additional functionality provided by:␊ |
321 | * POSIX.1-2008␊ |
322 | */␊ |
323 | ␊ |
324 | #if __DARWIN_C_LEVEL >= 200809L␊ |
325 | #ifndef _SSIZE_T␊ |
326 | #define _SSIZE_T␊ |
327 | typedef __darwin_ssize_t ssize_t;␊ |
328 | #endif␊ |
329 | ␊ |
330 | #endif /* __DARWIN_C_LEVEL >= 200809L */␊ |
331 | ␊ |
332 | ␊ |
333 | ␊ |
334 | /*␊ |
335 | * Stdio function-access interface.␊ |
336 | */␊ |
337 | #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL␊ |
338 | #define␉fileno_unlocked(p)␉__sfileno(p)␊ |
339 | #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */␊ |
340 | ␊ |
341 | ␊ |
342 | #endif /* _STDIO_H_ */␊ |
343 | |