]> git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/include/stdio.h
Add comments explaining changes to upstream source files.
[wasi-libc.git] / libc-top-half / musl / include / stdio.h
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 defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
15 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
16 || defined(_BSD_SOURCE)
17 #define __NEED_ssize_t
18 #define __NEED_off_t
19 #define __NEED_va_list
20 #endif
21
22 #include <bits/alltypes.h>
23
24 #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
25 #ifdef __cplusplus
26 #define NULL 0L
27 #else
28 #define NULL ((void*)0)
29 #endif
30 #else
31 #define __need_NULL
32 #include <stddef.h>
33 #endif
34
35 #undef EOF
36 #define EOF (-1)
37
38 #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
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 #else
46 #include <__header_unistd.h>
47 #endif
48
49 #define _IOFBF 0
50 #define _IOLBF 1
51 #define _IONBF 2
52
53 #define BUFSIZ 1024
54 #define FILENAME_MAX 4096
55 #define FOPEN_MAX 1000
56 #ifdef __wasilibc_unmodified_upstream /* WASI has no tmpnam */
57 #define TMP_MAX 10000
58 #define L_tmpnam 20
59 #endif
60
61 typedef union _G_fpos64_t {
62 char __opaque[16];
63 long long __lldata;
64 double __align;
65 } fpos_t;
66
67 extern FILE *const stdin;
68 extern FILE *const stdout;
69 extern FILE *const stderr;
70
71 #define stdin (stdin)
72 #define stdout (stdout)
73 #define stderr (stderr)
74
75 FILE *fopen(const char *__restrict, const char *__restrict);
76 FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict);
77 int fclose(FILE *);
78
79 int remove(const char *);
80 int rename(const char *, const char *);
81
82 int feof(FILE *);
83 int ferror(FILE *);
84 int fflush(FILE *);
85 void clearerr(FILE *);
86
87 int fseek(FILE *, long, int);
88 long ftell(FILE *);
89 void rewind(FILE *);
90
91 int fgetpos(FILE *__restrict, fpos_t *__restrict);
92 int fsetpos(FILE *, const fpos_t *);
93
94 size_t fread(void *__restrict, size_t, size_t, FILE *__restrict);
95 size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict);
96
97 int fgetc(FILE *);
98 int getc(FILE *);
99 int getchar(void);
100 int ungetc(int, FILE *);
101
102 int fputc(int, FILE *);
103 int putc(int, FILE *);
104 int putchar(int);
105
106 char *fgets(char *__restrict, int, FILE *__restrict);
107 #if __STDC_VERSION__ < 201112L
108 #ifdef __wasilibc_unmodified_upstream /* gets is obsolete */
109 char *gets(char *);
110 #else
111 char *gets(char *) __attribute__((__deprecated__("gets is not defined on WASI")));
112 #endif
113 #endif
114
115 int fputs(const char *__restrict, FILE *__restrict);
116 int puts(const char *);
117
118 int printf(const char *__restrict, ...);
119 int fprintf(FILE *__restrict, const char *__restrict, ...);
120 int sprintf(char *__restrict, const char *__restrict, ...);
121 int snprintf(char *__restrict, size_t, const char *__restrict, ...);
122
123 int vprintf(const char *__restrict, __isoc_va_list);
124 int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list);
125 int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list);
126 int vsnprintf(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 #ifdef __wasilibc_unmodified_upstream /* WASI has no tmpnam or tmpfile */
141 char *tmpnam(char *);
142 FILE *tmpfile(void);
143 #else
144 char *tmpnam(char *) __attribute__((__deprecated__("tmpnam is not defined on WASI")));
145 FILE *tmpfile(void) __attribute__((__deprecated__("tmpfile is not defined on WASI")));
146 #endif
147
148 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
149 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
150 || defined(_BSD_SOURCE)
151 FILE *fmemopen(void *__restrict, size_t, const char *__restrict);
152 FILE *open_memstream(char **, size_t *);
153 FILE *fdopen(int, const char *);
154 FILE *popen(const char *, const char *);
155 int pclose(FILE *);
156 int fileno(FILE *);
157 int fseeko(FILE *, off_t, int);
158 off_t ftello(FILE *);
159 int dprintf(int, const char *__restrict, ...);
160 int vdprintf(int, const char *__restrict, __isoc_va_list);
161 void flockfile(FILE *);
162 int ftrylockfile(FILE *);
163 void funlockfile(FILE *);
164 int getc_unlocked(FILE *);
165 int getchar_unlocked(void);
166 int putc_unlocked(int, FILE *);
167 int putchar_unlocked(int);
168 ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict);
169 ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict);
170 int renameat(int, const char *, int, const char *);
171 char *ctermid(char *);
172 #define L_ctermid 20
173 #endif
174
175
176 #ifdef __wasilibc_unmodified_upstream /* WASI has no tempnam */
177 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
178 || defined(_BSD_SOURCE)
179 #define P_tmpdir "/tmp"
180 char *tempnam(const char *, const char *);
181 #endif
182 #endif
183
184 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
185 #define L_cuserid 20
186 char *cuserid(char *);
187 void setlinebuf(FILE *);
188 void setbuffer(FILE *, char *, size_t);
189 int fgetc_unlocked(FILE *);
190 int fputc_unlocked(int, FILE *);
191 int fflush_unlocked(FILE *);
192 size_t fread_unlocked(void *, size_t, size_t, FILE *);
193 size_t fwrite_unlocked(const void *, size_t, size_t, FILE *);
194 void clearerr_unlocked(FILE *);
195 int feof_unlocked(FILE *);
196 int ferror_unlocked(FILE *);
197 int fileno_unlocked(FILE *);
198 int getw(FILE *);
199 int putw(int, FILE *);
200 char *fgetln(FILE *, size_t *);
201 int asprintf(char **, const char *, ...);
202 int vasprintf(char **, const char *, __isoc_va_list);
203 #endif
204
205 #ifdef _GNU_SOURCE
206 char *fgets_unlocked(char *, int, FILE *);
207 int fputs_unlocked(const char *, FILE *);
208
209 typedef ssize_t (cookie_read_function_t)(void *, char *, size_t);
210 typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t);
211 typedef int (cookie_seek_function_t)(void *, off_t *, int);
212 typedef int (cookie_close_function_t)(void *);
213
214 typedef struct _IO_cookie_io_functions_t {
215 cookie_read_function_t *read;
216 cookie_write_function_t *write;
217 cookie_seek_function_t *seek;
218 cookie_close_function_t *close;
219 } cookie_io_functions_t;
220
221 FILE *fopencookie(void *, const char *, cookie_io_functions_t);
222 #endif
223
224 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
225 #define tmpfile64 tmpfile
226 #define fopen64 fopen
227 #define freopen64 freopen
228 #define fseeko64 fseeko
229 #define ftello64 ftello
230 #define fgetpos64 fgetpos
231 #define fsetpos64 fsetpos
232 #define fpos64_t fpos_t
233 #define off64_t off_t
234 #endif
235
236 #ifdef __cplusplus
237 }
238 #endif
239
240 #endif