]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/Include/stdio.h
Standard Libraries for EDK II.
[mirror_edk2.git] / StdLib / Include / stdio.h
1 /*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)stdio.h 8.5 (Berkeley) 4/29/95
33 */
34 /* $NetBSD: stdio.h,v 1.66.2.3 2007/08/24 20:07:38 liamjfoy Exp $ */
35
36 #ifndef _STDIO_H_
37 #define _STDIO_H_
38
39 #include <sys/EfiCdefs.h>
40 #include <limits.h>
41 #include <sys/ansi.h>
42 #include <machine/ansi.h>
43
44 #ifdef _EFI_SIZE_T_
45 typedef _EFI_SIZE_T_ size_t;
46 #undef _EFI_SIZE_T_
47 #endif
48
49 /*
50 * This is fairly grotesque, but pure ANSI code must not inspect the
51 * innards of an fpos_t anyway. The library internally uses off_t,
52 * which we assume is exactly as big as eight chars.
53 */
54 #if (!defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)) || defined(_LIBC)
55 typedef __off_t fpos_t;
56 #else
57 typedef struct __sfpos {
58 __off_t _pos;
59 } fpos_t;
60 #endif
61
62 #define _FSTDIO /* Define for new stdio with functions. */
63
64 /*
65 * NB: to fit things in six character monocase externals, the stdio
66 * code uses the prefix `__s' for stdio objects, typically followed
67 * by a three-character attempt at a mnemonic.
68 */
69
70 /* stdio buffers */
71 struct __sbuf {
72 unsigned char *_base;
73 int _size;
74 };
75
76 /*
77 * stdio state variables.
78 *
79 * The following always hold:
80 *
81 * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
82 * _lbfsize is -_bf._size, else _lbfsize is 0
83 * if _flags&__SRD, _w is 0
84 * if _flags&__SWR, _r is 0
85 *
86 * This ensures that the getc and putc macros (or inline functions) never
87 * try to write or read from a file that is in `read' or `write' mode.
88 * (Moreover, they can, and do, automatically switch from read mode to
89 * write mode, and back, on "r+" and "w+" files.)
90 *
91 * _lbfsize is used only to make the inline line-buffered output stream
92 * code as compact as possible.
93 *
94 * _ub, _up, and _ur are used when ungetc() pushes back more characters
95 * than fit in the current _bf, or when ungetc() pushes back a character
96 * that does not match the previous one in _bf. When this happens,
97 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
98 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
99 *
100 * NB: see WARNING above before changing the layout of this structure!
101 */
102 typedef struct __sFILE {
103 unsigned char *_p; /* current position in (some) buffer */
104 int _r; /* read space left for getc() */
105 int _w; /* write space left for putc() */
106 unsigned short _flags; /* flags, below; this FILE is free if 0 */
107 short _file; /* fileno, if Unix descriptor, else -1 */
108 struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
109 int _lbfsize; /* 0 or -_bf._size, for inline putc */
110
111 /* operations */
112 void *_cookie; /* cookie passed to io functions */
113 int (*_close)(void *);
114 int (*_read) (void *, char *, int);
115 fpos_t (*_seek) (void *, fpos_t, int);
116 int (*_write)(void *, const char *, int);
117
118 /* file extension */
119 struct __sbuf _ext;
120
121 /* separate buffer for long sequences of ungetc() */
122 unsigned char *_up; /* saved _p when _p is doing ungetc data */
123 int _ur; /* saved _r when _r is counting ungetc data */
124
125 /* tricks to meet minimum requirements even when malloc() fails */
126 unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
127 unsigned char _nbuf[1]; /* guarantee a getc() buffer */
128
129 /* separate buffer for fgetln() when line crosses buffer boundary */
130 struct __sbuf _lb; /* buffer for fgetln() */
131
132 /* Unix stdio files get aligned to block boundaries on fseek() */
133 int _blksize; /* stat.st_blksize (may be != _bf._size) */
134 fpos_t _offset; /* current lseek offset */
135 } FILE;
136
137 __BEGIN_DECLS
138 extern FILE __sF[];
139 __END_DECLS
140
141 #define __SLBF 0x0001 /* line buffered */
142 #define __SNBF 0x0002 /* unbuffered */
143 #define __SRD 0x0004 /* OK to read */
144 #define __SWR 0x0008 /* OK to write */
145 /* RD and WR are never simultaneously asserted */
146 #define __SRW 0x0010 /* open for reading & writing */
147 #define __SEOF 0x0020 /* found EOF */
148 #define __SERR 0x0040 /* found error */
149 #define __SMBF 0x0080 /* _buf is from malloc */
150 #define __SAPP 0x0100 /* fdopen()ed in append mode */
151 #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
152 #define __SOPT 0x0400 /* do fseek() optimization */
153 #define __SNPT 0x0800 /* do not do fseek() optimization */
154 #define __SOFF 0x1000 /* set iff _offset is in fact correct */
155 #define __SMOD 0x2000 /* true => fgetln modified _p text */
156 #define __SALC 0x4000 /* allocate string space dynamically */
157
158 /*
159 * The following three definitions are for ANSI C, which took them
160 * from System V, which brilliantly took internal interface macros and
161 * made them official arguments to setvbuf(), without renaming them.
162 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
163 *
164 * Although numbered as their counterparts above, the implementation
165 * does not rely on this.
166 */
167 #define _IOFBF 0 /* setvbuf should set fully buffered */
168 #define _IOLBF 1 /* setvbuf should set line buffered */
169 #define _IONBF 2 /* setvbuf should set unbuffered */
170
171 #define BUFSIZ 1024 /* size of buffer used by setbuf */
172 #define EOF (-1)
173
174 /*
175 * FOPEN_MAX is a minimum maximum, and is the number of streams that
176 * stdio can provide without attempting to allocate further resources
177 * (which could fail). Do not use this for anything.
178 */
179 #define FOPEN_MAX OPEN_MAX /* must be <= OPEN_MAX <sys/syslimits.h> */
180 #define FILENAME_MAX PATH_MAX /* must be <= PATH_MAX <sys/syslimits.h> */
181
182 #define L_tmpnam PATH_MAX /* must be == PATH_MAX */
183
184 #ifndef TMP_MAX
185 #define TMP_MAX 308915776 /* Legacy */
186 #endif
187
188 /* Always ensure that these are consistent with <fcntl.h>! */
189 #ifndef SEEK_SET
190 #define SEEK_SET 0 /* set file offset to offset */
191 #endif
192 #ifndef SEEK_CUR
193 #define SEEK_CUR 1 /* set file offset to current plus offset */
194 #endif
195 #ifndef SEEK_END
196 #define SEEK_END 2 /* set file offset to EOF plus offset */
197 #endif
198
199 #define stdin (&__sF[0])
200 #define stdout (&__sF[1])
201 #define stderr (&__sF[2])
202
203 /*
204 * Functions defined in ANSI C standard.
205 */
206 __BEGIN_DECLS
207 void clearerr(FILE *);
208 int fclose (FILE *);
209 int feof (FILE *);
210 int ferror (FILE *);
211 int fflush (FILE *);
212 int fgetc (FILE *);
213 int fgetpos (FILE * __restrict, fpos_t * __restrict);
214 char *fgets (char * __restrict, int, FILE * __restrict);
215 FILE *fopen (const char * __restrict , const char * __restrict);
216
217 /** The fprintf function writes output to the stream pointed to by stream,
218 under control of the string pointed to by format that specifies how
219 subsequent arguments are converted for output. If there are insufficient
220 arguments for the format, the behavior is undefined. If the format is
221 exhausted while arguments remain, the excess arguments are evaluated
222 (as always) but are otherwise ignored. The fprintf function returns when
223 the end of the format string is encountered.
224
225 The format shall be a multibyte character sequence, beginning and ending in
226 its initial shift state. The format is composed of zero or more directives:
227 ordinary multibyte characters (not %), which are copied unchanged to the
228 output stream; and conversion specifications, each of which results in
229 fetching zero or more subsequent arguments, converting them, if applicable,
230 according to the corresponding conversion specifier, and then writing the
231 result to the output stream.
232
233 Each conversion specification is introduced by the character %. After
234 the %, the following appear in sequence:
235 - Zero or more flags (in any order) that modify the meaning of the
236 conversion specification.
237 - An optional minimum field width. If the converted value has fewer
238 characters than the field width, it is padded with spaces (by default)
239 on the left (or right, if the left adjustment flag, described later,
240 has been given) to the field width. The field width takes the form of
241 an asterisk * (described later) or a nonnegative decimal integer.
242 - An optional precision that gives the minimum number of digits to appear
243 for the d, i, o, u, x, and X conversions, the number of digits to
244 appear after the decimal-point character for e, E, f, and F
245 conversions, the maximum number of significant digits for the g and G
246 conversions, or the maximum number of bytes to be written for s
247 conversions. The precision takes the form of a period (.) followed
248 either by an asterisk * (described later) or by an optional decimal
249 integer; if only the period is specified, the precision is taken as
250 zero. If a precision appears with any other conversion specifier, the
251 behavior is undefined.
252 - An optional length modifier that specifies the size of the argument.
253 - A conversion specifier character that specifies the type of conversion
254 to be applied.
255
256 As noted above, a field width, or precision, or both, may be indicated by
257 an asterisk. In this case, an int argument supplies the field width or
258 precision. The arguments specifying field width, or precision, or both, shall
259 appear (in that order) before the argument (if any) to be converted. A negative
260 field width argument is taken as a - flag followed by a positive field width.
261 A negative precision argument is taken as if the precision were omitted.
262
263 The flag characters and their meanings are:
264 - The result of the conversion is left-justified within the field.
265 (It is right-justified if this flag is not specified.)
266 + The result of a signed conversion always begins with a plus or
267 minus sign. (It begins with a sign only when a negative value is
268 converted if this flag is not specified.)
269 space If the first character of a signed conversion is not a sign, or
270 if a signed conversion results in no characters, a space is
271 prefixed to the result. If the space and + flags both appear, the
272 space flag is ignored.
273 # The result is converted to an "alternative form". For o
274 conversion, it increases the precision, if and only if necessary,
275 to force the first digit of the result to be a zero (if the value
276 and precision are both 0, a single 0 is printed). For x (or X)
277 conversion, a nonzero result has 0x (or 0X) prefixed to it. For e,
278 E, f, F, g, and G conversions, the result of converting a
279 floating-point number always contains a decimal-point character,
280 even if no digits follow it. (Normally, a decimal-point character
281 appears in the result of these conversions only if a digit follows
282 it.) For g and G conversions, trailing zeros are not removed from
283 the result. For other conversions, the behavior is undefined.
284 0 For d, i, o, u, x, X, e, E, f, F, g, and G conversions, leading
285 zeros (following any indication of sign or base) are used to pad to
286 the field width rather than performing space padding, except when
287 converting an infinity or NaN. If the 0 and - flags both appear,
288 the 0 flag is ignored. For d, i, o, u, x, and X conversions, if a
289 precision is specified, the 0 flag is ignored. For other
290 conversions, the behavior is undefined.
291
292 The length modifiers and their meanings are:
293 hh Specifies that a following d, i, o, u, x, or X conversion specifier
294 applies to a signed char or unsigned char argument (the argument
295 will have been promoted according to the integer promotions, but
296 its value shall be converted to signed char or unsigned char before
297 printing); or that a following n conversion specifier applies to a
298 pointer to a signed char argument.
299 h Specifies that a following d, i, o, u, x, or X conversion specifier
300 applies to a short int or unsigned short int argument (the argument
301 will have been promoted according to the integer promotions, but
302 its value shall be converted to short int or unsigned short int
303 before printing); or that a following n conversion specifier
304 applies to a pointer to a short int argument.
305 l (ell) Specifies that a following d, i, o, u, x, or X conversion
306 specifier applies to a long int or unsigned long int argument; that
307 a following n conversion specifier applies to a pointer to a long
308 int argument; that a following c conversion specifier applies to a
309 wint_t argument; that a following s conversion specifier applies to
310 a pointer to a wchar_t argument; or has no effect on a following e,
311 E, f, F, g, or G conversion specifier.
312 ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion
313 specifier applies to a long long int or unsigned long long int
314 argument; or that a following n conversion specifier applies to a
315 pointer to a long long int argument.
316 j Specifies that a following d, i, o, u, x, or X conversion specifier
317 applies to an intmax_t or uintmax_t argument; or that a following n
318 conversion specifier applies to a pointer to an intmax_t argument.
319 z Specifies that a following d, i, o, u, x, or X conversion specifier
320 applies to a size_t or the corresponding signed integer type
321 argument; or that a following n conversion specifier applies to a
322 pointer to a signed integer type corresponding to size_t argument.
323 t Specifies that a following d, i, o, u, x, or X conversion specifier
324 applies to a ptrdiff_t or the corresponding unsigned integer type
325 argument; or that a following n conversion specifier applies to a
326 pointer to a ptrdiff_t argument.
327 L Specifies that a following e, E, f, F, g, or G conversion specifier
328 applies to a long double argument.
329
330 If a length modifier appears with any conversion specifier other than as
331 specified above, the behavior is undefined.
332
333 The conversion specifiers and their meanings are:
334 d,i The int argument is converted to signed decimal in the style
335 [-]dddd. The precision specifies the minimum number of digits to
336 appear; if the value being converted can be represented in fewer
337 digits, it is expanded with leading zeros. The default precision
338 is 1. The result of converting a zero value with a precision of
339 zero is no characters.
340 o,u,x,X The unsigned int argument is converted to unsigned octal (o),
341 unsigned decimal (u), or unsigned hexadecimal notation (x or X) in
342 the style dddd; the letters abcdef are used for x conversion and
343 the letters ABCDEF for X conversion. The precision specifies the
344 minimum number of digits to appear; if the value being converted
345 can be represented in fewer digits, it is expanded with leading
346 zeros. The default precision is 1. The result of converting a zero
347 value with a precision of zero is no characters.
348 f,F A double argument representing a floating-point number is
349 converted to decimal notation in the style [-]ddd.ddd, where the
350 number of digits after the decimal-point character is equal to the
351 precision specification. If the precision is missing, it is taken
352 as 6; if the precision is zero and the # flag is not specified, no
353 decimal-point character appears. If a decimal-point character
354 appears, at least one digit appears before it. The value is rounded
355 to the appropriate number of digits.
356 A double argument representing an infinity is converted in one
357 of the styles [-]inf or [-]infinity - which style is
358 implementation-defined. A double argument representing a NaN is
359 converted in one of the styles [-]nan or [-]nan(n-char-sequence)
360 - which style, and the meaning of any n-char-sequence, is
361 implementation-defined. The F conversion specifier produces INF,
362 INFINITY, or NAN instead of inf, infinity, or nan, respectively.
363 e,E A double argument representing a floating-point number is
364 converted in the style [-]d.ddd e[+-]dd, where there is one digit
365 (which is nonzero if the argument is nonzero) before the
366 decimal-point character and the number of digits after it is equal
367 to the precision; if the precision is missing, it is taken as 6; if
368 the precision is zero and the # flag is not specified, no
369 decimal-point character appears. The value is rounded to the
370 appropriate number of digits. The E conversion specifier produces a
371 number with E instead of e introducing the exponent. The exponent
372 always contains at least two digits, and only as many more digits
373 as necessary to represent the exponent. If the value is zero, the
374 exponent is zero.
375 A double argument representing an infinity or NaN is converted
376 in the style of an f or F conversion specifier.
377 g,G A double argument representing a floating-point number is
378 converted in style f or e (or in style F or E in the case of a G
379 conversion specifier), depending on the value converted and the
380 precision. Let P equal the precision if nonzero, 6 if the precision
381 is omitted, or 1 if the precision is zero. Then, if a conversion
382 with style E would have an exponent of X:
383 - if P > X = -4, the conversion is with style f (or F) and
384 precision P - (X + 1).
385 - otherwise, the conversion is with style e (or E) and
386 precision P - 1.
387
388 Finally, unless the # flag is used, any trailing zeros are removed
389 from the fractional portion of the result and the decimal-point
390 character is removed if there is no fractional portion remaining.
391 A double argument representing an infinity or NaN is converted in
392 the style of an f or F conversion specifier.
393 c If no l length modifier is present, the int argument is
394 converted to an unsigned char, and the resulting character is
395 written. If an l length modifier is present, the wint_t argument is
396 converted as if by an ls conversion specification with no precision
397 and an argument that points to the initial element of a two-element
398 array of wchar_t, the first element containing the wint_t argument
399 to the lc conversion specification and the second a null wide
400 character.
401 s If no l length modifier is present, the argument is a pointer
402 to the initial element of an array of character type. Characters
403 from the array are written up to (but not including) the
404 terminating null character. If the precision is specified, no more
405 than that many bytes are written. If the precision is not specified
406 or is greater than the size of the array, the array shall contain a
407 null character.
408 If an l length modifier is present, the argument shall be a
409 pointer to the initial element of an array of wchar_t type. Wide
410 characters from the array are converted to multibyte characters
411 (each as if by a call to the wcrtomb function, with the conversion
412 state described by an mbstate_t object initialized to zero before
413 the first wide character is converted) up to and including a
414 terminating null wide character. The resulting multibyte characters
415 are written up to (but not including) the terminating null
416 character (byte). If no precision is specified, the array shall
417 contain a null wide character. If a precision is specified, no more
418 than that many bytes are written (including shift sequences, if
419 any), and the array shall contain a null wide character if, to
420 equal the multibyte character sequence length given by the
421 precision, the function would need to access a wide character one
422 past the end of the array. In no case is a partial multibyte
423 character written.
424 p The argument shall be a pointer to void. The value of the
425 pointer is converted to a sequence of printing characters, in an
426 implementation-defined manner.
427 n The argument shall be a pointer to signed integer into which is
428 written the number of characters written to the output stream so
429 far by this call to fprintf. No argument is converted, but one is
430 consumed. If the conversion specification includes any flags, a
431 field width, or a precision, the behavior is undefined.
432 % A % character is written. No argument is converted. The
433 complete conversion specification shall be %%.
434
435 In no case does a nonexistent or small field width cause truncation of a
436 field; if the result of a conversion is wider than the field width, the
437 field is expanded to contain the conversion result.
438
439 @param[in] stream An open File specifier to which the output is sent.
440 @param[in] format A multi-byte character sequence containing characters
441 to be copied unchanged, and conversion specifiers
442 which convert their associated arguments. Copied and
443 converted characters are sent to the output stream.
444 @param ... Variable number of parameters as required by format.
445
446 @return The fprintf function returns the number of characters
447 transmitted, or a negative value if an output or encoding
448 error occurred.
449
450 **/
451 int fprintf (FILE * __restrict stream, const char * __restrict format, ...);
452
453 int fputc (int, FILE *);
454 int fputs (const char * __restrict, FILE * __restrict);
455 size_t fread (void * __restrict, size_t, size_t, FILE * __restrict);
456 FILE *freopen (const char * __restrict, const char * __restrict, FILE * __restrict);
457 int fscanf (FILE * __restrict, const char * __restrict, ...);
458 int fseek (FILE *, long, int);
459 int fsetpos (FILE *, const fpos_t *);
460 long ftell (FILE *);
461 size_t fwrite (const void * __restrict, size_t, size_t, FILE * __restrict);
462 int getc (FILE *);
463 int getchar (void);
464 void perror (const char *);
465 int printf (const char * __restrict, ...);
466 int putc (int, FILE *);
467 int putchar (int);
468 int puts (const char *);
469 int remove (const char *);
470 void rewind (FILE *);
471 int scanf (const char * __restrict, ...);
472 void setbuf (FILE * __restrict, char * __restrict);
473 int setvbuf (FILE * __restrict, char * __restrict, int, size_t);
474 int sscanf (const char * __restrict, const char * __restrict, ...);
475 FILE *tmpfile (void);
476 int ungetc (int, FILE *);
477 int vfprintf(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_);
478 int vprintf (const char * __restrict, _BSD_VA_LIST_);
479
480 #ifndef __AUDIT__
481 char *gets (char *);
482 int sprintf (char * __restrict, const char * __restrict, ...);
483 char *tmpnam (char *);
484 int vsprintf(char * __restrict, const char * __restrict, _BSD_VA_LIST_);
485 #endif
486
487 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
488 int rename (const char *, const char *) __RENAME(__posix_rename);
489 #else
490 int rename (const char *, const char *);
491 #endif
492 __END_DECLS
493
494 /*
495 * IEEE Std 1003.1-90
496 */
497 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
498 defined(_NETBSD_SOURCE)
499 #define L_ctermid 1024 /* size for ctermid(); PATH_MAX */
500 #define L_cuserid 9 /* size for cuserid(); UT_NAMESIZE + 1 */
501
502 __BEGIN_DECLS
503 char *ctermid(char *);
504 #ifndef __CUSERID_DECLARED
505 #define __CUSERID_DECLARED
506 /* also declared in unistd.h */
507 char *cuserid(char *);
508 #endif /* __CUSERID_DECLARED */
509 FILE *fdopen(int, const char *);
510 int fileno(FILE *);
511 __END_DECLS
512 #endif /* not ANSI */
513
514 /*
515 * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
516 */
517 #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
518 defined(_REENTRANT) || defined(_NETBSD_SOURCE)
519 __BEGIN_DECLS
520 void flockfile (FILE *);
521 int ftrylockfile (FILE *);
522 void funlockfile (FILE *);
523 int getc_unlocked (FILE *);
524 int getchar_unlocked(void);
525 int putc_unlocked (int, FILE *);
526 int putchar_unlocked(int);
527 __END_DECLS
528 #endif /* _POSIX_C_SOURCE >= 1995056 || _XOPEN_SOURCE >= 500 || ... */
529
530 /*
531 * Functions defined in POSIX 1003.2 and XPG2 or later.
532 */
533 #if (_POSIX_C_SOURCE - 0) >= 2 || (_XOPEN_SOURCE - 0) >= 2 || \
534 defined(_NETBSD_SOURCE)
535 __BEGIN_DECLS
536 int pclose (FILE *);
537 FILE *popen (const char *, const char *);
538 __END_DECLS
539 #endif
540
541 /*
542 * Functions defined in ISO XPG4.2, ISO C99, POSIX 1003.1-2001 or later.
543 */
544 #if ((__STDC_VERSION__ - 0) >= 199901L) || \
545 ((_POSIX_C_SOURCE - 0) >= 200112L) || \
546 (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
547 ((_XOPEN_SOURCE - 0) >= 500) || \
548 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
549 __BEGIN_DECLS
550 int snprintf (char * __restrict, size_t, const char * __restrict, ...)
551 __attribute__((__format__(__printf__, 3, 4)));
552 int vsnprintf(char * __restrict, size_t, const char * __restrict, _BSD_VA_LIST_)
553 __attribute__((__format__(__printf__, 3, 0)));
554 __END_DECLS
555 #endif
556
557 /*
558 * Functions defined in XPG4.2.
559 */
560 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
561 __BEGIN_DECLS
562 int getw(FILE *);
563 int putw(int, FILE *);
564 char *mkdtemp(char *);
565 int mkstemp(char *);
566 char *mktemp(char *);
567
568 #ifndef __AUDIT__
569 char *tempnam(const char *, const char *);
570 #endif
571 __END_DECLS
572 #endif
573
574 /*
575 * X/Open CAE Specification Issue 5 Version 2
576 */
577 #ifndef off_t
578 typedef __off_t off_t;
579 #define off_t __off_t
580 #endif /* off_t */
581
582 __BEGIN_DECLS
583 int fseeko(FILE *, off_t, int);
584 off_t ftello(FILE *);
585 __END_DECLS
586
587 /*
588 * Routines that are purely local.
589 */
590 #if defined(_NETBSD_SOURCE)
591
592 #define FPARSELN_UNESCESC 0x01
593 #define FPARSELN_UNESCCONT 0x02
594 #define FPARSELN_UNESCCOMM 0x04
595 #define FPARSELN_UNESCREST 0x08
596 #define FPARSELN_UNESCALL 0x0f
597
598 __BEGIN_DECLS
599 //int asprintf(char ** __restrict, const char * __restrict, ...)
600 // __attribute__((__format__(__printf__, 2, 3)));
601 char *fgetln(FILE * __restrict, size_t * __restrict);
602 char *fparseln(FILE *, size_t *, size_t *, const char[3], int);
603 int fpurge(FILE *);
604 void setbuffer(FILE *, char *, int);
605 int setlinebuf(FILE *);
606 int vasprintf(char ** __restrict, const char * __restrict,
607 _BSD_VA_LIST_)
608 __attribute__((__format__(__printf__, 2, 0)));
609 int vscanf(const char * __restrict, _BSD_VA_LIST_)
610 __attribute__((__format__(__scanf__, 1, 0)));
611 int vfscanf(FILE * __restrict, const char * __restrict,
612 _BSD_VA_LIST_)
613 __attribute__((__format__(__scanf__, 2, 0)));
614 int vsscanf(const char * __restrict, const char * __restrict,
615 _BSD_VA_LIST_)
616 __attribute__((__format__(__scanf__, 2, 0)));
617 const char *fmtcheck(const char *, const char *)
618 __attribute__((__format_arg__(2)));
619 __END_DECLS
620
621 /*
622 * Stdio function-access interface.
623 */
624 __BEGIN_DECLS
625 FILE *funopen(const void *,
626 int (*)(void *, char *, int),
627 int (*)(void *, const char *, int),
628 fpos_t (*)(void *, fpos_t, int),
629 int (*)(void *));
630 __END_DECLS
631 //#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
632 //#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
633 #endif /* _NETBSD_SOURCE */
634
635 /*
636 * Functions internal to the implementation.
637 */
638 __BEGIN_DECLS
639 int __srget(FILE *);
640 int __swbuf(int, FILE *);
641 __END_DECLS
642
643 /*
644 * The __sfoo macros are here so that we can
645 * define function versions in the C library.
646 */
647 #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
648 #if defined(__GNUC__) && defined(__STDC__)
649 static __inline int __sputc(int _c, FILE *_p) {
650 if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
651 return (*_p->_p++ = _c);
652 else
653 return (__swbuf(_c, _p));
654 }
655 #else
656 /*
657 * This has been tuned to generate reasonable code on the vax using pcc.
658 */
659 #define __sputc(c, p) \
660 (--(p)->_w < 0 ? \
661 (p)->_w >= (p)->_lbfsize ? \
662 (*(p)->_p = (unsigned char)(c)), *(p)->_p != '\n' ? \
663 (int)*(p)->_p++ : \
664 __swbuf('\n', p) : \
665 __swbuf((int)(c), p) : \
666 (*(p)->_p = (unsigned char)(c), (int)*(p)->_p++))
667 #endif
668
669 #define __sfeof(p) (((p)->_flags & __SEOF) != 0)
670 #define __sferror(p) (((p)->_flags & __SERR) != 0)
671 #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
672 #define __sfileno(p) ((p)->_file)
673
674 #ifndef __lint__
675 #if !defined(_REENTRANT) && !defined(_PTHREADS)
676 #define feof(p) __sfeof(p)
677 #define ferror(p) __sferror(p)
678 #define clearerr(p) __sclearerr(p)
679
680 #define getc(fp) __sgetc(fp)
681 #define putc(x, fp) __sputc(x, fp)
682 #endif /* !_REENTRANT && !_PTHREADS */
683 #endif /* __lint__ */
684
685 #define getchar() getc(stdin)
686 #define putchar(x) putc(x, stdout)
687
688 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
689 defined(_NETBSD_SOURCE)
690 #if !defined(_REENTRANT) && !defined(_PTHREADS)
691 #define fileno(p) __sfileno(p)
692 #endif /* !_REENTRANT && !_PTHREADS */
693 #endif /* !_ANSI_SOURCE */
694
695 #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
696 defined(_REENTRANT) || defined(_NETBSD_SOURCE)
697 #define getc_unlocked(fp) __sgetc(fp)
698 #define putc_unlocked(x, fp) __sputc(x, fp)
699
700 #define getchar_unlocked() getc_unlocked(stdin)
701 #define putchar_unlocked(x) putc_unlocked(x, stdout)
702 #endif /* _POSIX_C_SOURCE >= 199506 || _XOPEN_SOURCE >= 500 || _REENTRANT... */
703
704 #endif /* _STDIO_H_ */