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/cdefs.h>␊ |
65 | #include <Availability.h>␊ |
66 | ␊ |
67 | #include <_types.h>␊ |
68 | #include "saio_types.h"␊ |
69 | #include "platform.h"␊ |
70 | ␊ |
71 | ␊ |
72 | #ifndef _VA_LIST␊ |
73 | #define _VA_LIST␊ |
74 | /* DO NOT REMOVE THIS COMMENT: fixincludes needs to see:␊ |
75 | * __gnuc_va_list and include <stdarg.h> */␊ |
76 | typedef __darwin_va_list␉va_list;␊ |
77 | #endif␊ |
78 | ␊ |
79 | #ifndef␉_SIZE_T␊ |
80 | #define␉_SIZE_T␊ |
81 | typedef␉__darwin_size_t␉␉size_t;␊ |
82 | #endif␊ |
83 | ␊ |
84 | #ifndef NULL␊ |
85 | #define NULL __DARWIN_NULL␊ |
86 | #endif /* ! NULL */␊ |
87 | ␊ |
88 | typedef __darwin_off_t␉␉fpos_t;␊ |
89 | ␊ |
90 | #define␉_FSTDIO␉␉␉/* Define for new stdio with functions. */␊ |
91 | ␊ |
92 | /*␊ |
93 | * NB: to fit things in six character monocase externals, the stdio␊ |
94 | * code uses the prefix `__s' for stdio objects, typically followed␊ |
95 | * by a three-character attempt at a mnemonic.␊ |
96 | */␊ |
97 | ␊ |
98 | /* stdio buffers */␊ |
99 | struct __sbuf {␊ |
100 | ␉unsigned char␉*_base;␊ |
101 | ␉int␉␉_size;␊ |
102 | };␊ |
103 | ␊ |
104 | /* hold a buncha junk that would grow the ABI */␊ |
105 | struct __sFILEX;␊ |
106 | ␊ |
107 | /*␊ |
108 | * stdio state variables.␊ |
109 | *␊ |
110 | * The following always hold:␊ |
111 | *␊ |
112 | *␉if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),␊ |
113 | *␉␉_lbfsize is -_bf._size, else _lbfsize is 0␊ |
114 | *␉if _flags&__SRD, _w is 0␊ |
115 | *␉if _flags&__SWR, _r is 0␊ |
116 | *␊ |
117 | * This ensures that the getc and putc macros (or inline functions) never␊ |
118 | * try to write or read from a file that is in `read' or `write' mode.␊ |
119 | * (Moreover, they can, and do, automatically switch from read mode to␊ |
120 | * write mode, and back, on "r+" and "w+" files.)␊ |
121 | *␊ |
122 | * _lbfsize is used only to make the inline line-buffered output stream␊ |
123 | * code as compact as possible.␊ |
124 | *␊ |
125 | * _ub, _up, and _ur are used when ungetc() pushes back more characters␊ |
126 | * than fit in the current _bf, or when ungetc() pushes back a character␊ |
127 | * that does not match the previous one in _bf. When this happens,␊ |
128 | * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff␊ |
129 | * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.␊ |
130 | *␊ |
131 | * NB: see WARNING above before changing the layout of this structure!␊ |
132 | */␊ |
133 | typedef␉struct __sFILE {␊ |
134 | ␉unsigned char *_p;␉/* current position in (some) buffer */␊ |
135 | ␉int␉_r;␉␉/* read space left for getc() */␊ |
136 | ␉int␉_w;␉␉/* write space left for putc() */␊ |
137 | ␉short␉_flags;␉␉/* flags, below; this FILE is free if 0 */␊ |
138 | ␉short␉_file;␉␉/* fileno, if Unix descriptor, else -1 */␊ |
139 | ␉struct␉__sbuf _bf;␉/* the buffer (at least 1 byte, if !NULL) */␊ |
140 | ␉int␉_lbfsize;␉/* 0 or -_bf._size, for inline putc */␊ |
141 | ␉␊ |
142 | ␉/* operations */␊ |
143 | ␉void␉*_cookie;␉/* cookie passed to io functions */␊ |
144 | ␉int␉(*_close)(void *);␊ |
145 | ␉int␉(*_read) (void *, char *, int);␊ |
146 | ␉fpos_t␉(*_seek) (void *, fpos_t, int);␊ |
147 | ␉int␉(*_write)(void *, const char *, int);␊ |
148 | ␉␊ |
149 | ␉/* separate buffer for long sequences of ungetc() */␊ |
150 | ␉struct␉__sbuf _ub;␉/* ungetc buffer */␊ |
151 | ␉struct __sFILEX *_extra; /* additions to FILE to not break ABI */␊ |
152 | ␉int␉_ur;␉␉/* saved _r when _r is counting ungetc data */␊ |
153 | ␉␊ |
154 | ␉/* tricks to meet minimum requirements even when malloc() fails */␊ |
155 | ␉unsigned char _ubuf[3];␉/* guarantee an ungetc() buffer */␊ |
156 | ␉unsigned char _nbuf[1];␉/* guarantee a getc() buffer */␊ |
157 | ␉␊ |
158 | ␉/* separate buffer for fgetln() when line crosses buffer boundary */␊ |
159 | ␉struct␉__sbuf _lb;␉/* buffer for fgetln() */␊ |
160 | ␉␊ |
161 | ␉/* Unix stdio files get aligned to block boundaries on fseek() */␊ |
162 | ␉int␉_blksize;␉/* stat.st_blksize (may be != _bf._size) */␊ |
163 | ␉fpos_t␉_offset;␉/* current lseek offset (see WARNING) */␊ |
164 | } FILE;␊ |
165 | ␊ |
166 | ␊ |
167 | ␊ |
168 | __BEGIN_DECLS␊ |
169 | extern FILE *__stdinp;␊ |
170 | extern FILE *__stdoutp;␊ |
171 | extern FILE *__stderrp;␊ |
172 | __END_DECLS␊ |
173 | ␊ |
174 | #define␉__SLBF␉0x0001␉␉/* line buffered */␊ |
175 | #define␉__SNBF␉0x0002␉␉/* unbuffered */␊ |
176 | #define␉__SRD␉0x0004␉␉/* OK to read */␊ |
177 | #define␉__SWR␉0x0008␉␉/* OK to write */␊ |
178 | /* RD and WR are never simultaneously asserted */␊ |
179 | #define␉__SRW␉0x0010␉␉/* open for reading & writing */␊ |
180 | #define␉__SEOF␉0x0020␉␉/* found EOF */␊ |
181 | #define␉__SERR␉0x0040␉␉/* found error */␊ |
182 | #define␉__SMBF␉0x0080␉␉/* _buf is from malloc */␊ |
183 | #define␉__SAPP␉0x0100␉␉/* fdopen()ed in append mode */␊ |
184 | #define␉__SSTR␉0x0200␉␉/* this is an sprintf/snprintf string */␊ |
185 | #define␉__SOPT␉0x0400␉␉/* do fseek() optimisation */␊ |
186 | #define␉__SNPT␉0x0800␉␉/* do not do fseek() optimisation */␊ |
187 | #define␉__SOFF␉0x1000␉␉/* set iff _offset is in fact correct */␊ |
188 | #define␉__SMOD␉0x2000␉␉/* true => fgetln modified _p text */␊ |
189 | #define __SALC 0x4000␉␉/* allocate string space dynamically */␊ |
190 | #define __SIGN 0x8000␉␉/* ignore this file in _fwalk */␊ |
191 | ␊ |
192 | /*␊ |
193 | * The following three definitions are for ANSI C, which took them␊ |
194 | * from System V, which brilliantly took internal interface macros and␊ |
195 | * made them official arguments to setvbuf(), without renaming them.␊ |
196 | * Hence, these ugly _IOxxx names are *supposed* to appear in user code.␊ |
197 | *␊ |
198 | * Although numbered as their counterparts above, the implementation␊ |
199 | * does not rely on this.␊ |
200 | */␊ |
201 | #define␉_IOFBF␉0␉␉/* setvbuf should set fully buffered */␊ |
202 | #define␉_IOLBF␉1␉␉/* setvbuf should set line buffered */␊ |
203 | #define␉_IONBF␉2␉␉/* setvbuf should set unbuffered */␊ |
204 | ␊ |
205 | #define␉BUFSIZ␉1024␉␉/* size of buffer used by setbuf */␊ |
206 | #define␉EOF␉(-1)␊ |
207 | ␊ |
208 | /* must be == _POSIX_STREAM_MAX <limits.h> */␊ |
209 | #define␉FOPEN_MAX␉20␉/* must be <= OPEN_MAX <sys/syslimits.h> */␊ |
210 | #define␉FILENAME_MAX␉1024␉/* must be <= PATH_MAX <sys/syslimits.h> */␊ |
211 | ␊ |
212 | /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */␊ |
213 | #ifndef _ANSI_SOURCE␊ |
214 | #define␉P_tmpdir␉"/var/tmp/"␊ |
215 | #endif␊ |
216 | #define␉L_tmpnam␉1024␉/* XXX must be == PATH_MAX */␊ |
217 | #define␉TMP_MAX␉␉308915776␊ |
218 | ␊ |
219 | #ifndef SEEK_SET␊ |
220 | #define␉SEEK_SET␉0␉/* set file offset to offset */␊ |
221 | #endif␊ |
222 | #ifndef SEEK_CUR␊ |
223 | #define␉SEEK_CUR␉1␉/* set file offset to current plus offset */␊ |
224 | #endif␊ |
225 | #ifndef SEEK_END␊ |
226 | #define␉SEEK_END␉2␉/* set file offset to EOF plus offset */␊ |
227 | #endif␊ |
228 | ␊ |
229 | #define␉stdin␉__stdinp␊ |
230 | #define␉stdout␉__stdoutp␊ |
231 | #define␉stderr␉__stderrp␊ |
232 | ␊ |
233 | #ifdef _DARWIN_UNLIMITED_STREAMS␊ |
234 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_2␊ |
235 | #error "_DARWIN_UNLIMITED_STREAMS specified, but -miphoneos-version-min version does not support it."␊ |
236 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_6␊ |
237 | #error "_DARWIN_UNLIMITED_STREAMS specified, but -mmacosx-version-min version does not support it."␊ |
238 | #endif␊ |
239 | #endif␊ |
240 | ␊ |
241 | #define␉ STDIN_FILENO␉0␉/* standard input file descriptor */␊ |
242 | #define␉STDOUT_FILENO␉1␉/* standard output file descriptor */␊ |
243 | #define␉STDERR_FILENO␉2␉/* standard error file descriptor */␊ |
244 | ␊ |
245 | /* ANSI-C */␊ |
246 | ␊ |
247 | __BEGIN_DECLS␊ |
248 | int␉ fclose(FILE *);␊ |
249 | int␉ feof(FILE *);␊ |
250 | int␉ ferror(FILE *);␊ |
251 | int␉ fflush(FILE *);␊ |
252 | int␉ fgetc(FILE *);␊ |
253 | int␉ fgetpos(FILE * __restrict, fpos_t *);␊ |
254 | char *fgets(char * __restrict, int, FILE *);␊ |
255 | FILE␉*fopen(const char * __restrict, const char * __restrict) ;␊ |
256 | ␊ |
257 | int␉ fprintf(FILE * __restrict, const char * __restrict, ...);␊ |
258 | int␉ fputc(int, FILE *);␊ |
259 | ␊ |
260 | int␉ fputs(const char * __restrict, FILE * __restrict);␊ |
261 | ␊ |
262 | size_t␉ fread(void * __restrict, size_t, size_t, FILE * __restrict);␊ |
263 | ␊ |
264 | FILE␉*freopen(const char * __restrict, const char * __restrict,␊ |
265 | FILE * __restrict);␊ |
266 | FILE␉*fdopen(int, const char *);␊ |
267 | ␊ |
268 | int␉ fscanf(FILE * __restrict, const char * __restrict, ...) __scanflike(2, 3);␊ |
269 | int␉ fseek(FILE *, long, int);␊ |
270 | int␉ fsetpos(FILE *, const fpos_t *);␊ |
271 | long␉ ftell(FILE *);␊ |
272 | size_t␉ fwrite(const void * __restrict, size_t, size_t, FILE * __restrict) ;␊ |
273 | ␊ |
274 | void puts(const char *);␊ |
275 | int ungetc(int , FILE *);␊ |
276 | int ungetchar(int );␊ |
277 | ␊ |
278 | extern FILE *stdin;␊ |
279 | extern FILE *stdout;␊ |
280 | extern FILE *stderr;␊ |
281 | int␉ fseeko(FILE *, off_t, int);␊ |
282 | off_t␉ ftello(FILE *);␊ |
283 | int␊ |
284 | vfprintf(FILE *fp, const char *fmt0, va_list ap);␊ |
285 | __END_DECLS␊ |
286 | ␊ |
287 | /* Additional functionality provided by:␊ |
288 | * POSIX.1-1988␊ |
289 | */␊ |
290 | ␊ |
291 | ␊ |
292 | /* Additional functionality provided by:␊ |
293 | * POSIX.1c-1995,␊ |
294 | * POSIX.1i-1995,␊ |
295 | * and the omnibus ISO/IEC 9945-1: 1996␊ |
296 | */␊ |
297 | ␊ |
298 | //#if __DARWIN_C_LEVEL >= 199506L␊ |
299 | ␊ |
300 | ␊ |
301 | #define␉__sfeof(p)␉(((p)->_flags & __SEOF) != 0)␊ |
302 | #define␉__sferror(p)␉(((p)->_flags & __SERR) != 0)␊ |
303 | #define␉__sclearerr(p)␉((void)((p)->_flags &= ~(__SERR|__SEOF)))␊ |
304 | #define␉__sfileno(p)␉((p)->_file)␊ |
305 | ␊ |
306 | ␊ |
307 | ␊ |
308 | ␊ |
309 | //#endif /* __DARWIN_C_LEVEL >= 199506L */␊ |
310 | ␊ |
311 | ␊ |
312 | ␊ |
313 | /* Additional functionality provided by:␊ |
314 | * POSIX.1-2001␊ |
315 | * ISO C99␊ |
316 | */␊ |
317 | ␊ |
318 | #if __DARWIN_C_LEVEL >= 200112L␊ |
319 | #ifndef␉_OFF_T␊ |
320 | #define␉_OFF_T␊ |
321 | typedef␉__darwin_off_t␉␉off_t;␊ |
322 | #endif␊ |
323 | #endif /* __DARWIN_C_LEVEL >= 200112L */␊ |
324 | ␊ |
325 | /* Additional functionality provided by:␊ |
326 | * POSIX.1-2008␊ |
327 | */␊ |
328 | ␊ |
329 | #if __DARWIN_C_LEVEL >= 200809L␊ |
330 | #ifndef _SSIZE_T␊ |
331 | #define _SSIZE_T␊ |
332 | typedef __darwin_ssize_t ssize_t;␊ |
333 | #endif␊ |
334 | ␊ |
335 | #endif /* __DARWIN_C_LEVEL >= 200809L */␊ |
336 | ␊ |
337 | ␊ |
338 | ␊ |
339 | ␊ |
340 | ␊ |
341 | ␊ |
342 | ␊ |
343 | ␊ |
344 | #endif /* _STDIO_H_ */␊ |
345 | |