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