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