]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/Include/stdio.h
Update or add comments to files and functions for use by Doxygen.
[mirror_edk2.git] / StdLib / Include / stdio.h
1 /** @file
2 Macros, types, and functions for performing I/O.
3
4 The following functions are declared in this file:<BR>
5 @verbatim
6 ################### Operations on files. ####
7 int remove (const char *FileName);
8 int rename (const char *, const char *);
9 FILE *tmpfile (void);
10 char *tmpnam (char *);
11
12 ################### File access functions. ####
13 int fclose (FILE *);
14 int fflush (FILE *);
15 FILE *fopen (const char * __restrict ,
16 const char * __restrict);
17 FILE *freopen (const char * __restrict,
18 const char * __restrict, FILE * __restrict);
19 void setbuf (FILE * __restrict, char * __restrict);
20 int setvbuf (FILE * __restrict, char * __restrict,
21 int, size_t);
22
23 ################### Formatted Input/Output Functions. ####
24 int fprintf (FILE * __restrict stream,
25 const char * __restrict format, ...);
26 int fscanf (FILE * __restrict, const char * __restrict, ...);
27 int printf (const char * __restrict, ...);
28 int scanf (const char * __restrict, ...);
29 int sprintf (char * __restrict, const char * __restrict, ...);
30 int sscanf (const char * __restrict,
31 const char * __restrict, ...);
32 int vfprintf (FILE * __restrict,
33 const char * __restrict, va_list);
34 int vprintf (const char * __restrict, va_list);
35 int vsprintf (char * __restrict,
36 const char * __restrict, va_list);
37
38 ################### Character Input/Output Functions. ####
39 int fgetc (FILE *);
40 char *fgets (char * __restrict, int, FILE * __restrict);
41 int fputc (int, FILE *);
42 int fputs (const char * __restrict, FILE * __restrict);
43 int getc (FILE *);
44 int getchar (void);
45 char *gets (char *);
46 int putc (int, FILE *);
47 int putchar (int);
48 int puts (const char *);
49 int ungetc (int, FILE *);
50
51 ################### Direct Input/Output Functions. ####
52 size_t fread (void * __restrict, size_t, size_t,
53 FILE * __restrict);
54 size_t fwrite (const void * __restrict, size_t, size_t,
55 FILE * __restrict);
56
57 ################### File Positioning Functions. ####
58 int fgetpos (FILE * __restrict, fpos_t * __restrict);
59 int fseek (FILE *, long, int);
60 int fsetpos (FILE *, const fpos_t *);
61 long ftell (FILE *);
62 void rewind (FILE *);
63
64 ################### Error-handling Functions. ####
65 void clearerr (FILE *);
66 int feof (FILE *);
67 int ferror (FILE *);
68 void perror (const char *);
69
70 ################### Functions NOT specified by C95 ####
71
72 FILE *fdopen (int, const char *);
73 void flockfile (FILE *);
74 int ftrylockfile (FILE *);
75 void funlockfile (FILE *);
76 int getc_unlocked (FILE *);
77 int getchar_unlocked(void);
78 int putc_unlocked (int, FILE *);
79 int putchar_unlocked(int);
80 int pclose (FILE *);
81 FILE *popen (const char *, const char *);
82 int snprintf (char * __restrict, size_t,
83 const char * __restrict, ...);
84 int vsnprintf (char * __restrict, size_t,
85 const char * __restrict, va_list);
86 char *mkdtemp (char *);
87 int mkstemp (char *);
88 char *mktemp (char *);
89 char *tempnam (const char *, const char *);
90 int fseeko (FILE *, off_t, int);
91 char *fgetln (FILE * __restrict, size_t * __restrict);
92 char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
93 int fpurge (FILE *);
94 void setbuffer (FILE *, char *, int);
95 int setlinebuf (FILE *);
96 int vasprintf (char ** __restrict, const char * __restrict,
97 va_list);
98 int vscanf (const char * __restrict, va_list);
99 int vsscanf (const char * __restrict,
100 const char * __restrict, va_list);
101 @endverbatim
102
103 @note To fit things in six character monocase externals, the stdio
104 code uses the prefix `__s' for stdio objects, typically followed
105 by a three-character attempt at a mnemonic.
106
107
108 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
109 This program and the accompanying materials are licensed and made available under
110 the terms and conditions of the BSD License that accompanies this distribution.
111 The full text of the license may be found at
112 http://opensource.org/licenses/bsd-license.
113
114 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
115 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
116
117 * Copyright (c) 1990, 1993
118 * The Regents of the University of California. All rights reserved.
119 *
120 * This code is derived from software contributed to Berkeley by
121 * Chris Torek.
122 *
123 * Redistribution and use in source and binary forms, with or without
124 * modification, are permitted provided that the following conditions
125 * are met:
126 * 1. Redistributions of source code must retain the above copyright
127 * notice, this list of conditions and the following disclaimer.
128 * 2. Redistributions in binary form must reproduce the above copyright
129 * notice, this list of conditions and the following disclaimer in the
130 * documentation and/or other materials provided with the distribution.
131 * 3. Neither the name of the University nor the names of its contributors
132 * may be used to endorse or promote products derived from this software
133 * without specific prior written permission.
134 *
135 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
136 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
137 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
138 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
139 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
140 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
141 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
142 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
143 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
144 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
145 * SUCH DAMAGE.
146 *
147 * @(#)stdio.h 8.5 (Berkeley) 4/29/95
148 NetBSD: stdio.h,v 1.66.2.3 2007/08/24 20:07:38 liamjfoy Exp
149 */
150 #ifndef _STDIO_H_
151 #define _STDIO_H_
152
153 #include <stdarg.h>
154 #include <limits.h>
155 #include <sys/ansi.h>
156 #include <machine/ansi.h>
157
158 #ifdef _EFI_SIZE_T_
159 /** size_t is the unsigned integer type of the result of the sizeof operator. **/
160 typedef _EFI_SIZE_T_ size_t;
161 #undef _EFI_SIZE_T_
162 #undef _BSD_SIZE_T_
163 #endif
164
165 /** @{
166 An object type capable of holding all information necessary to specify any
167 position within a file.
168
169 Each wide-oriented stream has an associated mbstate_t object that stores the
170 current parse state of the stream. A successful call to fgetpos stores a
171 representation of the value of this mbstate_t object as part of the value
172 of the fpos_t object. A later successful call to fsetpos using the same
173 stored fpos_t value restores the value of the associated mbstate_t object
174 as well as the position within the controlled stream.
175
176 This is fairly grotesque, but pure ANSI code must not inspect the
177 innards of an fpos_t anyway. The library internally uses off_t,
178 which we assume is exactly as big as eight chars.
179 **/
180 #if (!defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)) || defined(_LIBC)
181 typedef __off_t fpos_t;
182 #else
183 typedef struct __sfpos {
184 __off_t _pos;
185 } fpos_t;
186 #endif
187 /*@}*/
188
189 /* stdio buffers */
190 struct __sbuf {
191 unsigned char *_base;
192 int _size;
193 };
194
195 /** Structure which holds all the information needed to control a stream or file.
196 *
197 * The following always hold:<BR>
198 *
199 * - if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
200 * - _lbfsize is -_bf._size, else _lbfsize is 0
201 * - if _flags&__SRD, _w is 0
202 * - if _flags&__SWR, _r is 0
203 *
204 * This ensures that the getc and putc macros (or inline functions) never
205 * try to write or read from a file that is in `read' or `write' mode.
206 * (Moreover, they can, and do, automatically switch from read mode to
207 * write mode, and back, on "r+" and "w+" files.)
208 *
209 * _lbfsize is used only to make the inline line-buffered output stream
210 * code as compact as possible.
211 *
212 * _ub, _up, and _ur are used when ungetc() pushes back more characters
213 * than fit in the current _bf, or when ungetc() pushes back a character
214 * that does not match the previous one in _bf. When this happens,
215 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
216 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
217 *
218 */
219 typedef struct __sFILE {
220 unsigned char *_p; /**< current position in (some) buffer */
221 int _r; /**< read space left for getc() */
222 int _w; /**< write space left for putc() */
223 unsigned short _flags; /**< flags, below; this FILE is free if 0 */
224 short _file; /**< fileno, if Unix descriptor, else -1 */
225 struct __sbuf _bf; /**< the buffer (at least 1 byte, if !NULL) */
226 int _lbfsize; /**< 0 or -_bf._size, for inline putc */
227
228 /* operations */
229 void *_cookie; /**< cookie passed to io functions */
230 int (*_close)(void *);
231 int (*_read) (void *, char *, int);
232 fpos_t (*_seek) (void *, fpos_t, int);
233 int (*_write)(void *, const char *, int);
234
235 /** file extension */
236 struct __sbuf _ext;
237
238 /** @{
239 Separate buffer for long sequences of ungetc().
240 **/
241 unsigned char *_up; /**< saved _p when _p is doing ungetc data */
242 int _ur; /**< saved _r when _r is counting ungetc data */
243 /*@}*/
244
245 /* tricks to meet minimum requirements even when malloc() fails */
246 unsigned char _ubuf[3]; /**< guarantee an ungetc() buffer */
247 unsigned char _nbuf[1]; /**< guarantee a getc() buffer */
248
249 /** separate buffer for fgetln() when line crosses buffer boundary */
250 struct __sbuf _lb; /* buffer for fgetln() */
251
252 /* Unix stdio files get aligned to block boundaries on fseek() */
253 int _blksize; /**< stat.st_blksize (may be != _bf._size) */
254 fpos_t _offset; /**< current lseek offset */
255 } FILE;
256
257 __BEGIN_DECLS
258 extern FILE __sF[];
259 __END_DECLS
260
261 #define __SLBF 0x0001 /**< line buffered */
262 #define __SNBF 0x0002 /**< unbuffered */
263 #define __SRD 0x0004 /**< OK to read */
264 #define __SWR 0x0008 /**< OK to write */
265 /* RD and WR are never simultaneously asserted */
266 #define __SRW 0x0010 /**< open for reading & writing */
267 #define __SEOF 0x0020 /**< found EOF */
268 #define __SERR 0x0040 /**< found error */
269 #define __SMBF 0x0080 /**< _buf is from malloc */
270 #define __SAPP 0x0100 /**< fdopen()ed in append mode */
271 #define __SSTR 0x0200 /**< this is an sprintf/snprintf string */
272 #define __SOPT 0x0400 /**< do fseek() optimization */
273 #define __SNPT 0x0800 /**< do not do fseek() optimization */
274 #define __SOFF 0x1000 /**< set iff _offset is in fact correct */
275 #define __SMOD 0x2000 /**< true => fgetln modified _p text */
276 #define __SALC 0x4000 /**< allocate string space dynamically */
277
278 /* The following three definitions are for ANSI C, which took them
279 from System V, which brilliantly took internal interface macros and
280 made them official arguments to setvbuf(), without renaming them.
281 Hence, these ugly _IOxxx names are *supposed* to appear in user code.
282
283 Although numbered as their counterparts above, the implementation
284 does not rely on this.
285 */
286 #define _IOFBF 0 /**< setvbuf should set fully buffered */
287 #define _IOLBF 1 /**< setvbuf should set line buffered */
288 #define _IONBF 2 /**< setvbuf should set unbuffered */
289
290 #define BUFSIZ 1024 /**< size of buffer used by setbuf */
291 #define EOF (-1) /**< A constant integer expression indicating end-of-file. */
292
293 /** FOPEN_MAX is a minimum maximum, and is the number of streams that
294 stdio can provide without attempting to allocate further resources
295 (which could fail). Do not use this for anything.
296 */
297 #define FOPEN_MAX OPEN_MAX /* must be <= OPEN_MAX <sys/syslimits.h> */
298
299 /** Size needed for an array of char large enough to hold the longest file name string. */
300 #define FILENAME_MAX PATH_MAX /* must be <= PATH_MAX <sys/syslimits.h> */
301
302 /** Size needed for an array of char large enough to hold the file name string
303 generated by the tmpname() function.
304 **/
305 #define L_tmpnam PATH_MAX /* must be == PATH_MAX */
306
307 #ifndef TMP_MAX
308 #define TMP_MAX 308915776 /**< The maximum number of unique file names
309 that can be generated by tmpnam(). **/
310 #endif
311
312 /* Always ensure that these are consistent with <fcntl.h>! */
313 #ifndef SEEK_SET
314 #define SEEK_SET 0 /**< set file offset to offset */
315 #endif
316 #ifndef SEEK_CUR
317 #define SEEK_CUR 1 /**< set file offset to current plus offset */
318 #endif
319 #ifndef SEEK_END
320 #define SEEK_END 2 /**< set file offset to EOF plus offset */
321 #endif
322
323 #define stdin (&__sF[0]) /**< FILE reference for the STanDard INput stream. */
324 #define stdout (&__sF[1]) /**< FILE reference for the STanDard OUTput stream. */
325 #define stderr (&__sF[2]) /**< FILE reference for the STanDard ERRor stream. */
326
327 __BEGIN_DECLS
328 /* Functions defined in C95 standard. ###################################### */
329
330 /* ################ Operations on files. */
331
332 /** Remove (delete) a file.
333
334 @param[in] FileName The path to the file to be removed.
335
336 @retval Zero The operation succeeded.
337 @retval Non-zero The operation failed.
338 **/
339 int remove (const char *FileName);
340
341 /** Rename the file named OldName to NewName.
342
343 @param[in] OldName The name of the existing file to be renamed.
344 @param[in] NewName The new name of the file.
345
346 @retval Zero The operation succeeded.
347 @retval Non-zero The operation failed. OldName still exists and has been unmodified.
348 If OldName does not exist, or a file named NewName already exists,
349 rename() will fail are return a non-zero value.
350 **/
351 int rename (const char *OldName, const char *NewName);
352
353 /** Create a guaranteed unique temporary file.
354 A binary file is created in the _PATH_TMP directory that is guaranteed to
355 have a unique name. The file will be open for update with mode "wb+" and
356 its FILE pointer returned upon successfull completion. When the file is
357 closed, or when the creating program terminates, the file will be removed.
358
359 @retval NULL The temporary file could not be created.
360 @retval non-NULL The returned value is a pointer to the FILE object
361 associated with the newly created and open temporary file.
362 **/
363 FILE *tmpfile (void);
364
365 /** Generate a string that is a valid file name, in the _PATH_TMP directory, that
366 is not the same as the name of an existing file. The function can potentially
367 generate up to TMP_MAX different strings.
368
369 @param[out] Buffer A pointer to an array of at least L_tmpnam char elements.
370 or NULL. If non-NULL, the tmpnam function writes its
371 result into that array and returns the argument
372 as its value.
373
374 @return If no suitable string can be generated a NULL pointer is returned.
375 Otherwise, if Buffer is NULL, the result is produced in an internal
376 static object and a pointer to that object is returned. If Buffer
377 is non-null, the results are written into the array pointed to by
378 Buffer and Buffer is returned.
379 **/
380 char *tmpnam (char *Buffer);
381
382 /* ################ File access functions. */
383
384 /** Close the open stream, specified by fp, and de-associate it from any file or device.
385
386 @param[in] fp Pointer to a stream object, of type FILE, associated with a
387 file or device.
388
389 @retval Zero The stream was successfully closed.
390 @retval Non-zero There was an error closing the stream.
391 **/
392 int fclose (FILE *fp);
393
394 /** Empties any buffers associated with the stream specified by fp.
395
396 @param[in] fp Pointer to a stream object, of type FILE, associated with a
397 file or device.
398
399 @retval Zero The stream's buffers were successfully emptied.
400 @retval EOF There was an error writing to the stream.
401 **/
402 int fflush (FILE *fp);
403
404 /** Associates a file, named by Path, with a stream and prepares it for subsequent
405 operations.
406
407 The parameter Mode points to a string specifying behavior characteristics for
408 the opened file. The recognized Mode strings are:
409 - r Open text file for reading.
410 - w Truncate file to zero length or create text file for writing.
411 - a Open or create a text file for writing at end-of-file (append).
412 - rb Open binary file for reading.
413 - wb Truncate file to zero length or create binary file for writing.
414 - ab Open or create a binary file for writing at end-of-file (append).
415 - r+ Open text file for update (reading and writing).
416 - w+ Truncate file to zero length or create text file for update.
417 - a+ Open or create a text file for update, writing at end-of-file.
418 - r+b or rb+ Open binary file for update (reading and writing).
419 - w+b or wb+ Truncate file to zero length or create binary file for update.
420 - a+b or ab+ Open or create a binary file for update, writing at end-of-file.
421
422 Opening a file with read mode fails if the file does not exist.
423
424 Opening a file with append mode causes all writes to the file to be forced to
425 the current end-of-file, regardless of any intervening calls to fseek.
426
427 @param[in] Path The path or name of the file or device to open.
428 @param[in] Mode The mode in which the file is to be opened.
429
430 @return A pointer to a FILE object associated with the opened file is returned
431 if the file was opened successfully. Otherwise, NULL is returned.
432 **/
433 FILE *fopen (const char * __restrict Path, const char * __restrict Mode);
434
435 /** Closes the file associated with Ofp then opens the file specified by Path and associates it with
436 stream Ofp.
437
438 Any errors that occur when closing Ofp are ignored. The file specified by Path is opened with mode Mode
439 and associated with stream Ofp instead of producing a new stream object.
440
441 If Path is NULL, the mode of the file associated with Ofp is changed to Mode.
442
443 @param[in] Path The path or name of the file or device to open.
444 @param[in] Mode The mode in which the file is to be opened.
445 @param[in] Ofp Pointer to the FILE object to be closed and associated with the new file.
446
447 @return If Path was not able to be opened, or the mode changed, NULL is returned;
448 otherwise Ofp is returned.
449 **/
450 FILE *freopen (const char * __restrict Path, const char * __restrict Mode, FILE * __restrict Ofp);
451
452 /** Establishes Fully Buffered or Non-buffered mode for a stream, fp, using Buff as the buffer.
453
454 The file associated with fp must have been successfully opened with no operations, other than
455 possibly an unsuccessful call to setvbuf, performed prior to the call to setbuf.
456
457 If Buff is non-NULL, the stream associated with fp is set to Fully Buffered mode using the
458 array pointed to by Buff as the buffer. The buffer is assumed to be BUFSIZ char long.
459 This is equivalent to calling setvbuf(fp, Buff, _IOFBF, BUFSIZ);
460
461 If Buff is NULL, stream fp is set to Non-buffered mode.
462 This is equivalent to calling setvbuf(fp, NULL, _IONBF, 0);
463
464 @param[in] fp Pointer to the FILE object which will have its buffer set.
465 @param[in] Buff The buffer to use for fp, or NULL.
466 **/
467 void setbuf (FILE * __restrict fp, char * __restrict Buff);
468
469 /** Establishes a buffering mode and buffer for use by operations performed on the file associated with fp.
470
471 The file associated with fp must have been successfully opened with no operations, other than
472 possibly an unsuccessful call to setvbuf, performed prior to the call to setbuf.
473
474 Parameter BufMode determines how stream fp will be buffered:
475 - _IOFBF causes I/O to be fully buffered.
476 - _IOLBF causes I/O to be line buffered.
477 - _IONBF causes I/O to be unbuffered.
478
479 If Buff is not NULL, it points to an array to be used as an I/O buffer for stream fp. The
480 buffer is set to BufSize char in length. Otherwise, an array of BufSize char is allocated
481 by the setvbuf function if BufMode is not _IONBF.
482
483 It is an error for BufSize to be zero unless BufMode is _IONBF, in which case BufSize is ignored.
484
485 @param[in] fp Pointer to the FILE object which will have its buffer set.
486 @param[in] Buff The buffer to use for fp, or NULL.
487 @param[in] BufMode The buffering mode to use.
488 @param[in] BufSize The size of the buffer to use, specified in char.
489
490 @retval Zero The buffer and mode were established successfully.
491 @retval Non-zero The request can not be honored, or an invalid value for BufMode was given.
492 **/
493 int setvbuf (FILE * __restrict fp, char * __restrict Buff, int BufMode, size_t BufSize);
494
495 /* ################ Formatted Input/Output Functions. */
496
497 /** The fprintf function writes output to the stream pointed to by stream,
498 under control of the string pointed to by format that specifies how
499 subsequent arguments are converted for output. If there are insufficient
500 arguments for the format, the behavior is indeterminate. If the format is
501 exhausted while arguments remain, the excess arguments are evaluated
502 (as always) but are otherwise ignored. The fprintf function returns when
503 the end of the format string is encountered.
504
505 The format is interpreted as a multibyte character sequence, beginning and ending
506 in its initial shift state. The format is composed of zero or more directives:
507 ordinary multibyte characters (not %), which are copied unchanged to the
508 output stream; and conversion specifications, each of which results in
509 fetching zero or more subsequent arguments, converting them, if applicable,
510 according to the corresponding conversion specifier, and then writing the
511 result to the output stream.
512
513 Each conversion specification is introduced by the character %. After
514 the %, the following appear in sequence:
515 - Zero or more flags (in any order) that modify the meaning of the
516 conversion specification.
517 - An optional minimum field width. If the converted value has fewer
518 characters than the field width, it is padded with spaces (by default)
519 on the left (or right, if the left adjustment flag, described later,
520 has been given) to the field width. The field width takes the form of
521 an asterisk * (described later) or a nonnegative decimal integer.
522 - An optional precision that gives the minimum number of digits to appear
523 for the d, i, o, u, x, and X conversions, the number of digits to
524 appear after the decimal-point character for e, E, f, and F
525 conversions, the maximum number of significant digits for the g and G
526 conversions, or the maximum number of bytes to be written for s
527 conversions. The precision takes the form of a period (.) followed
528 either by an asterisk * (described later) or by an optional decimal
529 integer; if only the period is specified, the precision is taken as
530 zero. If a precision appears with any other conversion specifier, it
531 is ignored.
532 - An optional length modifier that specifies the size of the argument.
533 - A conversion specifier character that specifies the type of conversion
534 to be applied.
535
536 As noted above, a field width, or precision, or both, may be indicated by
537 an asterisk. In this case, an int argument supplies the field width or
538 precision. The arguments specifying field width, or precision, or both, shall
539 appear (in that order) before the argument (if any) to be converted. A negative
540 field width argument is taken as a - flag followed by a positive field width.
541 A negative precision argument is interpreted as if the precision were omitted.
542
543 The flag characters and their meanings are:
544 - The result of the conversion is left-justified within the field.
545 (It is right-justified if this flag is not specified.)
546 + The result of a signed conversion always begins with a plus or
547 minus sign. (It begins with a sign only when a negative value is
548 converted if this flag is not specified.)
549 space If the first character of a signed conversion is not a sign, or
550 if a signed conversion results in no characters, a space is
551 prefixed to the result. If the space and + flags both appear, the
552 space flag is ignored.
553 # The result is converted to an "alternative form".
554 - For o conversion, it increases the precision, if and only if necessary,
555 to force the first digit of the result to be a zero (if the value
556 and precision are both 0, a single 0 is printed).
557 - For x (or X) conversion, a nonzero result has 0x (or 0X) prefixed to it.
558 - For e, E, f, F, g, and G conversions, the result of converting a
559 floating-point number always contains a decimal-point character,
560 even if no digits follow it. (Normally, a decimal-point character
561 appears in the result of these conversions only if a digit follows
562 it.)
563 - For g and G conversions, trailing zeros are not removed from
564 the result. For other conversions, it is ignored.
565 0 For d, i, o, u, x, X, e, E, f, F, g, and G conversions, leading
566 zeros (following any indication of sign or base) are used to pad to
567 the field width rather than performing space padding, except when
568 converting an infinity or NaN. If the 0 and - flags both appear,
569 the 0 flag is ignored. For d, i, o, u, x, and X conversions, if a
570 precision is specified, the 0 flag is ignored.
571
572 The length modifiers and their meanings are:
573 hh Specifies that a following d, i, o, u, x, or X conversion specifier
574 applies to a signed char or unsigned char argument (the argument
575 will have been promoted according to the integer promotions, but
576 its value shall be converted to signed char or unsigned char before
577 printing); or that a following n conversion specifier applies to a
578 pointer to a signed char argument.
579 h Specifies that a following d, i, o, u, x, or X conversion specifier
580 applies to a short int or unsigned short int argument (the argument
581 will have been promoted according to the integer promotions, but
582 its value shall be converted to short int or unsigned short int
583 before printing); or that a following n conversion specifier
584 applies to a pointer to a short int argument.
585 l (ell) Specifies that a following d, i, o, u, x, or X conversion
586 specifier applies to a long int or unsigned long int argument; that
587 a following n conversion specifier applies to a pointer to a long
588 int argument; that a following c conversion specifier applies to a
589 wint_t argument; that a following s conversion specifier applies to
590 a pointer to a wchar_t argument; or has no effect on a following e,
591 E, f, F, g, or G conversion specifier.
592 ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion
593 specifier applies to a long long int or unsigned long long int
594 argument; or that a following n conversion specifier applies to a
595 pointer to a long long int argument.
596 j Specifies that a following d, i, o, u, x, or X conversion specifier
597 applies to an intmax_t or uintmax_t argument; or that a following n
598 conversion specifier applies to a pointer to an intmax_t argument.
599 z Specifies that a following d, i, o, u, x, or X conversion specifier
600 applies to a size_t or the corresponding signed integer type
601 argument; or that a following n conversion specifier applies to a
602 pointer to a signed integer type corresponding to size_t argument.
603 t Specifies that a following d, i, o, u, x, or X conversion specifier
604 applies to a ptrdiff_t or the corresponding unsigned integer type
605 argument; or that a following n conversion specifier applies to a
606 pointer to a ptrdiff_t argument.
607 L Specifies that a following e, E, f, F, g, or G conversion specifier
608 applies to a long double argument.
609
610 If a length modifier appears with any conversion specifier other than as
611 specified above, it is ignored.
612
613 The conversion specifiers and their meanings are:
614 d,i The int argument is converted to signed decimal in the style
615 [-]dddd. The precision specifies the minimum number of digits to
616 appear; if the value being converted can be represented in fewer
617 digits, it is expanded with leading zeros. The default precision
618 is 1. The result of converting a zero value with a precision of
619 zero is no characters.
620 o,u,x,X The unsigned int argument is converted to unsigned octal (o),
621 unsigned decimal (u), or unsigned hexadecimal notation (x or X) in
622 the style dddd; the letters abcdef are used for x conversion and
623 the letters ABCDEF for X conversion. The precision specifies the
624 minimum number of digits to appear; if the value being converted
625 can be represented in fewer digits, it is expanded with leading
626 zeros. The default precision is 1. The result of converting a zero
627 value with a precision of zero is no characters.
628 f,F A double argument representing a floating-point number is
629 converted to decimal notation in the style [-]ddd.ddd, where the
630 number of digits after the decimal-point character is equal to the
631 precision specification. If the precision is missing, it is taken
632 as 6; if the precision is zero and the # flag is not specified, no
633 decimal-point character appears. If a decimal-point character
634 appears, at least one digit appears before it. The value is rounded
635 to the appropriate number of digits.
636 A double argument representing an infinity is converted in
637 the style [-]inf. A double argument representing a NaN is
638 converted in the style [-]nan. The F conversion specifier produces INF,
639 INFINITY, or NAN instead of inf, infinity, or nan, respectively.
640 e,E A double argument representing a floating-point number is
641 converted in the style [-]d.ddd e[+-]dd, where there is one digit
642 (which is nonzero if the argument is nonzero) before the
643 decimal-point character and the number of digits after it is equal
644 to the precision; if the precision is missing, it is taken as 6; if
645 the precision is zero and the # flag is not specified, no
646 decimal-point character appears. The value is rounded to the
647 appropriate number of digits. The E conversion specifier produces a
648 number with E instead of e introducing the exponent. The exponent
649 always contains at least two digits, and only as many more digits
650 as necessary to represent the exponent. If the value is zero, the
651 exponent is zero.
652 A double argument representing an infinity or NaN is converted
653 in the style of an f or F conversion specifier.
654 g,G A double argument representing a floating-point number is
655 converted in style f or e (or in style F or E in the case of a G
656 conversion specifier), depending on the value converted and the
657 precision. Let P equal the precision if nonzero, 6 if the precision
658 is omitted, or 1 if the precision is zero. Then, if a conversion
659 with style E would have an exponent of X:
660 - if P > X = -4, the conversion is with style f (or F) and
661 precision P - (X + 1).
662 - otherwise, the conversion is with style e (or E) and
663 precision P - 1.
664
665 Finally, unless the # flag is used, any trailing zeros are removed
666 from the fractional portion of the result and the decimal-point
667 character is removed if there is no fractional portion remaining.
668 A double argument representing an infinity or NaN is converted in
669 the style of an f or F conversion specifier.
670 c If no l length modifier is present, the int argument is
671 converted to an unsigned char, and the resulting character is
672 written. If an l length modifier is present, the wint_t argument is
673 converted as if by an ls conversion specification with no precision
674 and an argument that points to the initial element of a two-element
675 array of wchar_t, the first element containing the wint_t argument
676 to the lc conversion specification and the second a null wide
677 character.
678 s If no l length modifier is present, the argument is a pointer
679 to the initial element of an array of character type. Characters
680 from the array are written up to (but not including) the
681 terminating null character. If the precision is specified, no more
682 than that many bytes are written. If the precision is not specified
683 or is greater than the size of the array, the array shall contain a
684 null character.
685 If an l length modifier is present, the argument shall be a
686 pointer to the initial element of an array of wchar_t type. Wide
687 characters from the array are converted to multibyte characters
688 (each as if by a call to the wcrtomb function, with the conversion
689 state described by an mbstate_t object initialized to zero before
690 the first wide character is converted) up to and including a
691 terminating null wide character. The resulting multibyte characters
692 are written up to (but not including) the terminating null
693 character (byte). If no precision is specified, the array shall
694 contain a null wide character. If a precision is specified, no more
695 than that many bytes are written (including shift sequences, if
696 any), and the array shall contain a null wide character if, to
697 equal the multibyte character sequence length given by the
698 precision, the function would need to access a wide character one
699 past the end of the array. In no case is a partial multibyte
700 character written.
701 p The argument shall be a pointer to void. The value of the
702 pointer is converted to a sequence of printing characters.
703 n The argument shall be a pointer to signed integer into which is
704 written the number of characters written to the output stream so
705 far by this call to fprintf. No argument is converted, but one is
706 consumed. If the conversion specification includes any flags, a
707 field width, or a precision, they will be ignored.
708 % A % character is written. No argument is converted. The
709 complete conversion specification shall be %%.
710
711 In no case does a nonexistent or small field width cause truncation of a
712 field; if the result of a conversion is wider than the field width, the
713 field is expanded to contain the conversion result.
714
715 @param[in] stream An open File specifier to which the output is sent.
716 @param[in] format A multi-byte character sequence containing characters
717 to be copied unchanged, and conversion specifiers
718 which convert their associated arguments. Copied and
719 converted characters are sent to the output stream.
720 @param ... Variable number of parameters as required by format.
721
722 @return The fprintf function returns the number of characters
723 transmitted, or a negative value if an output or encoding
724 error occurred.
725 **/
726 int fprintf (FILE * __restrict stream, const char * __restrict format, ...);
727
728 /** Reads characters from stream, under control of format, storing the converted values
729 in variables pointed to by the variable-length parameter list.
730
731 The format is interpreted as a multibyte character sequence, beginning and ending
732 in its initial shift state. The format is composed of zero or more directives:
733 one or more white-space characters, an ordinary multibyte character
734 (neither % nor a white-space character), or a conversion specification.
735
736 Each conversion specification is introduced by the character %. After
737 the %, the following appear in sequence:
738 - An optional assignment-suppressing character, *.
739 - An optional decimal integer, greater than zero, that specifies the
740 maximum field width (in characters).
741 - An optional length modifier that specifies the size of the receiving object.
742 - A conversion specifier character that specifies the type of conversion
743 to be applied.
744
745 The fscanf function executes each directive of the format in turn. If a directive fails, as
746 detailed below, the function returns. Failures are described as input failures (due to the
747 occurrence of an encoding error or the unavailability of input characters), or matching
748 failures (due to inappropriate input).
749
750 A directive composed of white-space character(s) is executed by reading input up to the
751 first non-white-space character (which remains unread), or until no more characters can
752 be read.
753
754 A directive that is an ordinary multibyte character is executed by reading the next
755 characters of the stream. If any of those characters differ from the ones composing the
756 directive, the directive fails and the differing and subsequent characters remain unread.
757 Similarly, if end-of-file, an encoding error, or a read error prevents a character from being
758 read, the directive fails.
759
760 The length modifiers and their meanings are:
761 - hh Specifies that a following d, i, o, u, x, X, or n conversion
762 specifier applies to an argument with type pointer to signed
763 char or unsigned char.
764 - h Specifies that a following d, i, o, u, x, X, or n conversion
765 specifier applies to an argument with type pointer to short
766 int or unsigned short int.
767 - l (ell) Specifies that a following d, i, o, u, x, X, or n conversion
768 specifier applies to an argument with type pointer to
769 long int or unsigned long int; that a following a, A, e,
770 E, f, F, g, or G conversion specifier applies to an
771 argument with type pointer to double; or that a following
772 c, s, or [ conversion specifier applies to an argument
773 with type pointer to wchar_t.
774 - ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion
775 specifier applies to an argument with type pointer to
776 long long int or unsigned long long int.
777 - j Specifies that a following d, i, o, u, x, X, or n conversion
778 specifier applies to an argument with type pointer to
779 intmax_t or uintmax_t.
780 - z Specifies that a following d, i, o, u, x, X, or n conversion
781 specifier applies to an argument with type pointer to
782 size_t or the corresponding signed integer type.
783 - t Specifies that a following d, i, o, u, x, X, or n conversion
784 specifier applies to an argument with type pointer to
785 ptrdiff_t or the corresponding unsigned integer type.
786 - L Specifies that a following e, E, f, F, g, or G
787 conversion specifier applies to an argument with type
788 pointer to long double.
789
790 If a length modifier appears with any conversion specifier other than as specified above,
791 it will be ignored.
792
793 The conversion specifiers and their meanings are:
794 - d Matches an optionally signed decimal integer, whose format is
795 the same as expected for the subject sequence of the strtol
796 function with the value 10 for the base argument. The
797 corresponding argument shall be a pointer to signed integer.
798 - i Matches an optionally signed integer, whose format is the same
799 as expected for the subject sequence of the strtol function
800 with the value 0 for the base argument. The corresponding
801 argument shall be a pointer to signed integer.
802 - o Matches an optionally signed octal integer, whose format is the
803 same as expected for the subject sequence of the strtoul
804 function with the value 8 for the base argument. The
805 corresponding argument shall be a pointer to unsigned integer.
806 - u Matches an optionally signed decimal integer, whose format is
807 the same as expected for the subject sequence of the strtoul
808 function with the value 10 for the base argument. The
809 corresponding argument shall be a pointer to unsigned integer.
810 - x Matches an optionally signed hexadecimal integer, whose format
811 is the same as expected for the subject sequence of the strtoul
812 function with the value 16 for the base argument. The
813 corresponding argument shall be a pointer to unsigned integer.
814 - e,f,g Matches an optionally signed floating-point number, infinity,
815 or NaN, whose format is the same as expected for the subject
816 sequence of the strtod function. The corresponding argument
817 shall be a pointer to floating.
818 - c Matches a sequence of characters of exactly the number
819 specified by the field width (1 if no field width is present
820 in the directive). If no l length modifier is present, the
821 corresponding argument shall be a pointer to the initial
822 element of a character array large enough to accept the
823 sequence. No null character is added.<BR><BR>
824 If an l length modifier is present, the input shall be a
825 sequence of multibyte characters that begins in the initial
826 shift state. Each multibyte character in the sequence is
827 converted to a wide character as if by a call to the mbrtowc
828 function, with the conversion state described by an mbstate_t
829 object initialized to zero before the first multibyte character
830 is converted. The corresponding argument shall be a pointer to
831 the initial element of an array of wchar_t large enough to
832 accept the resulting sequence of wide characters. No null wide
833 character is added.
834 - s Matches a sequence of non-white-space characters.
835 If no l length modifier is present, the corresponding argument
836 shall be a pointer to the initial element of a character array
837 large enough to accept the sequence and a terminating null
838 character, which will be added automatically. If an l length
839 modifier is present, the input shall be a sequence of multibyte
840 characters that begins in the initial shift state. Each
841 multibyte character is converted to a wide character as if by a
842 call to the mbrtowc function, with the conversion state
843 described by an mbstate_t object initialized to zero before the
844 first multibyte character is converted. The corresponding
845 argument shall be a pointer to the initial element of an array
846 of wchar_t large enough to accept the sequence and the
847 terminating null wide character, which will be added automatically.
848 - [ Matches a nonempty sequence of characters from a set of
849 expected characters (the scanset).<BR><BR>
850 If no l length modifier is present, the corresponding argument
851 shall be a pointer to the initial element of a character array
852 large enough to accept the sequence and a terminating null
853 character, which will be added automatically. If an l length
854 modifier is present, the input shall be a sequence of multibyte
855 characters that begins in the initial shift state. Each
856 multibyte character is converted to a wide character as if by a
857 call to the mbrtowc function, with the conversion state
858 described by an mbstate_t object initialized to zero before the
859 first multibyte character is converted. The corresponding
860 argument shall be a pointer to the initial element of an array
861 of wchar_t large enough to accept the sequence and the
862 terminating null wide character, which will be added
863 automatically.<BR><BR>
864 The conversion specifier includes all subsequent characters in
865 the format string, up to and including the matching right
866 bracket (]). The characters between the brackets (the scanlist)
867 compose the scanset, unless the character after the left
868 bracket is a circumflex (^), in which case the scanset contains
869 all characters that do not appear in the scanlist between the
870 circumflex and the right bracket. If the conversion specifier
871 begins with [] or [^], the right bracket character is in the
872 scanlist and the next following right bracket character is the
873 matching right bracket that ends the specification; otherwise
874 the first following right bracket character is the one that
875 ends the specification. If a - character is in the scanlist and
876 is not the first, nor the second where the first character is
877 a ^, nor the last character, it will be treated as a regular character.
878 - p Matches a set of sequences, which are the same as the set of
879 sequences that are produced by the %p conversion of the fprintf
880 function. The corresponding argument must be a pointer to a
881 pointer to void. The input item is converted to a pointer value.
882 If the input item is a value converted earlier during the same
883 program execution, the pointer that results will compare equal
884 to that value; otherwise the behavior of the %p conversion is
885 indeterminate.
886 - n No input is consumed. The corresponding argument shall be a
887 pointer to signed integer into which is to be written the
888 number of characters read from the input stream so far by this
889 call to the fscanf function. Execution of a %n directive does
890 not increment the assignment count returned at the completion
891 of execution of the fscanf function. No argument is converted,
892 but one is consumed. If the conversion specification includes
893 an assignment suppressing character the conversion specification
894 is ignored. If the conversion specification contains a
895 field width, the field width will be ignored.
896 - % Matches a single % character; no conversion or assignment occurs.
897
898 @param[in] stream An open File specifier from which the input is read.
899 @param[in] format A multi-byte character sequence containing characters
900 to be matched against, and conversion specifiers
901 which convert their associated arguments. Converted
902 items are stored according to their associated arguments.
903 @param ... Variable number of parameters, as required by format,
904 specifying the objects to receive the converted input.
905
906 @return The fscanf function returns EOF if an input failure occurs before
907 any conversion. Otherwise the number of input items assigned
908 is returned; which can be fewer than provided for, or even zero
909 in the event of an early matching failure.
910 **/
911 int fscanf (FILE * __restrict stream, const char * __restrict format, ...);
912
913 /** Formatted print to stdout.
914
915 The printf function is equivalent to fprintf with stdout used as the output stream.
916
917 @param[in] format A multi-byte character sequence containing characters
918 to be copied unchanged, and conversion specifiers
919 which convert their associated arguments. Copied and
920 converted characters are sent to the output stream.
921 @param ... Variable number of parameters as required by format.
922
923 @return The printf function returns the number of characters
924 transmitted, or a negative value if an output or encoding
925 error occurred.
926 **/
927 int printf (const char * __restrict format, ...);
928
929 /** Formatted input from stdin.
930
931 The scanf function is equivalent to fscanf with stdin used as the input stream.
932
933 @param[in] format A multi-byte character sequence containing characters
934 to be matched against, and conversion specifiers
935 which convert their associated arguments. Converted
936 items are stored according to their associated arguments.
937 @param[out] ... Variable number of parameters, as required by format,
938 specifying the objects to receive the converted input.
939
940 @return The scanf function returns EOF if an input failure occurs before
941 any conversion. Otherwise the number of input items assigned
942 is returned; which can be fewer than provided for, or even zero
943 in the event of an early matching failure.
944 **/
945 int scanf (const char * __restrict format, ...);
946
947 /** Formatted output to a buffer.
948
949 The sprintf function is equivalent to fprintf, except that the output is
950 written into array Buff instead of to a stream. A null character is written
951 at the end of the characters written; it is not counted as part of the
952 returned value.
953
954 @param[out] Buff A pointer to the array to receive the formatted output.
955 @param[in] Format A multi-byte character sequence containing characters
956 to be copied unchanged, and conversion specifiers
957 which convert their associated arguments. Copied and
958 converted characters are written to the array pointed
959 to by Buff.
960 @param ... Variable number of parameters as required by format.
961
962 @return The sprintf function returns the number of characters written in
963 the array, not counting the terminating null character, or a
964 negative value if an encoding error occurred.
965 **/
966 int sprintf (char * __restrict Buff, const char * __restrict Format, ...);
967
968 /** Formatted input from a string.
969
970 The sscanf function is equivalent to fscanf, except that input is obtained
971 from a string rather than from a stream. Reaching the end of the string
972 is equivalent to encountering end-of-file for the fscanf function.
973
974 @param[in] Buff Pointer to the string from which to obtain input.
975 @param[in] Format A multi-byte character sequence containing characters
976 to be matched against, and conversion specifiers
977 which convert their associated arguments. Converted
978 items are stored according to their associated arguments.
979 @param[out] ... Variable number of parameters, as required by format,
980 specifying the objects to receive the converted input.
981
982 @return The scanf function returns EOF if an input failure occurs before
983 any conversion. Otherwise the number of input items assigned
984 is returned; which can be fewer than provided for, or even zero
985 in the event of an early matching failure.
986 **/
987 int sscanf (const char * __restrict Buff, const char * __restrict Format, ...);
988
989 /** Print formatted values from an argument list.
990
991 The vfprintf function is equivalent to fprintf, with the variable argument
992 list replaced by Args, which must have been initialized by the va_start macro.
993 The vfprintf function does not invoke the va_end macro.
994
995 @param[in] Stream The output stream to receive the formatted output.
996 @param[in] Format A multi-byte character sequence containing characters
997 to be matched against, and conversion specifiers
998 which convert their associated arguments. Converted
999 items are stored according to their associated arguments.
1000 @param[in] Args A list of arguments, initialized by the va_start macro
1001 and accessed using the va_arg macro, used to satisfy
1002 the directives in the Format string.
1003
1004 @return The vfprintf function returns the number of characters transmitted,
1005 or a negative value if an output or encoding error occurred.
1006 **/
1007 int vfprintf(FILE * __restrict Stream, const char * __restrict Format, va_list Args);
1008
1009 /** Formatted print, to stdout, from an argument list.
1010
1011 The vprintf function is equivalent to printf, with the variable argument
1012 list replaced by Args, which must have been initialized by the va_start
1013 macro (and possibly subsequent va_arg calls). The vprintf function does
1014 not invoke the va_end macro.
1015
1016 @param[in] Format A multi-byte character sequence containing characters
1017 to be matched against, and conversion specifiers
1018 which convert their associated arguments. Converted
1019 items are stored according to their associated arguments.
1020 @param[in] Args A list of arguments, initialized by the va_start macro
1021 and accessed using the va_arg macro, used to satisfy
1022 the directives in the Format string.
1023
1024 @return The vprintf function returns the number of characters transmitted,
1025 or a negative value if an output or encoding error occurred.
1026 **/
1027 int vprintf (const char * __restrict Format, va_list Args);
1028
1029 /** Formatted print, to a buffer, from an argument list.
1030
1031 The vsprintf function is equivalent to sprintf, with the variable argument
1032 list replaced by Args, which must have been initialized by the va_start
1033 macro. The vsprintf function does not invoke the va_end macro.
1034
1035 @param[out] Buff A pointer to the array to receive the formatted output.
1036 @param[in] Format A multi-byte character sequence containing characters
1037 to be copied unchanged, and conversion specifiers
1038 which convert their associated arguments. Copied and
1039 converted characters are written to the array pointed
1040 to by Buff.
1041 @param[in] Args A list of arguments, initialized by the va_start macro
1042 and accessed using the va_arg macro, used to satisfy
1043 the directives in the Format string.
1044
1045 @return The vsprintf function returns the number of characters written in
1046 the array, not counting the terminating null character, or a
1047 negative value if an encoding error occurred.
1048 **/
1049 int vsprintf(char * __restrict Buff, const char * __restrict Format, va_list Args);
1050
1051 /* ################ Character Input/Output Functions. */
1052
1053 /** Get a character from an input Stream.
1054
1055 If the end-of-file indicator for the input stream pointed to by Stream is
1056 not set, and a next character is present, the fgetc function obtains that
1057 character as an unsigned char converted to an int and advances the
1058 associated file position indicator for the stream.
1059
1060 @param[in] Stream An input stream from which to obtain a character.
1061
1062 @return If the end-of-file indicator for the stream is set, or if the
1063 stream is at end-of-file, the end-of-file indicator for the
1064 stream is set and the fgetc function returns EOF. Otherwise,
1065 the fgetc function returns the next character from the input
1066 stream pointed to by Stream. If a read error occurs, the
1067 error indicator for the stream is set and the fgetc function
1068 returns EOF.
1069 **/
1070 int fgetc (FILE *Stream);
1071
1072 /** Read a string from an input stream into a buffer.
1073
1074 The fgets function reads at most one less than the number of characters
1075 specified by Limit from the stream pointed to by Stream into the array
1076 pointed to by Buff. No additional characters are read after a
1077 new-line character (which is retained) or after end-of-file. A null
1078 character is written immediately after the last character read into the array.
1079
1080 @param[out] Buff A pointer to the array to receive the input string.
1081 @param[in] Limit The maximum number of characters to put into Buff,
1082 including the terminating null character.
1083 @param[in] Stream An input stream from which to obtain a character.
1084
1085 @return The fgets function returns Buff if successful. If end-of-file is
1086 encountered and no characters have been read into the array, the
1087 contents of the array remain unchanged and a null pointer is
1088 returned. If a read error occurs during the operation, the array
1089 contents are indeterminate and a null pointer is returned.
1090 **/
1091 char *fgets (char * __restrict Buff, int Limit, FILE * __restrict Stream);
1092
1093 /** Write a character to an output stream.
1094
1095 The fputc function writes the character specified by C (converted to an
1096 unsigned char) to the output stream pointed to by Stream, at the position
1097 indicated by the associated file position indicator for the stream
1098 (if defined), and advances the indicator appropriately. If the file cannot
1099 support positioning requests, or if the stream was opened with append mode,
1100 the character is appended to the output stream.
1101
1102 @param[in] C The character to be written to Stream.
1103 @param[in] Stream The output stream that C is to be written to.
1104
1105 @return The fputc function returns the character written. If a write
1106 error occurs, the error indicator for the stream is set and
1107 fputc returns EOF.
1108 **/
1109 int fputc (int C, FILE *Stream);
1110
1111 /** Write a string to an output stream.
1112
1113 The fputs function writes String to the stream pointed to by Stream. The
1114 terminating null character is not written.
1115
1116 @param[in] String The character string to be written to Stream.
1117 @param[in] Stream The output stream that String is to be written to.
1118
1119 @return The fputs function returns EOF if a write error occurs; otherwise
1120 it returns a non-negative value.
1121 **/
1122 int fputs (const char * __restrict String, FILE * __restrict Stream);
1123
1124 /** Get a character from an input stream.
1125
1126 The getc function is equivalent to fgetc, except that if it is implemented
1127 as a macro, it may evaluate stream more than once, so the argument should
1128 never be an expression with side effects.
1129
1130 @param[in] Stream An input stream from which to obtain a character.
1131
1132 @return If the end-of-file indicator for the stream is set, or if the
1133 stream is at end-of-file, the end-of-file indicator for the
1134 stream is set and getc returns EOF. Otherwise, getc returns
1135 the next character from the input stream pointed to by Stream.
1136 If a read error occurs, the error indicator for the stream is set
1137 and getc returns EOF.
1138 **/
1139 int getc (FILE *);
1140
1141 /** Get a character from stdin.
1142
1143 The getchar function is equivalent to getc with the argument stdin.
1144
1145 @return If the end-of-file indicator for stdin is set, or if stdin
1146 is at end-of-file, the end-of-file indicator is set and getchar
1147 returns EOF. Otherwise, getchar returns the next character from
1148 stdin. If a read error occurs, the error indicator for stdin is
1149 set and getchar returns EOF.
1150 **/
1151 int getchar (void);
1152
1153 /** Read a string from stdin into a buffer.
1154
1155 The gets function reads characters from the input stream pointed to by
1156 stdin, into the array pointed to by Buff, until end-of-file is encountered
1157 or a new-line character is read. Any new-line character is discarded, and
1158 a null character is written immediately after the last character read into
1159 the array.
1160
1161 @param[out] Buff A pointer to the array to receive the input string.
1162
1163 @return The gets function returns Buff if successful. If end-of-file is
1164 encountered and no characters have been read into the array, the
1165 contents of the array remain unchanged and a null pointer is
1166 returned. If a read error occurs during the operation, the array
1167 contents are indeterminate and a null pointer is returned.
1168 **/
1169 char *gets (char *Buff);
1170
1171 /** Write a character to an output stream.
1172
1173 The putc function is equivalent to fputc, except that if it is implemented
1174 as a macro, it may evaluate Stream more than once, so that argument should
1175 never be an expression with side effects.
1176
1177 @param[in] C The character to be written to Stream.
1178 @param[in] Stream The output stream that C is to be written to.
1179
1180 @return The putc function returns the character written. If a write
1181 error occurs, the error indicator for the stream is set and
1182 putc returns EOF.
1183 **/
1184 int putc (int C, FILE *Stream);
1185
1186 /** Write a character to stdout.
1187
1188 The putchar function is equivalent to putc with stdout as the Stream argument.
1189
1190 @param[in] C The character to be written to stdout.
1191
1192 @return The putchar function returns the character written. If a write
1193 error occurs, the error indicator for stdout is set and putchar
1194 returns EOF.
1195 **/
1196 int putchar (int C);
1197
1198 /** Write String to stdout.
1199
1200 The puts function writes the string pointed to by String to the stream
1201 pointed to by stdout, and appends a new-line character to the output. The
1202 terminating null character is not written.
1203
1204 @param[in] String A pointer to the character string to write to stdout.
1205
1206 @return The puts function returns EOF if a write error occurs; otherwise
1207 it returns a non-negative value.
1208 **/
1209 int puts (const char *String);
1210
1211 /** Return a character to the input Stream as if it had not been read.
1212
1213 The ungetc function pushes the character specified by C (converted to an
1214 unsigned char) back onto the input stream pointed to by Stream. Pushed-back
1215 characters will be returned by subsequent reads on that stream in the
1216 reverse order of their being pushed. A successful intervening call
1217 (with the stream pointed to by Stream) to a file positioning function
1218 (fseek, fsetpos, or rewind) discards any pushed-back characters for the
1219 stream. The external storage corresponding to the stream is unchanged.
1220
1221 One character of pushback is guaranteed. If the ungetc function is called
1222 too many times on the same stream without an intervening read or file
1223 positioning operation on that stream, the operation will fail.
1224
1225 If the value of C equals that of the macro EOF, the operation fails and the
1226 input stream is unchanged.
1227
1228 A successful call to the ungetc function clears the end-of-file indicator
1229 for the stream. The value of the file position indicator for the stream
1230 after reading or discarding all pushed-back characters is the same as it
1231 was before the characters were pushed back. For a binary stream, its
1232 file position indicator is decremented by each successful call to the
1233 ungetc function; if its value was zero before a call, it will remain zero
1234 after the call.
1235
1236 @param[in] C The character to push back onto the Stream.
1237 @param[in] Stream The output stream that C is to be pushed back onto.
1238
1239 @return The ungetc function returns the character pushed back,
1240 or EOF if the operation fails.
1241 **/
1242 int ungetc (int C, FILE *Stream);
1243
1244 /* ################ Direct Input/Output Functions. */
1245
1246 /** Read Num elements of size Size from a Stream into a Buffer.
1247
1248 The fread function reads, into the array pointed to by Buffer, up to Num
1249 elements, whose size is specified by Size, from the stream pointed to by
1250 Stream. For each object, Size calls are made to the fgetc function and the
1251 results stored, in the order read, in an array of unsigned char exactly
1252 overlaying the Buffer object. The file position indicator for the stream
1253 (if defined) is advanced by the number of characters successfully read. If
1254 an error occurs, the resulting value of the file position indicator for the
1255 stream is indeterminate.
1256
1257 @param[out] Buffer Pointer to an object to receive the read data.
1258 @param[in] Size Size of each element to be read.
1259 @param[in] Num Number of elements to read.
1260 @param[in] Stream Input stream to read the data from.
1261
1262 @return The fread function returns the number of elements successfully
1263 read, which may be less than Num if a read error or end-of-file
1264 is encountered. If Size or Num is zero, fread returns zero and
1265 the contents of the array and the state of the stream remain
1266 unchanged.
1267 **/
1268 size_t fread (void * __restrict Buffer,
1269 size_t Size,
1270 size_t Num,
1271 FILE * __restrict Stream
1272 );
1273
1274 /** Write Num elements of size Size from Buffer to Stream.
1275
1276 The fwrite function writes, from the array pointed to by Buffer, up to Num
1277 elements whose size is specified by Size, to the stream pointed to by
1278 Stream. For each object, Size calls are made to the fputc function, taking
1279 the values (in order) from an array of unsigned char exactly overlaying the
1280 Buffer object. The file position indicator for the stream (if defined) is
1281 advanced by the number of characters successfully written. If an error
1282 occurs, the resulting value of the file position indicator for the stream is
1283 indeterminate.
1284
1285 @param[out] Buffer Pointer to an object containing the data to be written.
1286 @param[in] Size Size of each element to be written.
1287 @param[in] Num Number of elements to write.
1288 @param[in] Stream Output stream to write the data to.
1289
1290 @return The fwrite function returns the number of elements successfully
1291 written, which will be less than Num only if a write error is
1292 encountered. If Size or Num is zero, fwrite returns zero and
1293 the state of the stream remains unchanged.
1294 **/
1295 size_t fwrite (void * __restrict Buffer,
1296 size_t Size,
1297 size_t Num,
1298 FILE * __restrict Stream
1299 );
1300
1301 /* ################ File Positioning Functions. */
1302
1303 /** Get a stream's position and parse state.
1304
1305 The fgetpos function stores the current values of the parse state (if any)
1306 and file position indicator for the stream pointed to by Stream in the
1307 object pointed to by Pos. The values stored contain unspecified
1308 information usable by the fsetpos function for repositioning the stream
1309 to its position at the time of the call to the fgetpos function.
1310
1311 @param[in] Stream Stream to get current position of.
1312 @param[out] Pos Object to receive the stream's state and position information.
1313
1314 @return If successful, the fgetpos function returns zero; if either
1315 parameter is NULL, the fgetpos function returns nonzero and
1316 stores EINVAL in errno.
1317 **/
1318 int fgetpos (FILE * __restrict Stream, fpos_t * __restrict Pos);
1319
1320 /** Set the file position for a stream.
1321
1322 The fseek function sets the file position indicator for the stream pointed
1323 to by Stream. If a read or write error occurs, the error indicator for the
1324 stream is set and fseek fails.
1325
1326 For a binary stream, the new position, measured in characters from the
1327 beginning of the file, is obtained by adding Offset to the position
1328 specified by Whence. The specified position is the beginning of the file if
1329 Whence is SEEK_SET, the current value of the file position indicator if
1330 SEEK_CUR, or end-of-file if SEEK_END.
1331
1332 For a text stream, Offset must either be zero or a value returned by an
1333 earlier successful call to the ftell function, on a stream associated with
1334 the same file, and Whence must be SEEK_SET.
1335
1336 After determining the new position, a successful call to the fseek function
1337 undoes any effects of the ungetc function on the stream, clears the
1338 end-of-file indicator for the stream, and then establishes the new position.
1339 After a successful fseek call, the next operation on an update stream may
1340 be either input or output.
1341
1342 @param[in] Stream The I/O stream to set the position of.
1343 @param[in] Offset The position, interpreted depending upon the value of
1344 Whence, that the stream is to be positioned to.
1345 @param[in] Whence A value indicating how Offset is to be interpreted:
1346 - SEEK_SET indicates Offset is an absolute position.
1347 - SEEK_END indicates Offset is relative to the end of the file.
1348 - SEEK_CUR indicates Offset is relative to the current position.
1349
1350 @return The fseek function returns nonzero only for a request that cannot be satisfied.
1351 **/
1352 int fseek (FILE *Stream, long Offset, int Whence);
1353
1354 /** Set a stream's position and parse state.
1355
1356 The fsetpos function sets the mbstate_t object (if any) and file position
1357 indicator for the stream pointed to by Stream according to the value of the
1358 object pointed to by Pos, which is a value that was obtained from an
1359 earlier successful call to the fgetpos function on a stream associated with
1360 the same file. If a read or write error occurs, the error indicator for the
1361 stream is set and fsetpos fails.
1362
1363 A successful call to the fsetpos function undoes any effects of the ungetc
1364 function on the stream, clears the end-of-file indicator for the stream,
1365 and then establishes the new parse state and position. After a successful
1366 fsetpos call, the next operation on an update stream may be either input or output.
1367
1368 @param[in] Stream Stream to set current position of.
1369 @param[in] Pos Object containing the state and position information.
1370
1371 @return If successful, the fsetpos function returns zero; on failure, the
1372 fsetpos function returns nonzero and stores EINVAL, or ESPIPE,
1373 in errno; depending upon whether the error was because of an invalid
1374 parameter, or because Stream is not seekable.
1375 **/
1376 int fsetpos (FILE *Stream, const fpos_t *Pos);
1377
1378 /** Get Stream's current position.
1379
1380 The ftell function obtains the current value of the file position indicator
1381 for the stream pointed to by Stream. For a binary stream, the value is the
1382 number of characters from the beginning of the file. For a text stream, its
1383 file position indicator contains unspecified information, usable by the
1384 fseek function for returning the file position indicator for the stream to
1385 its position at the time of the ftell call; the difference between two such
1386 return values is not necessarily a meaningful measure of the number of
1387 characters written or read.
1388
1389 @param[in] Stream Pointer to the FILE object to get the current position of.
1390
1391 @return If successful, the ftell function returns the current value of
1392 the file position indicator for the stream. On failure, the
1393 ftell function returns -1L and stores ESPIPE in errno indicating
1394 that the stream is not seekable.
1395 **/
1396 long ftell (FILE *Stream);
1397
1398 /** Restore a Stream's file position to the beginning of the file.
1399
1400 The rewind function sets the file position indicator for the stream pointed
1401 to by Stream to the beginning of the file and clears the stream's error indicator.
1402
1403 @param[in] Stream Pointer to the stream to be positioned to its beginning.
1404 **/
1405 void rewind (FILE *Stream);
1406
1407 /* ################ Error-handling Functions. */
1408
1409 /** Clear a Stream's error and end-of-file indicators.
1410
1411 @param[in] Stream Pointer to the stream to be cleared of errors.
1412 **/
1413 void clearerr(FILE *Stream);
1414
1415 /** Test the end-of-file indicator for Stream.
1416
1417 @param[in] Stream Pointer to the FILE object to be tested for EOF.
1418
1419 @return The feof function returns non-zero if, and only if, the end-of-file
1420 indicator is set for Stream.
1421 **/
1422 int feof (FILE *Stream);
1423
1424 /** Test the error indicator for Stream.
1425
1426 @param[in] Stream Pointer to the stream to be tested for error.
1427
1428 @return The ferror function returns non-zero if, and only if, the error
1429 indicator is set for Stream.
1430 **/
1431 int ferror (FILE *Stream);
1432
1433 /** Print an error message to stderr based upon the value of errno and String.
1434
1435 The perror function maps the error number in the integer expression errno
1436 to an error message. It writes a sequence of characters to the standard
1437 error stream thus: first (if String is not a null pointer and the character
1438 pointed to by String is not the null character), the string pointed to by
1439 String followed by a colon (:) and a space; then an appropriate error
1440 message string followed by a new-line character. The contents of the error
1441 message strings are the same as those returned by the strerror function
1442 with argument errno.
1443
1444 @param[in] String A text string to prefix the output error message with.
1445
1446 @sa strerror in <string.h>
1447 **/
1448 void perror (const char *String);
1449
1450 __END_DECLS
1451
1452 /*
1453 * IEEE Std 1003.1-90
1454 */
1455 __BEGIN_DECLS
1456 FILE *fdopen(int, const char *);
1457 __END_DECLS
1458
1459 /*
1460 * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
1461 */
1462 __BEGIN_DECLS
1463 void flockfile (FILE *);
1464 int ftrylockfile (FILE *);
1465 void funlockfile (FILE *);
1466 int getc_unlocked (FILE *);
1467 int getchar_unlocked(void);
1468 int putc_unlocked (int, FILE *);
1469 int putchar_unlocked(int);
1470 __END_DECLS
1471
1472 /*
1473 * Functions defined in POSIX 1003.2 and XPG2 or later.
1474 */
1475 __BEGIN_DECLS
1476 int pclose (FILE *);
1477 FILE *popen (const char *, const char *);
1478 __END_DECLS
1479
1480 /*
1481 * Functions defined in ISO XPG4.2, ISO C99, POSIX 1003.1-2001 or later.
1482 */
1483 __BEGIN_DECLS
1484 int snprintf (char * __restrict, size_t, const char * __restrict, ...)
1485 __attribute__((__format__(__printf__, 3, 4)));
1486 int vsnprintf(char * __restrict, size_t, const char * __restrict, va_list)
1487 __attribute__((__format__(__printf__, 3, 0)));
1488 __END_DECLS
1489
1490 /*
1491 * Functions defined in XPG4.2.
1492 */
1493 __BEGIN_DECLS
1494 //int getw(FILE *);
1495 //int putw(int, FILE *);
1496 char *mkdtemp(char *);
1497 int mkstemp(char *);
1498 char *mktemp(char *);
1499
1500 char *tempnam(const char *, const char *);
1501 __END_DECLS
1502
1503 /*
1504 * X/Open CAE Specification Issue 5 Version 2
1505 */
1506 #ifndef off_t
1507 typedef __off_t off_t;
1508 #define off_t __off_t
1509 #endif /* off_t */
1510
1511 __BEGIN_DECLS
1512 int fseeko(FILE *, off_t, int);
1513 //off_t ftello(FILE *);
1514 __END_DECLS
1515
1516 /*
1517 * Routines that are purely local.
1518 */
1519 #define FPARSELN_UNESCESC 0x01
1520 #define FPARSELN_UNESCCONT 0x02
1521 #define FPARSELN_UNESCCOMM 0x04
1522 #define FPARSELN_UNESCREST 0x08
1523 #define FPARSELN_UNESCALL 0x0f
1524
1525 __BEGIN_DECLS
1526 //int asprintf(char ** __restrict, const char * __restrict, ...)
1527 // __attribute__((__format__(__printf__, 2, 3)));
1528 char *fgetln(FILE * __restrict, size_t * __restrict);
1529 char *fparseln(FILE *, size_t *, size_t *, const char[3], int);
1530 int fpurge(FILE *);
1531 void setbuffer(FILE *, char *, int);
1532 int setlinebuf(FILE *);
1533 int vasprintf(char ** __restrict, const char * __restrict,
1534 va_list)
1535 __attribute__((__format__(__printf__, 2, 0)));
1536 int vscanf(const char * __restrict, va_list)
1537 __attribute__((__format__(__scanf__, 1, 0)));
1538 //int vfscanf(FILE * __restrict, const char * __restrict,
1539 // va_list)
1540 // __attribute__((__format__(__scanf__, 2, 0)));
1541 int vsscanf(const char * __restrict, const char * __restrict,
1542 va_list)
1543 __attribute__((__format__(__scanf__, 2, 0)));
1544 //const char *fmtcheck(const char *, const char *)
1545 // __attribute__((__format_arg__(2)));
1546 __END_DECLS
1547
1548 /*
1549 * Stdio function-access interface.
1550 */
1551 __BEGIN_DECLS
1552 FILE *funopen(const void *,
1553 int (*)(void *, char *, int),
1554 int (*)(void *, const char *, int),
1555 fpos_t (*)(void *, fpos_t, int),
1556 int (*)(void *));
1557 __END_DECLS
1558 //#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
1559 //#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
1560
1561 /*
1562 * Functions internal to the implementation.
1563 */
1564 __BEGIN_DECLS
1565 int __srget(FILE *);
1566 int __swbuf(int, FILE *);
1567 __END_DECLS
1568
1569 /*
1570 * The __sfoo macros are here so that we can
1571 * define function versions in the C library.
1572 */
1573 #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
1574
1575 #if defined(__GNUC__) && defined(__STDC__)
1576 static __inline int __sputc(int _c, FILE *_p) {
1577 if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
1578 return (*_p->_p++ = _c);
1579 else
1580 return (__swbuf(_c, _p));
1581 }
1582 #else
1583 /*
1584 * This has been tuned to generate reasonable code on the vax using pcc.
1585 */
1586 #define __sputc(c, p) \
1587 (--(p)->_w < 0 ? \
1588 (p)->_w >= (p)->_lbfsize ? \
1589 (*(p)->_p = (unsigned char)(c)), *(p)->_p != '\n' ? \
1590 (int)*(p)->_p++ : \
1591 __swbuf('\n', p) : \
1592 __swbuf((int)(c), p) : \
1593 (*(p)->_p = (unsigned char)(c), (int)*(p)->_p++))
1594 #endif
1595
1596 #define __sfeof(p) (((p)->_flags & __SEOF) != 0)
1597 #define __sferror(p) (((p)->_flags & __SERR) != 0)
1598 #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
1599 #define __sfileno(p) ((p)->_file)
1600
1601 #ifndef __lint__
1602 #define feof(p) __sfeof(p)
1603 #define ferror(p) __sferror(p)
1604 #define clearerr(p) __sclearerr(p)
1605
1606 #define getc(fp) __sgetc(fp)
1607 #define putc(x, fp) __sputc(x, fp)
1608 #endif /* __lint__ */
1609
1610 #define getchar() getc(stdin)
1611 #define putchar(x) putc(x, stdout)
1612
1613 #define fileno(p) __sfileno(p)
1614
1615 #define getc_unlocked(fp) __sgetc(fp)
1616 #define putc_unlocked(x, fp) __sputc(x, fp)
1617
1618 #define getchar_unlocked() getc_unlocked(stdin)
1619 #define putchar_unlocked(x) putc_unlocked(x, stdout)
1620
1621 #endif /* _STDIO_H_ */