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