• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @defgroup stdio Stdio
3  * @ingroup libc
4  */
5 
6 #ifndef _STDIO_H
7 #define _STDIO_H
8 
9 #ifdef __LITEOS__
10 #include <stdbool.h>
11 #endif
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #include <features.h>
18 
19 #define __NEED_FILE
20 #define __NEED___isoc_va_list
21 #define __NEED_size_t
22 
23 #if __STDC_VERSION__ < 201112L
24 #define __NEED_struct__IO_FILE
25 #endif
26 
27 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
28  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
29  || defined(_BSD_SOURCE)
30 #define __NEED_ssize_t
31 #define __NEED_off_t
32 #define __NEED_va_list
33 #endif
34 
35 #ifdef __LITEOS__
36 #define __NEED_int64_t
37 #endif
38 
39 #include <bits/alltypes.h>
40 
41 #ifdef __cplusplus
42 #define NULL 0L
43 #else
44 #ifndef NULL
45 #define NULL ((void*)0)
46 #endif
47 #endif
48 
49 #undef EOF
50 #define EOF (-1)
51 
52 #undef SEEK_SET
53 #undef SEEK_CUR
54 #undef SEEK_END
55 #define SEEK_SET 0
56 #define SEEK_CUR 1
57 #define SEEK_END 2
58 
59 #define _IOFBF 0
60 #define _IOLBF 1
61 #define _IONBF 2
62 
63 #ifdef __LITEOS__
64 #define BUFSIZ (8 * 1024)
65 #else
66 #define BUFSIZ 1024
67 #endif
68 #define FILENAME_MAX 4096
69 #define FOPEN_MAX 1000
70 #define TMP_MAX 10000
71 #define L_tmpnam 20
72 
73 #ifndef __LITEOS__
74 typedef union _G_fpos64_t {
75 	char __opaque[16];
76 	long long __lldata;
77 	double __align;
78 } fpos_t;
79 #else
80 typedef off_t fpos_t;
81 #endif
82 
83 extern FILE *const stdin;
84 extern FILE *const stdout;
85 extern FILE *const stderr;
86 
87 #define stdin  (stdin)
88 #define stdout (stdout)
89 #define stderr (stderr)
90 
91 /**
92  * @ingroup stdio
93  *
94  * @par Description:
95  * The fopen() function shall open the file whose pathname is the string pointed to by pathname, and associates a stream
96  * with it.
97  *
98  * @attention
99  * <ul>
100  * <li>None.</li>
101  * </ul>
102  *
103  * @retval #FILE* Upon successful completion, fopen() shall return a pointer to the object controlling the stream.\n
104  *                Otherwise, a null pointer shall be returned, and errno shall be set to indicate the error.
105  *
106  * @par Errors
107  * <ul>
108  * <li><b>EINVAL</b>: The mode argument is not a valid mode.</li>
109  * <li><b>EMFILE</b>: The file descriptor is greater than SHRT_MAX</li>
110  * </ul>
111  *
112  * @par Dependency:
113  * <ul><li>stdio.h</li></ul>
114  * @see open | fdopen | fclose
115  */
116 FILE *fopen(const char *__restrict, const char *__restrict);
117 
118 /**
119  * @ingroup stdio
120  *
121  * @par Description:
122  * The freopen() function opens the file whose name is the string pointed to by path and associates the stream pointed
123  * to by stream with it. The original stream (if it exists) is closed.
124  *
125  * @attention
126  * <ul>
127  * <li>when the file where is in the target directory mounted by the file system, the func returns NULL.</li>
128  * </ul>
129  *
130  * @retval #FILE* The freopen() function shall return a pointer to a stream, if it completes successfully;\n
131  *                otherwise, a null pointer shall be returned and errno set to indicate the error.
132  *
133  * @par Dependency:
134  * <ul><li>stdio.h</li></ul>
135  * @see open | fopen | fclose
136  */
137 FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict);
138 
139 /**
140  * @ingroup stdio
141  *
142  * @par Description:
143  * The fclose() function shall clear the end-of-file and error indicators for the stream to which stream points.
144  *
145  * @attention
146  * <ul>
147  * <li>None.</li>
148  * </ul>
149  *
150  * @retval #int The fclose() shall return 0, if it completes successfully;\n
151  *             otherwise, it shall return EOF.
152  *
153  * @par Errors
154  * <ul>
155  * <li><b>EBADF</b>: The file descriptor underlying stream is not valid.</li>
156  * </ul>
157  *
158  * @par Dependency:
159  * <ul><li>stdio.h</li></ul>
160  * @see fopen | fflush
161  */
162 int fclose(FILE *);
163 
164 /**
165  * @ingroup stdio
166  *
167  * @par Description:
168  * The remove() function shell remove a file or directory.
169  *
170  * @attention
171  * <ul>
172  * <li>None.</li>
173  * </ul>
174  *
175  * @retval #int The remove() function shall return 0, if it completes successfully;\n
176  *              otherwise, it shall return -1 and set errno to indicate the error.
177  *
178  * @par Dependency:
179  * <ul><li>stdio.h</li></ul>
180  * @see unlink | rmdir
181  */
182 int remove(const char *);
183 
184 /**
185  * @ingroup stdio
186  *
187  * @par Description:
188  * The rename() function shall change the name of a file.
189  *
190  * @attention
191  * <ul>
192  * <li>None.</li>
193  * </ul>
194  *
195  * @retval #int Upon successful completion, the rename() function shall return 0.\n
196  *              Otherwise, it shall return -1 and errno shall be set to indicate the error.
197  *
198  * @par Errors
199  * <ul>
200  * <li><b>EINVAL</b>: Invalid argument.</li>
201  * <li><b>ENOENT</b>: No such file or directory./li>
202  * <li><b>EXDEV</b>: Cross-device link.</li>
203  * <li><b>ENOSYS</b>: Rename function not implemented.</li>
204  * <li><b>EBUSY</b>: Device or resource busy.</li>
205  * <li><b>EEXIST</b>: File exists.</li>
206  * <li><b>ENXIO</b>: No such device or address.</li>
207  * </ul>
208  *
209  * @par Dependency:
210  * <ul><li>stdio.h</li></ul>
211  * @see rmdir | unlink
212  */
213 int rename(const char *, const char *);
214 
215 /**
216  * @ingroup stdio
217  *
218  * @par Description:
219  * The feof() function shall test the end-of-file indicator for the stream pointed to by stream.
220  *
221  * @attention
222  * <ul>
223  * <li>None.</li>
224  * </ul>
225  *
226  * @retval #int The feof() shall return non-zero if and only if the end-of-file indicator is set for stream.
227  * @par Dependency:
228  * <ul><li>stdio.h</li></ul>
229  * @see clearerr | ferror | fopen
230  */
231 int feof(FILE *);
232 
233 /**
234  * @ingroup stdio
235  *
236  * @par Description:
237  * The ferror() function shall test the error indicator for the stream pointed to by stream.
238  *
239  * @attention
240  * <ul>
241  * <li>None.</li>
242  * </ul>
243  *
244  * @retval #int The ferror() function shall return non-zero if and only if the error indicator is set for stream.
245  * @par Dependency:
246  * <ul><li>stdio.h</li></ul>
247  * @see clearerr | feof | fopen
248  */
249 int ferror(FILE *);
250 
251 /**
252  * @ingroup stdio
253  *
254  * @par Description:
255  * If stream points to an output stream or an update stream in which the most recent operation was not input, fflush()
256  * shall cause any unwritten data for that stream to be written to the file, [CX] [Option Start]  and the last data
257  * modification and last file status change timestamps of the underlying file shall be marked for update.
258  *
259  * @attention
260  * <ul>
261  * <li>None.</li>
262  * </ul>
263  *
264  * @retval #int The fflush() function shall return 0, if it completes successfully;\n
265  *              otherwise, it shall set the error indicator for the stream, return EOF and set errno to
266  *              indicate the error.
267  *
268  * @par Errors
269  * <ul>
270  * <li><b>EBADF</b>: The file descriptor underlying stream is not valid.</li>
271  * <li><b>ENOBUFS</b>: No buffer space available.</li>
272  * </ul>
273  *
274  * @par Dependency:
275  * <ul><li>stdio.h</li></ul>
276  * @see sync | write | fclose | fopen
277  */
278 int fflush(FILE *);
279 
280 /**
281  * @ingroup stdio
282  *
283  * @par Description:
284  * The clearerr() function shall clear the end-of-file and error indicators for the stream to which stream points.
285  *
286  * @attention
287  * <ul>
288  * <li>None.</li>
289  * </ul>
290  *
291  * @retval #void None.
292  * @par Dependency:
293  * <ul><li>stdio.h</li></ul>
294  * @see None
295  */
296 void clearerr(FILE *);
297 
298 /**
299  * @ingroup stdio
300  *
301  * @par Description:
302  * The fseek() function shall set the file-position indicator for the stream pointed to by stream.
303  *
304  * @attention
305  * <ul>
306  * <li>None.</li>
307  * </ul>
308  *
309  * @retval #int The fseek() function shall return 0, if it completes successfully;\n
310  *              otherwise, it shall return -1 and set errno to indicate the error.
311  *
312  * @par Errors
313  * <ul>
314  * <li><b>ESPIPE</b>: Illegal seek.</li>
315  * <li><b>EINVAL</b>: The whence argument to fseek() was not SEEK_SET, SEEK_END, or SEEK_CUR.</li>
316  * <li><b>EBADF</b>: The stream specified is not a seekable stream.</li>
317  * </ul>
318  *
319  * @par Dependency:
320  * <ul><li>stdio.h</li></ul>
321  * @see fopen | fgetpos | fseeko
322  */
323 int fseek(FILE *, long, int);
324 
325 /**
326  * @ingroup stdio
327  *
328  * @par Description:
329  * The ftell() function shall obtain the current value of the file-position indicator for the stream pointed to by stream.
330  *
331  * @attention
332  * <ul>
333  * <li>None.</li>
334  * </ul>
335  *
336  * @retval #long The ftell() function shall return the current offset, if it completes successfully;\n
337  *               otherwise, it shall return -1 and set errno to indicate the error.
338  *
339  * @par Errors
340  * <ul>
341  * <li><b>ESPIPE</b>: Illegal seek.</li>
342  * </ul>
343  *
344  * @par Dependency:
345  * <ul><li>stdio.h</li></ul>
346  * @see fseek | ftello
347  */
348 long ftell(FILE *);
349 
350 /**
351  * @ingroup stdio
352  *
353  * @par Description:
354  * The rewind() function sets the file position indicator for the stream pointed to by stream
355  * to the beginning of the file.  It is equivalent to:\n
356  *              (void) fseek(stream, 0L, SEEK_SET)
357  *
358  * @attention
359  * <ul>
360  * <li>None.</li>
361  * </ul>
362  *
363  * @retval #void None.
364  *
365  * @par Dependency:
366  * <ul><li>stdio.h</li></ul>
367  * @see fseek | fseeko
368  */
369 void rewind(FILE *);
370 
371 /**
372  * @ingroup stdio
373  *
374  * @par Description:
375  * The fgetpos() function shall store the current values of the parse state (if any) and file position indicator for the
376  * stream pointed to by stream in the object pointed to by pos.
377  *
378  * @attention
379  * <ul>
380  * <li>None.</li>
381  * </ul>
382  *
383  * @retval #int The fgetpos() function shall return 0, if it completes successfully;\n
384  *              otherwise, it shall return 1 and set errno to indicate the error.
385  *
386  * @par Errors
387  * <ul>
388  * <li><b>ESPIPE</b>: Illegal seek.</li>
389  * </ul>
390  *
391  * @par Dependency:
392  * <ul><li>stdio.h</li></ul>
393  * @see fopen | fsetpos
394  */
395 int fgetpos(FILE *__restrict, fpos_t *__restrict);
396 
397 /**
398  * @ingroup stdio
399  *
400  * @par Description:
401  * The fsetpos() function shall set the file position and state indicators for the stream.
402  *
403  * @attention
404  * <ul>
405  * <li>None.</li>
406  * </ul>
407  *
408  * @retval #int The fsetpos() function shall return 0, if it completes successfully;\n
409  *              otherwise, it shall return -1 and set errno to indicate the error.
410  *
411  * @par Errors
412  * <ul>
413  * <li><b>ESPIPE</b>: Illegal seek.</li>
414  * <li><b>EINVAL</b>: The whence argument to fseek() was not SEEK_SET, SEEK_END, or SEEK_CUR.</li>
415  * <li><b>EBADF</b>: The stream specified is not a seekable stream.</li>
416  * </ul>
417  *
418  * @par Dependency:
419  * <ul><li>stdio.h</li></ul>
420  * @see fseeko | fgetpos
421  */
422 int fsetpos(FILE *, const fpos_t *);
423 
424 /**
425  * @ingroup stdio
426  *
427  * @par Description:
428  * The fread() function shall read into the array pointed to by ptr up to nitems elements whose size is specified by
429  * size in bytes, from the stream pointed to by stream.
430  *
431  * @attention
432  * <ul>
433  * <li>None.</li>
434  * </ul>
435  *
436  * @retval #size_t Upon successful completion, fread() shall return the number of elements successfully read
437  *                 which is less than nitems only if a read error or end-of-file is encountered. \n
438  *                 If size or nitems is 0, fread() shall return 0 and the contents of the array
439  *                 and the state of the stream remain unchanged.\n
440  *                 Otherwise, if a read error occurs, the error indicator for the stream shall be set,
441  *                 and errno shall be set to indicate the error.
442  *
443  * @par Errors
444  * <ul>
445  * <li><b>EEOF</b>: The end of file has been reached</li>
446  * <li><b>EBADF</b>: Bad file number.</li>
447  * </ul>
448  *
449  * @par Dependency:
450  * <ul><li>stdio.h</li></ul>
451  * @see read | write | feof
452  */
453 size_t fread(void *__restrict, size_t, size_t, FILE *__restrict);
454 
455 /**
456  * @ingroup stdio
457  *
458  * @par Description:
459  * The fwrite() function shall write, from the array pointed to by ptr, up to nitems elements whose size is specified by
460  * size, to the stream pointed to by stream.
461  *
462  * @attention
463  * <ul>
464  * <li>None.</li>
465  * </ul>
466  *
467  * @retval #size_t The fwrite() function shall return the number of elements successfully written,
468  *                 which may be less than nitems if a write error is encountered.
469  *                 If size or nitems is 0, fwrite() shall return 0 and the state of the stream remains unchanged.
470  *                 Otherwise, if a write error occurs, the error indicator for the stream shall be set,
471  *                 and errno shall be set to indicate the error.
472  *
473  * @par Errors
474  * <ul>
475  * <li><b>EINVAL</b>: Invalid argument.</li>
476  * <li><b>EBADF</b>: Bad file number.</li>
477  * </ul>
478  *
479  * @par Dependency:
480  * <ul><li>stdio.h</li></ul>
481  * @see puts | fwrite | ferror | fopen
482  */
483 size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict);
484 
485 /**
486  * @ingroup stdio
487  *
488  * @par Description:
489  * the fgetc() function shall obtain the next byte as an unsigned char converted to an int, from the input stream.
490  *
491  * @attention
492  * <ul>
493  * <li>None.</li>
494  * </ul>
495  *
496  * @retval #int The fgetc() shall return the next byte from the input stream pointed to by stream
497  * @par Dependency:
498  * <ul><li>stdio.h</li></ul>
499  * @see feof | ferror | fgets | fread | fscanf | getchar | getc | gets
500  */
501 int fgetc(FILE *);
502 
503 /**
504  * @ingroup stdio
505  *
506  * @par Description:
507  * The getc() function shell get a byte from a stream.
508  *
509  * @attention
510  * <ul>
511  * <li>None.</li>
512  * </ul>
513  *
514  * @retval #int The getc() function return the character read as an unsigned char
515  *              cast to an int or EOF on end of file or error.
516  *
517  * @par Dependency:
518  * <ul><li>stdio.h</li></ul>
519  * @see putc | getchar
520  */
521 int getc(FILE *);
522 
523 /**
524  * @ingroup stdio
525  *
526  * @par Description:
527  * The getchar() function shell get a byte from a stdin stream.
528  *
529  * @attention
530  * <ul>
531  * <li>None.</li>
532  * </ul>
533  *
534  * @retval #int The getchar() function return the character read as an unsigned char
535  *              cast to an int or EOF on end of file or error.
536  *
537  * @par Dependency:
538  * <ul><li>stdio.h</li></ul>
539  * @see putchar | getc
540  */
541 int getchar(void);
542 
543 /**
544  * @ingroup stdio
545  *
546  * @par Description:
547  *  The ungetc() function shall push the byte specified by c (converted to an unsigned char)
548  *  back onto the input stream pointed to by stream.
549  *
550  * @attention
551  * <ul>
552  * <li>None.</li>
553  * </ul>
554  *
555  * @retval #int Upon successful completion, ungetc() shall return the byte pushed back after conversion.\n
556  *              Otherwise, it shall return EOF.
557  *
558  * @par Dependency:
559  * <ul><li>stdio.h</li></ul>
560  * @see fseek | getc | fsetpos
561  */
562 int ungetc(int, FILE *);
563 
564 /**
565  * @ingroup stdio
566  *
567  * @par Description:
568  * The fputc() function shall write the byte (converted to an unsigned char) to the output stream.
569  *
570  * @attention
571  * <ul>
572  * <li>None.</li>
573  * </ul>
574  *
575  * @retval #int The fputc() shall return the value it has written. Otherwise, it shall return EOF.
576  * @par Dependency:
577  * <ul><li>stdio.h</li></ul>
578  * @see fprintf | fscanf | fputs
579  */
580 int fputc(int, FILE *);
581 
582 /**
583  * @ingroup stdio
584  *
585  * @par Description:
586  * The putc() function shell put a byte from a stream.
587  *
588  * @attention
589  * <ul>
590  * <li>None.</li>
591  * </ul>
592  *
593  * @retval #int The putc() function return the character written as an unsigned char
594  *              cast to an int or EOF on end of file or error.
595  *
596  * @par Dependency:
597  * <ul><li>stdio.h</li></ul>
598  * @see putchar | getc
599  */
600 int putc(int, FILE *);
601 
602 /**
603  * @ingroup stdio
604  *
605  * @par Description:
606  * The putchar() function shell put a byte from a stdin stream.
607  *
608  * @attention
609  * <ul>
610  * <li>None.</li>
611  * </ul>
612  *
613  * @retval #int The putchar() function return the character written as an unsigned char
614  *              cast to an int or EOF on end of file or error.
615  *
616  * @par Dependency:
617  * <ul><li>stdio.h</li></ul>
618  * @see getchar | putc
619  */
620 int putchar(int);
621 
622 /**
623  * @ingroup stdio
624  *
625  * @par Description:
626  * The fgets() function shall read bytes from stream into the array pointed to by s until n-1 bytes are read, or a <
627  * newline> is read and transferred to s, or an end-of-file condition is encountered.
628  *
629  * @attention
630  * <ul>
631  * <li>None.</li>
632  * </ul>
633  *
634  * @retval #char* Upon successful completion, fgets() shall return s. If the stream is at end-of-file,
635  * the end-of-file indicator for the stream shall be set and fgets() shall return a null pointer.
636  * If a read error occurs, the error indicator for the stream shall be set,
637  * fgets() shall return a null pointer,  and shall set errno to indicate the error.
638  *
639  * @par Errors
640  * <ul>
641  * <li><b>EINVAL</b>: Invalid argument.</li>
642  * </ul>
643  *
644  * @par Dependency:
645  * <ul><li>stdio.h</li></ul>
646  * @see fgetc | fopen | fread | fscanf | getc
647  */
648 char *fgets(char *__restrict, int, FILE *__restrict);
649 #if __STDC_VERSION__ < 201112L
650 /**
651  * @ingroup stdio
652  *
653  * @par Description:
654  * The gets() function shall get a string from a stdin stream.
655  *
656  * @attention
657  * <ul>
658  * <li>gets is unsafe, use fgets instead.</li>
659  * </ul>
660  *
661  * @retval #char* Upon successful completion, gets() shall return s; otherwise, it shall return NULL;
662  *
663  * @par Dependency:
664  * <ul><li>stdio.h</li></ul>
665  * @see printf | dprintf | fprintf
666  */
667 char *gets(char *);
668 #endif
669 
670 /**
671  * @ingroup stdio
672  *
673  * @par Description:
674  * The fputs() function shall  writes the string s to stream.
675  *
676  * @attention
677  * <ul>
678  * <li>None.</li>
679  * </ul>
680  *
681  * @retval #int The fputs() shall return the 0, if it completes successfully;\n
682  *              Otherwise, it shall return EOF.
683  *
684  * @par Dependency:
685  * <ul><li>stdio.h</li></ul>
686  * @see fopen | fputc | puts
687  */
688 int fputs(const char *__restrict, FILE *__restrict);
689 
690 /**
691  * @ingroup stdio
692  *
693  * @par Description:
694  * The puts() function shell put a string on standard output.
695  *
696  * @attention
697  * <ul>
698  * <li>None.</li>
699  * </ul>
700  *
701  * @retval #int Upon successful completion, puts() shall return 0. Otherwise, it shall return EOF, shall set an
702  *              error indicator for the stream, and errno shall be set to indicate the error.
703  *
704  * @par Errors
705  * <ul>
706  * <li><b>EBADF</b>: Bad file number.</li>
707  * </ul>
708  *
709  * @par Dependency:
710  * <ul><li>stdio.h</li></ul>
711  * @see fputs | putc
712  */
713 int puts(const char *);
714 
715 /**
716  * @ingroup stdio
717  *
718  * @par Description:
719  * The printf() function shall place output on the stdout stream.
720  *
721  * @attention
722  * <ul>
723  * <li>None.</li>
724  * </ul>
725  *
726  * @retval #int The printf() function shall return the number of characters printed.
727  *
728  * @par Dependency:
729  * <ul><li>stdio.h</li></ul>
730  * @see snprintf | dprintf | fprintf
731  */
732 int printf(const char *__restrict, ...);
733 
734 /**
735  * @ingroup stdio
736  *
737  * @par Description:
738  * The fprintf() function shall place output on the named output stream.
739  *
740  * @attention
741  * <ul>
742  * <li>None.</li>
743  * </ul>
744  *
745  * @retval #int The fprintf() functions shall return the number of bytes transmitted.
746  * @par Dependency:
747  * <ul><li>stdio.h</li></ul>
748  * @see fputc | fscanf
749  */
750 int fprintf(FILE *__restrict, const char *__restrict, ...);
751 
752 /**
753  * @ingroup stdio
754  *
755  * @par Description:
756  * The sprintf() function shall write to the string according to the format.
757  *
758  * @attention
759  * <ul>
760  * <li>None.</li>
761  * </ul>
762  *
763  * @retval #int The sprintf() function shall return the number of characters printed.
764  *
765  * @par Dependency:
766  * <ul><li>stdio.h</li></ul>
767  * @see printf | dprintf | fprintf
768  */
769 int sprintf(char *__restrict, const char *__restrict, ...);
770 
771 /**
772  * @ingroup stdio
773  *
774  * @par Description:
775  * The snprintf() function shall write at most size bytes to the string.
776  *
777  * @attention
778  * <ul>
779  * <li>None.</li>
780  * </ul>
781  *
782  * @retval #int The snprintf() function shall return the number of characters printed.
783  *
784  * @par Dependency:
785  * <ul><li>stdio.h</li></ul>
786  * @see printf | dprintf | fprintf
787  */
788 int snprintf(char *__restrict, size_t, const char *__restrict, ...);
789 
790 /**
791  * @ingroup stdio
792  *
793  * @par Description:
794  * The vprintf() function shall format output of a stdarg argument list to the stdout.
795  *
796  * @attention
797  * <ul>
798  * <li>None.</li>
799  * </ul>
800  *
801  * @retval #int The vprintf() function shall return the number of characters printed.
802  *
803  * @par Dependency:
804  * <ul><li>stdio.h</li></ul>
805  * @see printf | dprintf | fprintf
806  */
807 int vprintf(const char *__restrict, __isoc_va_list);
808 
809 /**
810  * @ingroup stdio
811  *
812  * @par Description:
813  * The vfprintf() function shall format output of a stdarg argument list to the named file descriptor.
814  *
815  * @attention
816  * <ul>
817  * <li>None.</li>
818  * </ul>
819  *
820  * @retval #int The vfprintf() function shall return the number of characters printed.
821  *
822  * @par Dependency:
823  * <ul><li>stdio.h</li></ul>
824  * @see printf | dprintf | fprintf
825  */
826 int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list);
827 
828 /**
829  * @ingroup stdio
830  *
831  * @par Description:
832  * The vsprintf() function shall format output of a stdarg argument list to the string.
833  *
834  * @attention
835  * <ul>
836  * <li>None.</li>
837  * </ul>
838  *
839  * @retval #int The vsprintf() function shall return the number of characters printed.
840  *
841  * @par Dependency:
842  * <ul><li>stdio.h</li></ul>
843  * @see printf | dprintf | fprintf
844  */
845 int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list);
846 
847 /**
848  * @ingroup stdio
849  *
850  * @par Description:
851  * The vsnprintf() function shall format output of a stdarg argument list to the string at most size bytes.
852  *
853  * @attention
854  * <ul>
855  * <li>None.</li>
856  * </ul>
857  *
858  * @retval #int The vsnprintf() function shall return the number of characters printed.
859  *
860  * @par Dependency:
861  * <ul><li>stdio.h</li></ul>
862  * @see printf | dprintf | fprintf
863  */
864 int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list);
865 
866 /**
867  * @ingroup stdio
868  *
869  * @par Description:
870  *  The scanf() function scans shall read from the stdin stream
871  *
872  * @attention
873  * <ul>
874  * <li>None.</li>
875  * </ul>
876  *
877  * @retval #int On success, these functions return the number of input items successfully matched and assigned;\n
878  *              this can be fewer than provided for, or even zero, in the event of an early matching failure.\n
879  *              The  value  EOF is returned if the end of input is reached
880  *              before either the first successful conversion or a matching failure  occurs.
881  *
882  * @par Dependency:
883  * <ul><li>stdio.h</li></ul>
884  * @see fprintf | getc | scanf
885  */
886 int scanf(const char *__restrict, ...);
887 
888 /**
889  * @ingroup stdio
890  *
891  * @par Description:
892  *  The fscanf() function scans shall read from the named input stream.
893  *
894  * @attention
895  * <ul>
896  * <li>None.</li>
897  * </ul>
898  *
899  * @retval #int On success, these functions return the number of input items successfully matched and assigned;\n
900  *              this can be fewer than provided for, or even zero, in the event of an early matching failure.\n
901  *              The  value  EOF is returned if the end of input is reached
902  *              before either the first successful conversion or a matching failure  occurs.
903  *
904  * @par Dependency:
905  * <ul><li>stdio.h</li></ul>
906  * @see fprintf | getc | scanf
907  */
908 int fscanf(FILE *__restrict, const char *__restrict, ...);
909 
910 /**
911  * @ingroup stdio
912  *
913  * @par Description:
914  *  The scanf() function scans shall read from the named string.
915  *
916  * @attention
917  * <ul>
918  * <li>None.</li>
919  * </ul>
920  *
921  * @retval #int On success, these functions return the number of input items successfully matched and assigned;\n
922  *              this can be fewer than provided for, or even zero, in the event of an early matching failure.\n
923  *              The  value  EOF is returned if the end of input is reached
924  *              before either the first successful conversion or a matching failure  occurs.
925  *
926  * @par Dependency:
927  * <ul><li>stdio.h</li></ul>
928  * @see fprintf | getc | scanf
929  */
930 int sscanf(const char *__restrict, const char *__restrict, ...);
931 
932 /**
933  * @ingroup stdio
934  *
935  * @par Description:
936  *  The vscanf() function scans a variable argument list from the standard input.
937  *
938  * @attention
939  * <ul>
940  * <li>None.</li>
941  * </ul>
942  *
943  * @retval #int On success, the vscanf() function return the number of input items successfully matched and assigned;\n
944  * this can be fewer than provided for, or even zero, in the event of an early matching failure.
945  *
946  * @par Dependency:
947  * <ul><li>stdio.h</li></ul>
948  * @see vfscanf | getc | fprintf
949  */
950 int vscanf(const char *__restrict, __isoc_va_list);
951 
952 /**
953  * @ingroup stdio
954  *
955  * @par Description:
956  *  The vfscanf() function scans a variable argument list from the named input stream.
957  *
958  * @attention
959  * <ul>
960  * <li>None.</li>
961  * </ul>
962  *
963  * @retval #int On success, these functions return the number of input items successfully matched and assigned;\n
964  *              this can be fewer than provided for, or even zero, in the event of an early matching failure.\n
965  *              The  value  EOF is returned if the end of input is reached
966  *              before either the first successful conversion or a matching failure  occurs.
967  *
968  * @par Dependency:
969  * <ul><li>stdio.h</li></ul>
970  * @see vscanf | getc | fprintf
971  */
972 int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list);
973 int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list);
974 
975 /**
976  * @ingroup stdio
977  *
978  * @par Description:
979  * The perror() function shell write error messages to standard error.
980  *
981  * @attention
982  * <ul>
983  * <li>None.</li>
984  * </ul>
985  *
986  * @retval #void None.
987  *
988  * @par Dependency:
989  * <ul><li>stdio.h</li></ul>
990  * @see fprintf | fputc
991  */
992 void perror(const char *);
993 
994 /**
995  * @ingroup stdio
996  *
997  * @par Description:
998  * The setvbuf() function may be used after the stream pointed to by stream
999  * is associated with an open file but before any other operation
1000  * (other than an unsuccessful call to setvbuf()) is performed on the stream.
1001  *
1002  * @attention
1003  * <ul>
1004  * <li>when buf is NULL, the default requested memory size is BUFSIZ.</li>
1005  * </ul>
1006  *
1007  * @retval #int Upon successful completion, setvbuf() shall return 0.\n
1008  *              Otherwise, it shall return EOF if an invalid value
1009  *              is given for type or if the request cannot be honored,
1010  *              and may set errno to indicate the error.
1011  *
1012  * @par Errors
1013  * <ul>
1014  * <li><b>EINVAL</b>: Invalid argument.</li>
1015  * <li><b>ENOBUFS</b>: No buffer space available.</li>
1016  * </ul>
1017  *
1018  * @par Dependency:
1019  * <ul><li>stdio.h</li></ul>
1020  * @see setbuf | fopen
1021  */
1022 int setvbuf(FILE *__restrict, char *__restrict, int, size_t);
1023 
1024 /**
1025  * @ingroup stdio
1026  *
1027  * @par Description:
1028  * The setvbuf() function assign buffering to a stream, and is exactly equivalent to the call\n
1029  *           setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
1030  *
1031  * @attention
1032  * <ul>
1033  * <li>None.</li>
1034  * </ul>
1035  *
1036  * @retval #void None.
1037  *
1038  * @par Errors
1039  * <ul>
1040  * <li><b>EINVAL</b>: Invalid argument.</li>
1041  * <li><b>ENOBUFS</b>: No buffer space available.</li>
1042  * </ul>
1043  *
1044  * @par Dependency:
1045  * <ul><li>stdio.h</li></ul>
1046  * @see setvbuf | fopen
1047  */
1048 void setbuf(FILE *__restrict, char *__restrict);
1049 
1050 /**
1051  * @ingroup stdio
1052  *
1053  * @par Description:
1054  * The tmpnam() function shall generate a string that is a valid pathname that does not name an existing file.
1055  *
1056  * @attention
1057  * <ul>
1058  * <li>None.</li>
1059  * </ul>
1060  *
1061  * @retval #char* Upon successful completion, tmpnam() shall return a pointer to a string. If no suitable string can be generated, the
1062  *                tmpnam() function shall return a null pointer.
1063  *
1064  * @par Dependency:
1065  * <ul><li>stdio.h</li></ul>
1066  * @see fopen | mkstemp
1067  */
1068 char *tmpnam(char *);
1069 FILE *tmpfile(void);
1070 
1071 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
1072  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
1073  || defined(_BSD_SOURCE)
1074 FILE *fmemopen(void *__restrict, size_t, const char *__restrict);
1075 FILE *open_memstream(char **, size_t *);
1076 
1077 /**
1078  * @ingroup stdio
1079  *
1080  * @par Description:
1081  * The fdopen() function shall associate a stream with a file descriptor.
1082  *
1083  * @attention
1084  * <ul>
1085  * <li>None.</li>
1086  * </ul>
1087  *
1088  * @retval #FILE* The fdopen() function shall return a pointer to a stream, if it completes successfully;\n
1089  *                otherwise, a null pointer shall be returned and errno set to indicate the error.
1090  *
1091  * @par Errors
1092  * <ul>
1093  * <li><b>EMFILE</b>: The file descriptor is greater than SHRT_MAX</li>
1094  * <li><b>EINVAL</b>: The mode argument is not a valid mode.</li>
1095  * </ul>
1096  *
1097  * @par Dependency:
1098  * <ul><li>stdio.h</li></ul>
1099  * @see fclose | fopen | open
1100  */
1101 FILE *fdopen(int, const char *);
1102 FILE *popen(const char *, const char *);
1103 int pclose(FILE *);
1104 
1105 /**
1106  * @ingroup stdio
1107  *
1108  * @par Description:
1109  * The fileno() function shall return the integer file descriptor associated with the stream.
1110  *
1111  * @attention
1112  * <ul>
1113  * <li>None.</li>
1114  * </ul>
1115  *
1116  * @retval #int The fileno() function return the integer value of the file descriptor associated with stream.\n
1117  *              Otherwise, the value -1 shall be returned and errno set to indicate the error.
1118  *
1119  * @par Errors
1120  * <ul>
1121  * <li><b>EBADF</b>: The stream is not associated with a file.</li>
1122  * </ul>
1123  *
1124  * @par Dependency:
1125  * <ul><li>stdio.h</li></ul>
1126  * @see fdopen | fopen
1127  */
1128 int fileno(FILE *);
1129 
1130 /**
1131  * @ingroup stdio
1132  *
1133  * @par Description:
1134  * The fseeko() function shall set the file-position indicator for the stream pointed to by stream.
1135  *
1136  * @attention
1137  * <ul>
1138  * <li>None.</li>
1139  * </ul>
1140  *
1141  * @retval #int The fseeko() function shall return 0, if it completes successfully;\n
1142  *              otherwise, it shall return -1 and set errno to indicate the error.
1143  *
1144  * @par Errors
1145  * <ul>
1146  * <li><b>ESPIPE</b>: Illegal seek.</li>
1147  * <li><b>EINVAL</b>: The whence argument to fseek() was not SEEK_SET, SEEK_END, or SEEK_CUR.</li>
1148  * <li><b>EBADF</b>: The stream specified is not a seekable stream.</li>
1149  * </ul>
1150  *
1151  * @par Dependency:
1152  * <ul><li>stdio.h</li></ul>
1153  * @see fopen | fgetpos | fseek
1154  */
1155 int fseeko(FILE *, off_t, int);
1156 
1157 /**
1158  * @ingroup stdio
1159  *
1160  * @par Description:
1161  * The ftello() function shall obtain the current value of the file-position indicator for the stream pointed to by stream.
1162  *
1163  * @attention
1164  * <ul>
1165  * <li>None.</li>
1166  * </ul>
1167  *
1168  * @retval #off_t The ftello() function shall return the current offset, if it completes successfully;\n
1169  *                otherwise, it shall return -1 and set errno to indicate the error.
1170  *
1171  * @par Errors
1172  * <ul>
1173  * <li><b>ESPIPE</b>: Illegal seek.</li>
1174  * </ul>
1175  *
1176  * @par Dependency:
1177  * <ul><li>stdio.h</li></ul>
1178  * @see fseeko | ftell
1179  */
1180 off_t ftello(FILE *);
1181 /* func realization is used dprintf in printf.c, func declaration conflict hear*/
1182 #ifndef __LITEOS__
1183 int dprintf(int, const char *__restrict, ...);
1184 #else
1185 int dprintf(const char *fmt, ...);
1186 #endif
1187 int vdprintf(int, const char *__restrict, __isoc_va_list);
1188 
1189 /**
1190  * @ingroup stdio
1191  *
1192  * @par Description:
1193  * The flockfile() function shall acquire for a thread ownership of a (FILE *) object.
1194  *
1195  * @attention
1196  * <ul>
1197  * <li>None.</li>
1198  * </ul>
1199  *
1200  * @retval #void None.
1201  *
1202  * @par Dependency:
1203  * <ul><li>stdio.h</li></ul>
1204  * @see ftrylockfile | funlockfile
1205  */
1206 void flockfile(FILE *);
1207 
1208 /**
1209  * @ingroup stdio
1210  *
1211  * @par Description:
1212  * The ftrylockfile() function shall acquire for a thread ownership of a (FILE *) object if the object is available;
1213  *
1214  * @attention
1215  * <ul>
1216  * <li>None.</li>
1217  * </ul>
1218  *
1219  * @retval #int The ftrylockfile() function shall return zero for success and non-zero to indicate that the lock cannot be acquired.
1220  *
1221  * @par Dependency:
1222  * <ul><li>stdio.h</li></ul>
1223  * @see flockfile | funlockfile
1224  */
1225 int ftrylockfile(FILE *);
1226 
1227 /**
1228  * @ingroup stdio
1229  *
1230  * @par Description:
1231  * The funlockfile() function shall relinquish the ownership granted to the thread.
1232  *
1233  * @attention
1234  * <ul>
1235  * <li>None.</li>
1236  * </ul>
1237  *
1238  * @retval #void None.
1239  *
1240  * @par Dependency:
1241  * <ul><li>stdio.h</li></ul>
1242  * @see flockfile | ftrylockfile
1243  */
1244 void funlockfile(FILE *);
1245 
1246 /**
1247  * @ingroup stdio
1248  *
1249  * @par Description:
1250  * The getc_unlocked() function shell get a byte from a stream without the thread-safe.
1251  *
1252  * @attention
1253  * <ul>
1254  * <li>None.</li>
1255  * </ul>
1256  *
1257  * @retval #int The getc_unlocked() function return the character read as an unsigned char cast to an int or EOF on end of file or error.
1258  *
1259  * @par Dependency:
1260  * <ul><li>stdio.h</li></ul>
1261  * @see putc_unlocked | getc
1262  */
1263 int getc_unlocked(FILE *);
1264 
1265 /**
1266  * @ingroup stdio
1267  *
1268  * @par Description:
1269  * The getchar_unlocked() function shell get a byte from a stdin stream without the thread-safe.
1270  *
1271  * @attention
1272  * <ul>
1273  * <li>None.</li>
1274  * </ul>
1275  *
1276  * @retval #int The getchar_unlocked() function return the character read as an unsigned char cast to an int or EOF on end of file or error.
1277  *
1278  * @par Dependency:
1279  * <ul><li>stdio.h</li></ul>
1280  * @see putchar_unlocked | getchar
1281  */
1282 int getchar_unlocked(void);
1283 int putc_unlocked(int, FILE *);
1284 int putchar_unlocked(int);
1285 ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict);
1286 ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict);
1287 int renameat(int, const char *, int, const char *);
1288 char *ctermid(char *);
1289 #define L_ctermid 20
1290 #endif
1291 
1292 
1293 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
1294  || defined(_BSD_SOURCE)
1295 #define P_tmpdir "/tmp"
1296 char *tempnam(const char *, const char *);
1297 #endif
1298 
1299 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
1300 #define L_cuserid 20
1301 char *cuserid(char *);
1302 void setlinebuf(FILE *);
1303 void setbuffer(FILE *, char *, size_t);
1304 int fgetc_unlocked(FILE *);
1305 int fputc_unlocked(int, FILE *);
1306 int fflush_unlocked(FILE *);
1307 size_t fread_unlocked(void *, size_t, size_t, FILE *);
1308 size_t fwrite_unlocked(const void *, size_t, size_t, FILE *);
1309 void clearerr_unlocked(FILE *);
1310 int feof_unlocked(FILE *);
1311 int ferror_unlocked(FILE *);
1312 int fileno_unlocked(FILE *);
1313 int getw(FILE *);
1314 int putw(int, FILE *);
1315 char *fgetln(FILE *, size_t *);
1316 
1317 /**
1318  * @ingroup stdio
1319  *
1320  * @par Description:
1321  * The asprintf() function shell allocate a string large enough to hold the output.
1322  *
1323  * @attention
1324  * <ul>
1325  * <li>None.</li>
1326  * </ul>
1327  *
1328  * @retval #int  The asprintf() function return the number of bytes printed, if it completes successfully;\n
1329  *               otherwise, it shall return -1.
1330  *
1331  * @par Errors
1332  * <ul>
1333  * <li><b>ENOMEM</b>: Insufficient storage space is available.</li>
1334  * </ul>
1335  *
1336  * @par Dependency:
1337  * <ul><li>stdio.h</li></ul>
1338  * @see malloc | free | printf
1339  */
1340 int asprintf(char **, const char *, ...);
1341 
1342 /**
1343  * @ingroup stdio
1344  *
1345  * @par Description:
1346  * The vasprintf() function shell allocate a string large enough to hold the output.
1347  *
1348  * @attention
1349  * <ul>
1350  * <li>None.</li>
1351  * </ul>
1352  *
1353  * @retval #int  The vasprintf() function return the number of bytes printed, if it completes successfully;\n
1354  *               otherwise, it shall return -1.
1355  *
1356  * @par Errors
1357  * <ul>
1358  * <li><b>ENOMEM</b>: Insufficient storage space is available.</li>
1359  * </ul>
1360  *
1361  * @par Dependency:
1362  * <ul><li>stdio.h</li></ul>
1363  * @see malloc | free | printf
1364  */
1365 int vasprintf(char **, const char *, __isoc_va_list);
1366 #endif
1367 
1368 #ifdef _GNU_SOURCE
1369 char *fgets_unlocked(char *, int, FILE *);
1370 int fputs_unlocked(const char *, FILE *);
1371 
1372 typedef ssize_t (cookie_read_function_t)(void *, char *, size_t);
1373 typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t);
1374 typedef int (cookie_seek_function_t)(void *, off_t *, int);
1375 typedef int (cookie_close_function_t)(void *);
1376 
1377 typedef struct _IO_cookie_io_functions_t {
1378 	cookie_read_function_t *read;
1379 	cookie_write_function_t *write;
1380 	cookie_seek_function_t *seek;
1381 	cookie_close_function_t *close;
1382 } cookie_io_functions_t;
1383 
1384 FILE *fopencookie(void *, const char *, cookie_io_functions_t);
1385 #endif
1386 
1387 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
1388 #ifdef __LITEOS__
1389 #define off64_t int64_t
1390 #define fpos64_t fpos_t
1391 FILE *tmpfile64(void);
1392 FILE *fopen64(const char *, const char *);
1393 FILE *freopen64(const char *, const char *, FILE *);
1394 int fseeko64(FILE *, off64_t, int);
1395 off64_t ftello64(FILE *);
1396 int fsetpos64(FILE *, const fpos64_t *);
1397 int fsetpos64(FILE *, const fpos64_t *);
1398 #else
1399 #define tmpfile64 tmpfile
1400 #define fopen64 fopen
1401 #define freopen64 freopen
1402 #define fseeko64 fseeko
1403 #define ftello64 ftello
1404 #define fgetpos64 fgetpos
1405 #define fsetpos64 fsetpos
1406 #define fpos64_t fpos_t
1407 #define off64_t off_t
1408 #endif
1409 #endif
1410 
1411 #ifdef __cplusplus
1412 }
1413 #endif
1414 
1415 #endif
1416