blob: d1ed01f03f8f22b888ca751ddb092339ca6e2507 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#ifndef _STDIO_H
2#define _STDIO_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
Rich Felkerc1a96582012-09-07 23:13:55 -04008#include <features.h>
Rich Felker400c5e52012-09-06 22:44:55 -04009
Rich Felker0b44a032011-02-12 00:22:29 -050010#define __NEED_FILE
Rich Felkera3e2f3c2013-06-25 22:26:20 -040011#define __NEED___isoc_va_list
Rich Felker0b44a032011-02-12 00:22:29 -050012#define __NEED_size_t
Rich Felker80695b12011-02-14 05:10:10 -050013
Rich Felkerf368d9f2019-03-12 15:24:00 -040014#if __STDC_VERSION__ < 201112L
15#define __NEED_struct__IO_FILE
16#endif
17
Rich Felker80695b12011-02-14 05:10:10 -050018#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
Rich Felker419ae6d2012-05-22 21:52:08 -040019 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
20 || defined(_BSD_SOURCE)
Rich Felker0b44a032011-02-12 00:22:29 -050021#define __NEED_ssize_t
22#define __NEED_off_t
Rich Felkera3e2f3c2013-06-25 22:26:20 -040023#define __NEED_va_list
Rich Felker80695b12011-02-14 05:10:10 -050024#endif
Rich Felker0b44a032011-02-12 00:22:29 -050025
26#include <bits/alltypes.h>
27
Ismael Luceno98e688a2021-08-15 17:51:57 +020028#if __cplusplus >= 201103L
29#define NULL nullptr
30#elif defined(__cplusplus)
Rich Felker41d7c772013-01-18 20:35:26 -050031#define NULL 0L
Rich Felkerc8a9c222013-11-24 21:42:55 -050032#else
33#define NULL ((void*)0)
34#endif
Rich Felker0b44a032011-02-12 00:22:29 -050035
36#undef EOF
37#define EOF (-1)
38
39#undef SEEK_SET
40#undef SEEK_CUR
41#undef SEEK_END
42#define SEEK_SET 0
43#define SEEK_CUR 1
44#define SEEK_END 2
45
46#define _IOFBF 0
47#define _IOLBF 1
48#define _IONBF 2
49
Rich Felker571312d2011-02-15 19:47:22 -050050#define BUFSIZ 1024
Rich Felkerb823ef22013-07-18 14:15:48 -040051#define FILENAME_MAX 4096
Rich Felker571312d2011-02-15 19:47:22 -050052#define FOPEN_MAX 1000
53#define TMP_MAX 10000
54#define L_tmpnam 20
Rich Felker0b44a032011-02-12 00:22:29 -050055
Rich Felker9448b052013-07-22 11:22:36 -040056typedef union _G_fpos64_t {
Rich Felker0b44a032011-02-12 00:22:29 -050057 char __opaque[16];
Rich Felker2fae10f2018-02-24 16:45:33 -050058 long long __lldata;
Rich Felker0b44a032011-02-12 00:22:29 -050059 double __align;
60} fpos_t;
61
62extern FILE *const stdin;
63extern FILE *const stdout;
64extern FILE *const stderr;
65
66#define stdin (stdin)
67#define stdout (stdout)
68#define stderr (stderr)
69
Rich Felker400c5e52012-09-06 22:44:55 -040070FILE *fopen(const char *__restrict, const char *__restrict);
71FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -050072int fclose(FILE *);
73
Rich Felker0b44a032011-02-12 00:22:29 -050074int remove(const char *);
75int rename(const char *, const char *);
76
Rich Felker0b44a032011-02-12 00:22:29 -050077int feof(FILE *);
78int ferror(FILE *);
79int fflush(FILE *);
80void clearerr(FILE *);
81
82int fseek(FILE *, long, int);
Rich Felker0b44a032011-02-12 00:22:29 -050083long ftell(FILE *);
Rich Felker0b44a032011-02-12 00:22:29 -050084void rewind(FILE *);
85
Rich Felker400c5e52012-09-06 22:44:55 -040086int fgetpos(FILE *__restrict, fpos_t *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -050087int fsetpos(FILE *, const fpos_t *);
88
Rich Felker400c5e52012-09-06 22:44:55 -040089size_t fread(void *__restrict, size_t, size_t, FILE *__restrict);
90size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -050091
92int fgetc(FILE *);
93int getc(FILE *);
94int getchar(void);
95int ungetc(int, FILE *);
96
97int fputc(int, FILE *);
98int putc(int, FILE *);
99int putchar(int);
100
Rich Felker400c5e52012-09-06 22:44:55 -0400101char *fgets(char *__restrict, int, FILE *__restrict);
Rich Felker9bff7c12012-08-25 23:15:13 -0400102#if __STDC_VERSION__ < 201112L
Rich Felker0b44a032011-02-12 00:22:29 -0500103char *gets(char *);
Rich Felker9bff7c12012-08-25 23:15:13 -0400104#endif
Rich Felker0b44a032011-02-12 00:22:29 -0500105
Rich Felker400c5e52012-09-06 22:44:55 -0400106int fputs(const char *__restrict, FILE *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500107int puts(const char *);
108
Rich Felker400c5e52012-09-06 22:44:55 -0400109int printf(const char *__restrict, ...);
110int fprintf(FILE *__restrict, const char *__restrict, ...);
111int sprintf(char *__restrict, const char *__restrict, ...);
112int snprintf(char *__restrict, size_t, const char *__restrict, ...);
Rich Felker0b44a032011-02-12 00:22:29 -0500113
Rich Felkera3e2f3c2013-06-25 22:26:20 -0400114int vprintf(const char *__restrict, __isoc_va_list);
115int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list);
116int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list);
117int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list);
Rich Felker0b44a032011-02-12 00:22:29 -0500118
Rich Felker400c5e52012-09-06 22:44:55 -0400119int scanf(const char *__restrict, ...);
120int fscanf(FILE *__restrict, const char *__restrict, ...);
121int sscanf(const char *__restrict, const char *__restrict, ...);
Rich Felkera3e2f3c2013-06-25 22:26:20 -0400122int vscanf(const char *__restrict, __isoc_va_list);
123int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list);
124int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list);
Rich Felker0b44a032011-02-12 00:22:29 -0500125
126void perror(const char *);
127
Rich Felker400c5e52012-09-06 22:44:55 -0400128int setvbuf(FILE *__restrict, char *__restrict, int, size_t);
129void setbuf(FILE *__restrict, char *__restrict);
Rich Felker80695b12011-02-14 05:10:10 -0500130
131char *tmpnam(char *);
132FILE *tmpfile(void);
133
134#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
Rich Felker419ae6d2012-05-22 21:52:08 -0400135 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
136 || defined(_BSD_SOURCE)
Rich Felker400c5e52012-09-06 22:44:55 -0400137FILE *fmemopen(void *__restrict, size_t, const char *__restrict);
Rich Felkerb158b322011-09-03 00:45:21 -0400138FILE *open_memstream(char **, size_t *);
Rich Felker80695b12011-02-14 05:10:10 -0500139FILE *fdopen(int, const char *);
140FILE *popen(const char *, const char *);
141int pclose(FILE *);
142int fileno(FILE *);
143int fseeko(FILE *, off_t, int);
144off_t ftello(FILE *);
Rich Felker400c5e52012-09-06 22:44:55 -0400145int dprintf(int, const char *__restrict, ...);
Rich Felkera3e2f3c2013-06-25 22:26:20 -0400146int vdprintf(int, const char *__restrict, __isoc_va_list);
Rich Felker0b44a032011-02-12 00:22:29 -0500147void flockfile(FILE *);
148int ftrylockfile(FILE *);
149void funlockfile(FILE *);
150int getc_unlocked(FILE *);
151int getchar_unlocked(void);
152int putc_unlocked(int, FILE *);
153int putchar_unlocked(int);
Rich Felker400c5e52012-09-06 22:44:55 -0400154ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict);
155ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500156int renameat(int, const char *, int, const char *);
Rich Felker80695b12011-02-14 05:10:10 -0500157char *ctermid(char *);
Rich Felker571312d2011-02-15 19:47:22 -0500158#define L_ctermid 20
Rich Felker80695b12011-02-14 05:10:10 -0500159#endif
160
161
Rich Felker419ae6d2012-05-22 21:52:08 -0400162#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
163 || defined(_BSD_SOURCE)
Rich Felker571312d2011-02-15 19:47:22 -0500164#define P_tmpdir "/tmp"
Rich Felker80695b12011-02-14 05:10:10 -0500165char *tempnam(const char *, const char *);
166#endif
167
Rich Felker419ae6d2012-05-22 21:52:08 -0400168#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
Rich Felker571312d2011-02-15 19:47:22 -0500169#define L_cuserid 20
170char *cuserid(char *);
Rich Felkere7218002011-04-05 12:25:31 -0400171void setlinebuf(FILE *);
172void setbuffer(FILE *, char *, size_t);
Rich Felkerce17ea62011-09-11 22:50:02 -0400173int fgetc_unlocked(FILE *);
174int fputc_unlocked(int, FILE *);
Rich Felkerb63cab72012-05-28 22:53:24 -0400175int fflush_unlocked(FILE *);
176size_t fread_unlocked(void *, size_t, size_t, FILE *);
177size_t fwrite_unlocked(const void *, size_t, size_t, FILE *);
178void clearerr_unlocked(FILE *);
179int feof_unlocked(FILE *);
180int ferror_unlocked(FILE *);
181int fileno_unlocked(FILE *);
Rich Felker25b88f02012-07-04 12:18:04 -0400182int getw(FILE *);
183int putw(int, FILE *);
Rich Felker61718272012-08-11 18:10:38 -0400184char *fgetln(FILE *, size_t *);
Rich Felkerd18a4102012-12-28 15:39:33 -0500185int asprintf(char **, const char *, ...);
Rich Felkera3e2f3c2013-06-25 22:26:20 -0400186int vasprintf(char **, const char *, __isoc_va_list);
Rich Felker61718272012-08-11 18:10:38 -0400187#endif
188
Rich Felkerb63cab72012-05-28 22:53:24 -0400189#ifdef _GNU_SOURCE
Rich Felkerce17ea62011-09-11 22:50:02 -0400190char *fgets_unlocked(char *, int, FILE *);
191int fputs_unlocked(const char *, FILE *);
William Pitcock06184332017-12-05 16:04:43 -0500192
193typedef ssize_t (cookie_read_function_t)(void *, char *, size_t);
194typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t);
195typedef int (cookie_seek_function_t)(void *, off_t *, int);
196typedef int (cookie_close_function_t)(void *);
197
Rich Felker2488d312017-12-06 13:14:22 -0500198typedef struct _IO_cookie_io_functions_t {
William Pitcock06184332017-12-05 16:04:43 -0500199 cookie_read_function_t *read;
200 cookie_write_function_t *write;
201 cookie_seek_function_t *seek;
202 cookie_close_function_t *close;
203} cookie_io_functions_t;
204
205FILE *fopencookie(void *, const char *, cookie_io_functions_t);
Rich Felker80695b12011-02-14 05:10:10 -0500206#endif
Rich Felker0b44a032011-02-12 00:22:29 -0500207
Rich Felker3b94dab2012-06-04 08:03:56 -0400208#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
Rich Felker2dd8d5e2012-05-04 00:13:23 -0400209#define tmpfile64 tmpfile
210#define fopen64 fopen
211#define freopen64 freopen
212#define fseeko64 fseeko
213#define ftello64 ftello
214#define fgetpos64 fgetpos
215#define fsetpos64 fsetpos
216#define fpos64_t fpos_t
217#define off64_t off_t
218#endif
219
Rich Felker0b44a032011-02-12 00:22:29 -0500220#ifdef __cplusplus
221}
222#endif
223
224#endif