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