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 <_stdio.h> |
65 | |
66 | __BEGIN_DECLS |
67 | extern FILE *__stdinp; |
68 | extern FILE *__stdoutp; |
69 | extern FILE *__stderrp; |
70 | __END_DECLS |
71 | |
72 | #define __SLBF 0x0001 /* line buffered */ |
73 | #define __SNBF 0x0002 /* unbuffered */ |
74 | #define __SRD 0x0004 /* OK to read */ |
75 | #define __SWR 0x0008 /* OK to write */ |
76 | /* RD and WR are never simultaneously asserted */ |
77 | #define __SRW 0x0010 /* open for reading & writing */ |
78 | #define __SEOF 0x0020 /* found EOF */ |
79 | #define __SERR 0x0040 /* found error */ |
80 | #define __SMBF 0x0080 /* _buf is from malloc */ |
81 | #define __SAPP 0x0100 /* fdopen()ed in append mode */ |
82 | #define __SSTR 0x0200 /* this is an sprintf/snprintf string */ |
83 | #define __SOPT 0x0400 /* do fseek() optimisation */ |
84 | #define __SNPT 0x0800 /* do not do fseek() optimisation */ |
85 | #define __SOFF 0x1000 /* set iff _offset is in fact correct */ |
86 | #define __SMOD 0x2000 /* true => fgetln modified _p text */ |
87 | #define __SALC 0x4000 /* allocate string space dynamically */ |
88 | #define __SIGN 0x8000 /* ignore this file in _fwalk */ |
89 | |
90 | /* |
91 | * The following three definitions are for ANSI C, which took them |
92 | * from System V, which brilliantly took internal interface macros and |
93 | * made them official arguments to setvbuf(), without renaming them. |
94 | * Hence, these ugly _IOxxx names are *supposed* to appear in user code. |
95 | * |
96 | * Although numbered as their counterparts above, the implementation |
97 | * does not rely on this. |
98 | */ |
99 | #define _IOFBF 0 /* setvbuf should set fully buffered */ |
100 | #define _IOLBF 1 /* setvbuf should set line buffered */ |
101 | #define _IONBF 2 /* setvbuf should set unbuffered */ |
102 | |
103 | #define BUFSIZ 1024 /* size of buffer used by setbuf */ |
104 | #define EOF (-1) |
105 | |
106 | /* must be == _POSIX_STREAM_MAX <limits.h> */ |
107 | #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ |
108 | #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ |
109 | |
110 | /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ |
111 | #ifndef _ANSI_SOURCE |
112 | #define P_tmpdir "/var/tmp/" |
113 | #endif |
114 | #define L_tmpnam 1024 /* XXX must be == PATH_MAX */ |
115 | #define TMP_MAX 308915776 |
116 | |
117 | #ifndef SEEK_SET |
118 | #define SEEK_SET 0 /* set file offset to offset */ |
119 | #endif |
120 | #ifndef SEEK_CUR |
121 | #define SEEK_CUR 1 /* set file offset to current plus offset */ |
122 | #endif |
123 | #ifndef SEEK_END |
124 | #define SEEK_END 2 /* set file offset to EOF plus offset */ |
125 | #endif |
126 | |
127 | #define stdin __stdinp |
128 | #define stdout __stdoutp |
129 | #define stderr __stderrp |
130 | |
131 | #ifdef _DARWIN_UNLIMITED_STREAMS |
132 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_2 |
133 | #error "_DARWIN_UNLIMITED_STREAMS specified, but -miphoneos-version-min version does not support it." |
134 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_6 |
135 | #error "_DARWIN_UNLIMITED_STREAMS specified, but -mmacosx-version-min version does not support it." |
136 | #endif |
137 | #endif |
138 | |
139 | /* ANSI-C */ |
140 | |
141 | __BEGIN_DECLS |
142 | void clearerr(FILE *); |
143 | int fclose(FILE *); |
144 | int feof(FILE *); |
145 | int ferror(FILE *); |
146 | int fflush(FILE *); |
147 | int fgetc(FILE *); |
148 | int fgetpos(FILE * __restrict, fpos_t *); |
149 | char *fgets(char * __restrict, int, FILE *); |
150 | #if defined(_DARWIN_UNLIMITED_STREAMS) || defined(_DARWIN_C_SOURCE) |
151 | FILE *fopen(const char * __restrict __filename, const char * __restrict __mode) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_3_2, __DARWIN_EXTSN(fopen)); |
152 | #else /* !_DARWIN_UNLIMITED_STREAMS && !_DARWIN_C_SOURCE */ |
153 | FILE *fopen(const char * __restrict __filename, const char * __restrict __mode) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fopen)); |
154 | #endif /* (DARWIN_UNLIMITED_STREAMS || _DARWIN_C_SOURCE) */ |
155 | int fprintf(FILE * __restrict, const char * __restrict, ...) __printflike(2, 3); |
156 | int fputc(int, FILE *); |
157 | int fputs(const char * __restrict, FILE * __restrict) __DARWIN_ALIAS(fputs); |
158 | size_t fread(void * __restrict __ptr, size_t __size, size_t __nitems, FILE * __restrict __stream); |
159 | FILE *freopen(const char * __restrict, const char * __restrict, |
160 | FILE * __restrict) __DARWIN_ALIAS(freopen); |
161 | int fscanf(FILE * __restrict, const char * __restrict, ...) __scanflike(2, 3); |
162 | int fseek(FILE *, long, int); |
163 | int fsetpos(FILE *, const fpos_t *); |
164 | long ftell(FILE *); |
165 | size_t fwrite(const void * __restrict __ptr, size_t __size, size_t __nitems, FILE * __restrict __stream) __DARWIN_ALIAS(fwrite); |
166 | int getc(FILE *); |
167 | int getchar(void); |
168 | char *gets(char *); |
169 | void perror(const char *); |
170 | int printf(const char * __restrict, ...) __printflike(1, 2); |
171 | int putc(int, FILE *); |
172 | int putchar(int); |
173 | int puts(const char *); |
174 | int remove(const char *); |
175 | int rename (const char *__old, const char *__new); |
176 | void rewind(FILE *); |
177 | int scanf(const char * __restrict, ...) __scanflike(1, 2); |
178 | void setbuf(FILE * __restrict, char * __restrict); |
179 | int setvbuf(FILE * __restrict, char * __restrict, int, size_t); |
180 | int sprintf(char * __restrict, const char * __restrict, ...) __printflike(2, 3) __swift_unavailable("Use snprintf instead." ); |
181 | int sscanf(const char * __restrict, const char * __restrict, ...) __scanflike(2, 3); |
182 | FILE *tmpfile(void); |
183 | |
184 | __swift_unavailable("Use mkstemp(3) instead." ) |
185 | #if !defined(_POSIX_C_SOURCE) |
186 | __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tmpnam(3), it is highly recommended that you use mkstemp(3) instead." ) |
187 | #endif |
188 | char *tmpnam(char *); |
189 | int ungetc(int, FILE *); |
190 | int vfprintf(FILE * __restrict, const char * __restrict, va_list) __printflike(2, 0); |
191 | int vprintf(const char * __restrict, va_list) __printflike(1, 0); |
192 | int vsprintf(char * __restrict, const char * __restrict, va_list) __printflike(2, 0) __swift_unavailable("Use vsnprintf instead." ); |
193 | __END_DECLS |
194 | |
195 | |
196 | |
197 | /* Additional functionality provided by: |
198 | * POSIX.1-1988 |
199 | */ |
200 | |
201 | #if __DARWIN_C_LEVEL >= 198808L |
202 | #define L_ctermid 1024 /* size for ctermid(); PATH_MAX */ |
203 | |
204 | __BEGIN_DECLS |
205 | #ifndef __CTERMID_DEFINED |
206 | /* Multiply defined in stdio.h and unistd.h by SUS */ |
207 | #define __CTERMID_DEFINED 1 |
208 | char *ctermid(char *); |
209 | #endif |
210 | |
211 | #if defined(_DARWIN_UNLIMITED_STREAMS) || defined(_DARWIN_C_SOURCE) |
212 | FILE *fdopen(int, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_3_2, __DARWIN_EXTSN(fdopen)); |
213 | #else /* !_DARWIN_UNLIMITED_STREAMS && !_DARWIN_C_SOURCE */ |
214 | FILE *fdopen(int, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fdopen)); |
215 | #endif /* (DARWIN_UNLIMITED_STREAMS || _DARWIN_C_SOURCE) */ |
216 | int fileno(FILE *); |
217 | __END_DECLS |
218 | #endif /* __DARWIN_C_LEVEL >= 198808L */ |
219 | |
220 | |
221 | /* Additional functionality provided by: |
222 | * POSIX.2-1992 C Language Binding Option |
223 | */ |
224 | #if TARGET_OS_EMBEDDED |
225 | #define __swift_unavailable_on(osx_msg, ios_msg) __swift_unavailable(ios_msg) |
226 | #else |
227 | #define __swift_unavailable_on(osx_msg, ios_msg) __swift_unavailable(osx_msg) |
228 | #endif |
229 | |
230 | #if __DARWIN_C_LEVEL >= 199209L |
231 | __BEGIN_DECLS |
232 | int pclose(FILE *) __swift_unavailable_on("Use posix_spawn APIs or NSTask instead." , "Process spawning is unavailable." ); |
233 | #if defined(_DARWIN_UNLIMITED_STREAMS) || defined(_DARWIN_C_SOURCE) |
234 | FILE *popen(const char *, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_3_2, __DARWIN_EXTSN(popen)) __swift_unavailable_on("Use posix_spawn APIs or NSTask instead." , "Process spawning is unavailable." ); |
235 | #else /* !_DARWIN_UNLIMITED_STREAMS && !_DARWIN_C_SOURCE */ |
236 | FILE *popen(const char *, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(popen)) __swift_unavailable_on("Use posix_spawn APIs or NSTask instead." , "Process spawning is unavailable." ); |
237 | #endif /* (DARWIN_UNLIMITED_STREAMS || _DARWIN_C_SOURCE) */ |
238 | __END_DECLS |
239 | #endif /* __DARWIN_C_LEVEL >= 199209L */ |
240 | |
241 | #undef __swift_unavailable_on |
242 | |
243 | /* Additional functionality provided by: |
244 | * POSIX.1c-1995, |
245 | * POSIX.1i-1995, |
246 | * and the omnibus ISO/IEC 9945-1: 1996 |
247 | */ |
248 | |
249 | #if __DARWIN_C_LEVEL >= 199506L |
250 | |
251 | /* Functions internal to the implementation. */ |
252 | __BEGIN_DECLS |
253 | int __srget(FILE *); |
254 | int __svfscanf(FILE *, const char *, va_list) __scanflike(2, 0); |
255 | int __swbuf(int, FILE *); |
256 | __END_DECLS |
257 | |
258 | /* |
259 | * The __sfoo macros are here so that we can |
260 | * define function versions in the C library. |
261 | */ |
262 | #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) |
263 | #if defined(__GNUC__) && defined(__STDC__) |
264 | __header_always_inline int __sputc(int _c, FILE *_p) { |
265 | if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) |
266 | return (*_p->_p++ = _c); |
267 | else |
268 | return (__swbuf(_c, _p)); |
269 | } |
270 | #else |
271 | /* |
272 | * This has been tuned to generate reasonable code on the vax using pcc. |
273 | */ |
274 | #define __sputc(c, p) \ |
275 | (--(p)->_w < 0 ? \ |
276 | (p)->_w >= (p)->_lbfsize ? \ |
277 | (*(p)->_p = (c)), *(p)->_p != '\n' ? \ |
278 | (int)*(p)->_p++ : \ |
279 | __swbuf('\n', p) : \ |
280 | __swbuf((int)(c), p) : \ |
281 | (*(p)->_p = (c), (int)*(p)->_p++)) |
282 | #endif |
283 | |
284 | #define __sfeof(p) (((p)->_flags & __SEOF) != 0) |
285 | #define __sferror(p) (((p)->_flags & __SERR) != 0) |
286 | #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) |
287 | #define __sfileno(p) ((p)->_file) |
288 | |
289 | __BEGIN_DECLS |
290 | void flockfile(FILE *); |
291 | int ftrylockfile(FILE *); |
292 | void funlockfile(FILE *); |
293 | int getc_unlocked(FILE *); |
294 | int getchar_unlocked(void); |
295 | int putc_unlocked(int, FILE *); |
296 | int putchar_unlocked(int); |
297 | |
298 | /* Removed in Issue 6 */ |
299 | #if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200112L |
300 | int getw(FILE *); |
301 | int putw(int, FILE *); |
302 | #endif |
303 | |
304 | __swift_unavailable("Use mkstemp(3) instead." ) |
305 | #if !defined(_POSIX_C_SOURCE) |
306 | __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead." ) |
307 | #endif |
308 | char *tempnam(const char *__dir, const char *__prefix) __DARWIN_ALIAS(tempnam); |
309 | __END_DECLS |
310 | |
311 | #ifndef lint |
312 | #define getc_unlocked(fp) __sgetc(fp) |
313 | #define putc_unlocked(x, fp) __sputc(x, fp) |
314 | #endif /* lint */ |
315 | |
316 | #define getchar_unlocked() getc_unlocked(stdin) |
317 | #define putchar_unlocked(x) putc_unlocked(x, stdout) |
318 | #endif /* __DARWIN_C_LEVEL >= 199506L */ |
319 | |
320 | |
321 | |
322 | /* Additional functionality provided by: |
323 | * POSIX.1-2001 |
324 | * ISO C99 |
325 | */ |
326 | |
327 | #if __DARWIN_C_LEVEL >= 200112L |
328 | #include <sys/_types/_off_t.h> |
329 | |
330 | __BEGIN_DECLS |
331 | int fseeko(FILE * __stream, off_t __offset, int __whence); |
332 | off_t ftello(FILE * __stream); |
333 | __END_DECLS |
334 | #endif /* __DARWIN_C_LEVEL >= 200112L */ |
335 | |
336 | #if __DARWIN_C_LEVEL >= 200112L || defined(_C99_SOURCE) || defined(__cplusplus) |
337 | __BEGIN_DECLS |
338 | int snprintf(char * __restrict __str, size_t __size, const char * __restrict __format, ...) __printflike(3, 4); |
339 | int vfscanf(FILE * __restrict __stream, const char * __restrict __format, va_list) __scanflike(2, 0); |
340 | int vscanf(const char * __restrict __format, va_list) __scanflike(1, 0); |
341 | int vsnprintf(char * __restrict __str, size_t __size, const char * __restrict __format, va_list) __printflike(3, 0); |
342 | int vsscanf(const char * __restrict __str, const char * __restrict __format, va_list) __scanflike(2, 0); |
343 | __END_DECLS |
344 | #endif /* __DARWIN_C_LEVEL >= 200112L || defined(_C99_SOURCE) || defined(__cplusplus) */ |
345 | |
346 | |
347 | |
348 | /* Additional functionality provided by: |
349 | * POSIX.1-2008 |
350 | */ |
351 | |
352 | #if __DARWIN_C_LEVEL >= 200809L |
353 | #include <sys/_types/_ssize_t.h> |
354 | |
355 | __BEGIN_DECLS |
356 | int dprintf(int, const char * __restrict, ...) __printflike(2, 3) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3); |
357 | int vdprintf(int, const char * __restrict, va_list) __printflike(2, 0) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3); |
358 | ssize_t getdelim(char ** __restrict __linep, size_t * __restrict __linecapp, int __delimiter, FILE * __restrict __stream) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3); |
359 | ssize_t getline(char ** __restrict __linep, size_t * __restrict __linecapp, FILE * __restrict __stream) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3); |
360 | FILE *fmemopen(void * __restrict __buf, size_t __size, const char * __restrict __mode) __API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)); |
361 | FILE *open_memstream(char **__bufp, size_t *__sizep) __API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)); |
362 | __END_DECLS |
363 | #endif /* __DARWIN_C_LEVEL >= 200809L */ |
364 | |
365 | |
366 | |
367 | /* Darwin extensions */ |
368 | |
369 | #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL |
370 | __BEGIN_DECLS |
371 | extern __const int sys_nerr; /* perror(3) external variables */ |
372 | extern __const char *__const sys_errlist[]; |
373 | |
374 | int asprintf(char ** __restrict, const char * __restrict, ...) __printflike(2, 3); |
375 | char *ctermid_r(char *); |
376 | char *fgetln(FILE *, size_t *); |
377 | __const char *fmtcheck(const char *, const char *); |
378 | int fpurge(FILE *); |
379 | void setbuffer(FILE *, char *, int); |
380 | int setlinebuf(FILE *); |
381 | int vasprintf(char ** __restrict, const char * __restrict, va_list) __printflike(2, 0); |
382 | FILE *zopen(const char *, const char *, int); |
383 | |
384 | |
385 | /* |
386 | * Stdio function-access interface. |
387 | */ |
388 | FILE *funopen(const void *, |
389 | int (* _Nullable)(void *, char *, int), |
390 | int (* _Nullable)(void *, const char *, int), |
391 | fpos_t (* _Nullable)(void *, fpos_t, int), |
392 | int (* _Nullable)(void *)); |
393 | __END_DECLS |
394 | #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) |
395 | #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) |
396 | |
397 | #define feof_unlocked(p) __sfeof(p) |
398 | #define ferror_unlocked(p) __sferror(p) |
399 | #define clearerr_unlocked(p) __sclearerr(p) |
400 | #define fileno_unlocked(p) __sfileno(p) |
401 | |
402 | #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ |
403 | |
404 | |
405 | #ifdef _USE_EXTENDED_LOCALES_ |
406 | #include <xlocale/_stdio.h> |
407 | #endif /* _USE_EXTENDED_LOCALES_ */ |
408 | |
409 | #if defined (__GNUC__) && _FORTIFY_SOURCE > 0 && !defined (__cplusplus) |
410 | /* Security checking functions. */ |
411 | #include <secure/_stdio.h> |
412 | #endif |
413 | |
414 | #endif /* _STDIO_H_ */ |
415 | |