1 #ifndef _STDIO_H
2 #define _STDIO_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include <features.h>
9 
10 #define __NEED_FILE
11 #define __NEED___isoc_va_list
12 #define __NEED_size_t
13 
14 #if __STDC_VERSION__ < 201112L
15 #define __NEED_struct__IO_FILE
16 #endif
17 
18 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
19  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
20  || defined(_BSD_SOURCE)
21 #define __NEED_ssize_t
22 #define __NEED_off_t
23 #define __NEED_va_list
24 #endif
25 
26 #include <bits/alltypes.h>
27 
28 #ifdef __cplusplus
29 #define NULL __null
30 #else
31 #define NULL ((void*)0)
32 #endif
33 
34 #undef EOF
35 #define EOF (-1)
36 
37 #undef SEEK_SET
38 #undef SEEK_CUR
39 #undef SEEK_END
40 #define SEEK_SET 0
41 #define SEEK_CUR 1
42 #define SEEK_END 2
43 
44 #define _IOFBF 0
45 #define _IOLBF 1
46 #define _IONBF 2
47 
48 /* TRUSTY - reduce the buffer size to save memory. */
49 #define BUFSIZ 120
50 #define FILENAME_MAX 4096
51 #define FOPEN_MAX 1000
52 #define TMP_MAX 10000
53 #define L_tmpnam 20
54 
55 typedef union _G_fpos64_t {
56 	char __opaque[16];
57 	long long __lldata;
58 	double __align;
59 } fpos_t;
60 
61 extern FILE *const stdin;
62 extern FILE *const stdout;
63 extern FILE *const stderr;
64 
65 #define stdin  (stdin)
66 #define stdout (stdout)
67 #define stderr (stderr)
68 
69 FILE *fopen(const char *__restrict, const char *__restrict);
70 FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict);
71 int fclose(FILE *);
72 
73 int remove(const char *);
74 int rename(const char *, const char *);
75 
76 int feof(FILE *);
77 int ferror(FILE *);
78 int fflush(FILE *);
79 void clearerr(FILE *);
80 
81 int fseek(FILE *, long, int);
82 long ftell(FILE *);
83 void rewind(FILE *);
84 
85 int fgetpos(FILE *__restrict, fpos_t *__restrict);
86 int fsetpos(FILE *, const fpos_t *);
87 
88 size_t fread(void *__restrict, size_t, size_t, FILE *__restrict);
89 size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict);
90 
91 int fgetc(FILE *);
92 int getc(FILE *);
93 int getchar(void);
94 int ungetc(int, FILE *);
95 
96 int fputc(int, FILE *);
97 int putc(int, FILE *);
98 int putchar(int);
99 
100 char *fgets(char *__restrict, int, FILE *__restrict);
101 #if __STDC_VERSION__ < 201112L
102 char *gets(char *);
103 #endif
104 
105 int fputs(const char *__restrict, FILE *__restrict);
106 int puts(const char *);
107 
108 int printf(const char *__restrict, ...);
109 int fprintf(FILE *__restrict, const char *__restrict, ...);
110 int sprintf(char *__restrict, const char *__restrict, ...);
111 int snprintf(char *__restrict, size_t, const char *__restrict, ...);
112 int snprintf_filtered(char *__restrict, size_t, const char *__restrict, ...);
113 
114 int vprintf(const char *__restrict, __isoc_va_list);
115 int vfprintf_worker(FILE *__restrict, const char *__restrict, __isoc_va_list, int);
vfprintf(FILE * __restrict f,const char * __restrict fmt,va_list ap)116 static inline int vfprintf(FILE *__restrict f, const char *__restrict fmt, va_list ap)
117 {
118 	return vfprintf_worker(f, fmt, ap, 1);
119 }
vfprintf_unfiltered(FILE * __restrict f,const char * __restrict fmt,va_list ap)120 static inline int vfprintf_unfiltered(FILE *__restrict f, const char *__restrict fmt, va_list ap)
121 {
122 	return vfprintf_worker(f, fmt, ap, 0);
123 }
124 int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list);
125 int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list);
126 int vsnprintf_filtered(char *__restrict, size_t, const char *__restrict, __isoc_va_list);
127 
128 int scanf(const char *__restrict, ...);
129 int fscanf(FILE *__restrict, const char *__restrict, ...);
130 int sscanf(const char *__restrict, const char *__restrict, ...);
131 int vscanf(const char *__restrict, __isoc_va_list);
132 int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list);
133 int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list);
134 
135 void perror(const char *);
136 
137 int setvbuf(FILE *__restrict, char *__restrict, int, size_t);
138 void setbuf(FILE *__restrict, char *__restrict);
139 
140 char *tmpnam(char *);
141 FILE *tmpfile(void);
142 
143 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
144  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
145  || defined(_BSD_SOURCE)
146 FILE *fmemopen(void *__restrict, size_t, const char *__restrict);
147 FILE *open_memstream(char **, size_t *);
148 FILE *fdopen(int, const char *);
149 FILE *popen(const char *, const char *);
150 int pclose(FILE *);
151 int fileno(FILE *);
152 int fseeko(FILE *, off_t, int);
153 off_t ftello(FILE *);
154 int dprintf(int, const char *__restrict, ...);
155 int vdprintf(int, const char *__restrict, __isoc_va_list);
156 void flockfile(FILE *);
157 int ftrylockfile(FILE *);
158 void funlockfile(FILE *);
159 int getc_unlocked(FILE *);
160 int getchar_unlocked(void);
161 int putc_unlocked(int, FILE *);
162 int putchar_unlocked(int);
163 ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict);
164 ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict);
165 int renameat(int, const char *, int, const char *);
166 char *ctermid(char *);
167 #define L_ctermid 20
168 #endif
169 
170 
171 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
172  || defined(_BSD_SOURCE)
173 #define P_tmpdir "/tmp"
174 char *tempnam(const char *, const char *);
175 #endif
176 
177 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
178 #define L_cuserid 20
179 char *cuserid(char *);
180 void setlinebuf(FILE *);
181 void setbuffer(FILE *, char *, size_t);
182 int fgetc_unlocked(FILE *);
183 int fputc_unlocked(int, FILE *);
184 int fflush_unlocked(FILE *);
185 size_t fread_unlocked(void *, size_t, size_t, FILE *);
186 size_t fwrite_unlocked(const void *, size_t, size_t, FILE *);
187 void clearerr_unlocked(FILE *);
188 int feof_unlocked(FILE *);
189 int ferror_unlocked(FILE *);
190 int fileno_unlocked(FILE *);
191 int getw(FILE *);
192 int putw(int, FILE *);
193 char *fgetln(FILE *, size_t *);
194 int asprintf(char **, const char *, ...);
195 int vasprintf(char **, const char *, __isoc_va_list);
196 #endif
197 
198 #ifdef _GNU_SOURCE
199 char *fgets_unlocked(char *, int, FILE *);
200 int fputs_unlocked(const char *, FILE *);
201 
202 typedef ssize_t (cookie_read_function_t)(void *, char *, size_t);
203 typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t);
204 typedef int (cookie_seek_function_t)(void *, off_t *, int);
205 typedef int (cookie_close_function_t)(void *);
206 
207 typedef struct _IO_cookie_io_functions_t {
208 	cookie_read_function_t *read;
209 	cookie_write_function_t *write;
210 	cookie_seek_function_t *seek;
211 	cookie_close_function_t *close;
212 } cookie_io_functions_t;
213 
214 FILE *fopencookie(void *, const char *, cookie_io_functions_t);
215 #endif
216 
217 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
218 #define tmpfile64 tmpfile
219 #define fopen64 fopen
220 #define freopen64 freopen
221 #define fseeko64 fseeko
222 #define ftello64 ftello
223 #define fgetpos64 fgetpos
224 #define fsetpos64 fsetpos
225 #define fpos64_t fpos_t
226 #define off64_t off_t
227 #endif
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #endif
234