Sync to trunk head (r40091)
[reactos.git] / reactos / include / crt / stdio.h
1 /**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the w64 mingw-runtime package.
4 * No warranty is given; refer to the file DISCLAIMER within this package.
5 */
6 #ifndef _INC_STDIO
7 #define _INC_STDIO
8
9 #include <crtdefs.h>
10
11 #pragma pack(push,_CRT_PACKING)
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #define BUFSIZ 512
18 #define _NFILE _NSTREAM_
19 #define _NSTREAM_ 512
20 #define _IOB_ENTRIES 20
21 #define EOF (-1)
22
23 #ifndef _FILE_DEFINED
24 struct _iobuf {
25 char *_ptr;
26 int _cnt;
27 char *_base;
28 int _flag;
29 int _file;
30 int _charbuf;
31 int _bufsiz;
32 char *_tmpfname;
33 };
34 typedef struct _iobuf FILE;
35 #define _FILE_DEFINED
36 #endif
37
38 #ifdef _POSIX_
39 #define _P_tmpdir "/"
40 #define _wP_tmpdir L"/"
41 #else
42 #define _P_tmpdir "\\"
43 #define _wP_tmpdir L"\\"
44 #endif
45
46 #define L_tmpnam (sizeof(_P_tmpdir) + 12)
47
48 #ifdef _POSIX_
49 #define L_ctermid 9
50 #define L_cuserid 32
51 #endif
52
53 #define SEEK_CUR 1
54 #define SEEK_END 2
55 #define SEEK_SET 0
56
57 #define STDIN_FILENO 0
58 #define STDOUT_FILENO 1
59 #define STDERR_FILENO 2
60
61 #define FILENAME_MAX 260
62 #define FOPEN_MAX 20
63 #define _SYS_OPEN 20
64 #define TMP_MAX 32767
65
66 #ifndef NULL
67 #ifdef __cplusplus
68 #define NULL 0
69 #else
70 #define NULL ((void *)0)
71 #endif
72 #endif
73
74 #ifndef _OFF_T_DEFINED
75 #define _OFF_T_DEFINED
76 #ifndef _OFF_T_
77 #define _OFF_T_
78 typedef long _off_t;
79 #if !defined(NO_OLDNAMES) || defined(_POSIX)
80 typedef long off_t;
81 #endif
82 #endif
83 #endif
84
85 #ifndef _OFF64_T_DEFINED
86 #define _OFF64_T_DEFINED
87 typedef long long _off64_t;
88 #if !defined(NO_OLDNAMES) || defined(_POSIX)
89 typedef long long off64_t;
90 #endif
91 #endif
92
93 #ifndef _STDIO_DEFINED
94 _CRTIMP FILE *__cdecl __iob_func(void);
95 _CRTDATA(extern FILE _iob[];)
96 #ifdef _M_CEE_PURE
97 #define _iob __iob_func()
98 #endif
99 #endif
100
101 #ifndef _FPOS_T_DEFINED
102 #define _FPOS_T_DEFINED
103 #undef _FPOSOFF
104
105 #if (!defined(NO_OLDNAMES) || defined(__GNUC__)) && _INTEGRAL_MAX_BITS >= 64
106 typedef __int64 fpos_t;
107 #define _FPOSOFF(fp) ((long)(fp))
108 #else
109 typedef long long fpos_t;
110 #define _FPOSOFF(fp) ((long)(fp))
111 #endif
112
113 #endif
114
115 #ifndef _STDSTREAM_DEFINED
116 #define _STDSTREAM_DEFINED
117 #define stdin (&_iob[0])
118 #define stdout (&_iob[1])
119 #define stderr (&_iob[1])
120 #endif /* !_STDSTREAM_DEFINED */
121
122 #define _IOREAD 0x0001
123 #define _IOWRT 0x0002
124
125 #define _IOFBF 0x0000
126 #define _IOLBF 0x0040
127 #define _IONBF 0x0004
128
129 #define _IOMYBUF 0x0008
130 #define _IOEOF 0x0010
131 #define _IOERR 0x0020
132 #define _IOSTRG 0x0040
133 #define _IORW 0x0080
134
135 #define _TWO_DIGIT_EXPONENT 0x1
136
137 #ifndef _STDIO_DEFINED
138
139 _CRTIMP int __cdecl _filbuf(FILE *_File);
140 _CRTIMP int __cdecl _flsbuf(int _Ch,FILE *_File);
141 #ifdef _POSIX_
142 _CRTIMP FILE *__cdecl _fsopen(const char *_Filename,const char *_Mode);
143 #else
144 _CRTIMP FILE *__cdecl _fsopen(const char *_Filename,const char *_Mode,int _ShFlag);
145 #endif
146 _CRTIMP void __cdecl clearerr(FILE *_File);
147 _CRTIMP int __cdecl fclose(FILE *_File);
148 _CRTIMP int __cdecl _fcloseall(void);
149 #ifdef _POSIX_
150 FILE *__cdecl fdopen(int _FileHandle,const char *_Mode);
151 #else
152 _CRTIMP FILE *__cdecl _fdopen(int _FileHandle,const char *_Mode);
153 #endif
154 _CRTIMP int __cdecl feof(FILE *_File);
155 _CRTIMP int __cdecl ferror(FILE *_File);
156 _CRTIMP int __cdecl fflush(FILE *_File);
157 _CRTIMP int __cdecl fgetc(FILE *_File);
158 _CRTIMP int __cdecl _fgetchar(void);
159 _CRTIMP int __cdecl fgetpos(FILE *_File ,fpos_t *_Pos);
160 _CRTIMP char *__cdecl fgets(char *_Buf,int _MaxCount,FILE *_File);
161 #ifdef _POSIX_
162 int __cdecl fileno(FILE *_File);
163 #else
164 _CRTIMP int __cdecl _fileno(FILE *_File);
165 #endif
166 _CRTIMP char *__cdecl _tempnam(const char *_DirName,const char *_FilePrefix);
167 _CRTIMP int __cdecl _flushall(void);
168 _CRTIMP FILE *__cdecl fopen(const char *_Filename,const char *_Mode);
169 _CRTIMP int __cdecl fprintf(FILE *_File,const char *_Format,...);
170 _CRTIMP int __cdecl fputc(int _Ch,FILE *_File);
171 _CRTIMP int __cdecl _fputchar(int _Ch);
172 _CRTIMP int __cdecl fputs(const char *_Str,FILE *_File);
173 _CRTIMP size_t __cdecl fread(void *_DstBuf,size_t _ElementSize,size_t _Count,FILE *_File);
174 _CRTIMP _CRT_INSECURE_DEPRECATE(freopen_s) FILE *__cdecl freopen(const char *_Filename,const char *_Mode,FILE *_File);
175 _CRTIMP _CRT_INSECURE_DEPRECATE(fscanf_s) int __cdecl fscanf(FILE *_File,const char *_Format,...);
176 _CRTIMP int __cdecl fsetpos(FILE *_File,const fpos_t *_Pos);
177 _CRTIMP int __cdecl fseek(FILE *_File,long _Offset,int _Origin);
178 _CRTIMP long __cdecl ftell(FILE *_File);
179 _CRTIMP int __cdecl _fseeki64(FILE *_File,__int64 _Offset,int _Origin);
180 _CRTIMP __int64 __cdecl _ftelli64(FILE *_File);
181 _CRTIMP size_t __cdecl fwrite(const void *_Str,size_t _Size,size_t _Count,FILE *_File);
182 _CRTIMP int __cdecl getc(FILE *_File);
183 _CRTIMP int __cdecl getchar(void);
184 _CRTIMP int __cdecl _getmaxstdio(void);
185 _CRTIMP char *__cdecl gets(char *_Buffer); // FIXME: non-standard
186 _CRTIMP int __cdecl _getw(FILE *_File);
187 #ifndef _CRT_PERROR_DEFINED
188 #define _CRT_PERROR_DEFINED
189 _CRTIMP void __cdecl perror(const char *_ErrMsg);
190 #endif
191 _CRTIMP int __cdecl _pclose(FILE *_File);
192 _CRTIMP FILE *__cdecl _popen(const char *_Command,const char *_Mode);
193 _CRTIMP int __cdecl printf(const char *_Format,...);
194 _CRTIMP int __cdecl putc(int _Ch,FILE *_File);
195 _CRTIMP int __cdecl putchar(int _Ch);
196 _CRTIMP int __cdecl puts(const char *_Str);
197 _CRTIMP int __cdecl _putw(int _Word,FILE *_File);
198 #ifndef _CRT_DIRECTORY_DEFINED
199 #define _CRT_DIRECTORY_DEFINED
200 _CRTIMP int __cdecl remove(const char *_Filename);
201 _CRTIMP int __cdecl rename(const char *_OldFilename,const char *_NewFilename);
202 _CRTIMP int __cdecl _unlink(const char *_Filename);
203 #ifndef NO_OLDNAMES
204 _CRTIMP _CRT_NONSTDC_DEPRECATE(_unlink) int __cdecl unlink(const char *_Filename);
205 #endif
206 #endif
207 _CRTIMP void __cdecl rewind(FILE *_File);
208 _CRTIMP int __cdecl _rmtmp(void);
209 _CRTIMP _CRT_INSECURE_DEPRECATE_CORE(scanf_s) int __cdecl scanf(const char *_Format,...);
210 _CRTIMP _CRT_INSECURE_DEPRECATE(setvbuf) void __cdecl setbuf(FILE *_File,char *_Buffer);
211 _CRTIMP int __cdecl _setmaxstdio(int _Max);
212 _CRTIMP unsigned int __cdecl _set_output_format(unsigned int _Format);
213 _CRTIMP unsigned int __cdecl _get_output_format(void);
214 _CRTIMP int __cdecl setvbuf(FILE *_File,char *_Buf,int _Mode,size_t _Size);
215 _CRTIMP int __cdecl _scprintf(const char *_Format,...);
216 _CRTIMP _CRT_INSECURE_DEPRECATE_CORE(sscanf_s) int __cdecl sscanf(const char *_Src,const char *_Format,...);
217 _CRTIMP _CRT_INSECURE_DEPRECATE_CORE(_snscanf_s) int __cdecl _snscanf(const char *_Src,size_t _MaxCount,const char *_Format,...);
218 _CRTIMP _CRT_INSECURE_DEPRECATE(tmpfile_s) FILE *__cdecl tmpfile(void);
219 _CRTIMP char *__cdecl tmpnam(char *_Buffer);
220 _CRTIMP_ALT int __cdecl ungetc(int _Ch,FILE *_File);
221 _CRTIMP int __cdecl vfprintf(FILE *_File,const char *_Format,va_list _ArgList);
222 _CRTIMP int __cdecl vprintf(const char *_Format,va_list _ArgList);
223 /* Make sure macros are not defined. */
224 #if __MINGW_GNUC_PREREQ(4,4)
225 #pragma push_macro("vsnprintf")
226 #pragma push_macro("snprintf")
227 #endif
228 #undef vsnprintf
229 #undef snprintf
230 _CRTIMP _CRT_INSECURE_DEPRECATE(vsnprintf_s) int __cdecl vsnprintf(char *_DstBuf,size_t _MaxCount,const char *_Format,va_list _ArgList);
231 _CRTIMP int __cdecl _snprintf(char *_Dest,size_t _Count,const char *_Format,...);
232 _CRTIMP int __cdecl _vsnprintf(char *_Dest,size_t _Count,const char *_Format,va_list _Args);
233 int __cdecl sprintf(char *_Dest,const char *_Format,...);
234 int __cdecl vsprintf(char *_Dest,const char *_Format,va_list _Args);
235 #ifndef __NO_ISOCEXT /* externs in libmingwex.a */
236 int __cdecl snprintf(char* s, size_t n, const char* format, ...);
237 int __cdecl vscanf(const char * __restrict__ Format, va_list argp);
238 int __cdecl vfscanf (FILE * __restrict__ fp, const char * Format,va_list argp);
239 int __cdecl vsscanf (const char * __restrict__ _Str,const char * __restrict__ Format,va_list argp);
240 #endif
241 /* Restore may prior defined macros snprintf/vsnprintf. */
242 #if __MINGW_GNUC_PREREQ(4,4)
243 #pragma pop_macro("snprintf")
244 #pragma pop_macro("vsnprintf")
245 #endif
246
247 #ifndef vsnprintf
248 #define vsnprintf _vsnprintf
249 #endif
250 #ifndef snprintf
251 #define snprintf _snprintf
252 #endif
253
254 _CRTIMP int __cdecl _vscprintf(const char *_Format,va_list _ArgList);
255 #ifdef _SAFECRT_IMPL
256 #define _set_printf_count_output(i)
257 #define _get_printf_count_output() (FALSE)
258 #else
259 _CRTIMP int __cdecl _set_printf_count_output(int _Value);
260 _CRTIMP int __cdecl _get_printf_count_output(void);
261 #endif
262
263 #ifndef _WSTDIO_DEFINED
264
265 #ifndef WEOF
266 #define WEOF (wint_t)(0xFFFF)
267 #endif
268
269 #ifdef _POSIX_
270 _CRTIMP FILE *__cdecl _wfsopen(const wchar_t *_Filename,const wchar_t *_Mode);
271 #else
272 _CRTIMP FILE *__cdecl _wfsopen(const wchar_t *_Filename,const wchar_t *_Mode,int _ShFlag);
273 #endif
274 _CRTIMP wint_t __cdecl fgetwc(FILE *_File);
275 _CRTIMP wint_t __cdecl _fgetwchar(void);
276 _CRTIMP wint_t __cdecl fputwc(wchar_t _Ch,FILE *_File);
277 _CRTIMP wint_t __cdecl _fputwchar(wchar_t _Ch);
278 _CRTIMP wint_t __cdecl getwc(FILE *_File);
279 _CRTIMP wint_t __cdecl getwchar(void);
280 _CRTIMP wint_t __cdecl putwc(wchar_t _Ch,FILE *_File);
281 _CRTIMP wint_t __cdecl putwchar(wchar_t _Ch);
282 _CRTIMP wint_t __cdecl ungetwc(wint_t _Ch,FILE *_File);
283 _CRTIMP wchar_t *__cdecl fgetws(wchar_t *_Dst,int _SizeInWords,FILE *_File);
284 _CRTIMP int __cdecl fputws(const wchar_t *_Str,FILE *_File);
285 _CRTIMP wchar_t *__cdecl _getws(wchar_t *_String);
286 _CRTIMP int __cdecl _putws(const wchar_t *_Str);
287 _CRTIMP int __cdecl fwprintf(FILE *_File,const wchar_t *_Format,...);
288 _CRTIMP int __cdecl wprintf(const wchar_t *_Format,...);
289 _CRTIMP int __cdecl _scwprintf(const wchar_t *_Format,...);
290 _CRTIMP int __cdecl vfwprintf(FILE *_File,const wchar_t *_Format,va_list _ArgList);
291 _CRTIMP int __cdecl vwprintf(const wchar_t *_Format,va_list _ArgList);
292 _CRTIMP int __cdecl swprintf(wchar_t*, const wchar_t*, ...);
293 _CRTIMP int __cdecl vswprintf(wchar_t*, const wchar_t*,va_list);
294 _CRTIMP int __cdecl _swprintf_c(wchar_t *_DstBuf,size_t _SizeInWords,const wchar_t *_Format,...);
295 _CRTIMP int __cdecl _vswprintf_c(wchar_t *_DstBuf,size_t _SizeInWords,const wchar_t *_Format,va_list _ArgList);
296 _CRTIMP int __cdecl _snwprintf(wchar_t *_Dest,size_t _Count,const wchar_t *_Format,...);
297 _CRTIMP int __cdecl _vsnwprintf(wchar_t *_Dest,size_t _Count,const wchar_t *_Format,va_list _Args);
298 #ifndef __NO_ISOCEXT /* externs in libmingwex.a */
299 _CRTIMP int __cdecl snwprintf (wchar_t* s, size_t n, const wchar_t* format, ...);
300 __CRT_INLINE int __cdecl vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, va_list arg) { return _vsnwprintf(s,n,format,arg); }
301 _CRTIMP int __cdecl vwscanf (const wchar_t *, va_list);
302 _CRTIMP int __cdecl vfwscanf (FILE *,const wchar_t *,va_list);
303 _CRTIMP int __cdecl vswscanf (const wchar_t *,const wchar_t *,va_list);
304 #endif
305 _CRTIMP int __cdecl _swprintf(wchar_t *_Dest,const wchar_t *_Format,...);
306 _CRTIMP int __cdecl _vswprintf(wchar_t *_Dest,const wchar_t *_Format,va_list _Args);
307
308 #ifndef RC_INVOKED
309 #include <vadefs.h>
310 #endif
311
312 #ifdef _CRT_NON_CONFORMING_SWPRINTFS
313 #ifndef __cplusplus
314 #define swprintf _swprintf
315 #define vswprintf _vswprintf
316 #define _swprintf_l __swprintf_l
317 #define _vswprintf_l __vswprintf_l
318 #endif
319 #endif
320
321 _CRTIMP wchar_t *__cdecl _wtempnam(const wchar_t *_Directory,const wchar_t *_FilePrefix);
322 _CRTIMP int __cdecl _vscwprintf(const wchar_t *_Format,va_list _ArgList);
323 _CRTIMP int __cdecl fwscanf(FILE *_File,const wchar_t *_Format,...);
324 _CRTIMP int __cdecl swscanf(const wchar_t *_Src,const wchar_t *_Format,...);
325 _CRTIMP int __cdecl _snwscanf(const wchar_t *_Src,size_t _MaxCount,const wchar_t *_Format,...);
326 _CRTIMP int __cdecl wscanf(const wchar_t *_Format,...);
327 _CRTIMP FILE *__cdecl _wfdopen(int _FileHandle ,const wchar_t *_Mode);
328 _CRTIMP FILE *__cdecl _wfopen(const wchar_t *_Filename,const wchar_t *_Mode);
329 _CRTIMP FILE *__cdecl _wfreopen(const wchar_t *_Filename,const wchar_t *_Mode,FILE *_OldFile);
330 #ifndef _CRT_WPERROR_DEFINED
331 #define _CRT_WPERROR_DEFINED
332 _CRTIMP void __cdecl _wperror(const wchar_t *_ErrMsg);
333 #endif
334 _CRTIMP FILE *__cdecl _wpopen(const wchar_t *_Command,const wchar_t *_Mode);
335 #if !defined(NO_OLDNAMES) && !defined(wpopen)
336 #define wpopen _wpopen
337 #endif
338 _CRTIMP int __cdecl _wremove(const wchar_t *_Filename);
339 _CRTIMP wchar_t *__cdecl _wtmpnam(wchar_t *_Buffer);
340 _CRTIMP wint_t __cdecl _fgetwc_nolock(FILE *_File);
341 _CRTIMP wint_t __cdecl _fputwc_nolock(wchar_t _Ch,FILE *_File);
342 _CRTIMP wint_t __cdecl _ungetwc_nolock(wint_t _Ch,FILE *_File);
343
344 #undef _CRT_GETPUTWCHAR_NOINLINE
345
346 #if !defined(__cplusplus) || defined(_CRT_GETPUTWCHAR_NOINLINE)
347 #define getwchar() fgetwc(stdin)
348 #define putwchar(_c) fputwc((_c),stdout)
349 #else
350 __CRT_INLINE wint_t __cdecl getwchar() { return (fgetwc(stdin)); }
351 __CRT_INLINE wint_t __cdecl putwchar(wchar_t _C) { return (fputwc(_C,stdout)); }
352 #endif
353
354 #define getwc(_stm) fgetwc(_stm)
355 #define putwc(_c,_stm) fputwc(_c,_stm)
356 #define _putwc_nolock(_c,_stm) _fputwc_nolock(_c,_stm)
357 #define _getwc_nolock(_stm) _fgetwc_nolock(_stm)
358
359 #define _WSTDIO_DEFINED
360 #endif
361
362 #define _STDIO_DEFINED
363 #endif // !_STDIO_DEFINED
364
365 #define _fgetc_nolock(_stream) (--(_stream)->_cnt >= 0 ? 0xff & *(_stream)->_ptr++ : _filbuf(_stream))
366 #define _fputc_nolock(_c,_stream) (--(_stream)->_cnt >= 0 ? 0xff & (*(_stream)->_ptr++ = (char)(_c)) : _flsbuf((_c),(_stream)))
367 #define _getc_nolock(_stream) _fgetc_nolock(_stream)
368 #define _putc_nolock(_c,_stream) _fputc_nolock(_c,_stream)
369 #define _getchar_nolock() _getc_nolock(stdin)
370 #define _putchar_nolock(_c) _putc_nolock((_c),stdout)
371 #define _getwchar_nolock() _getwc_nolock(stdin)
372 #define _putwchar_nolock(_c) _putwc_nolock((_c),stdout)
373
374 _CRTIMP void __cdecl _lock_file(FILE *_File);
375 _CRTIMP void __cdecl _unlock_file(FILE *_File);
376 _CRTIMP int __cdecl _fclose_nolock(FILE *_File);
377 _CRTIMP int __cdecl _fflush_nolock(FILE *_File);
378 _CRTIMP size_t __cdecl _fread_nolock(void *_DstBuf,size_t _ElementSize,size_t _Count,FILE *_File);
379 _CRTIMP int __cdecl _fseek_nolock(FILE *_File,long _Offset,int _Origin);
380 _CRTIMP long __cdecl _ftell_nolock(FILE *_File);
381 _CRTIMP int __cdecl _fseeki64_nolock(FILE *_File,__int64 _Offset,int _Origin);
382 _CRTIMP __int64 __cdecl _ftelli64_nolock(FILE *_File);
383 _CRTIMP size_t __cdecl _fwrite_nolock(const void *_DstBuf,size_t _Size,size_t _Count,FILE *_File);
384 _CRTIMP int __cdecl _ungetc_nolock(int _Ch,FILE *_File);
385
386 #if !defined(NO_OLDNAMES) || !defined(_POSIX)
387 #define P_tmpdir _P_tmpdir
388 #define SYS_OPEN _SYS_OPEN
389
390 char *__cdecl tempnam(const char *_Directory,const char *_FilePrefix);
391 int __cdecl fcloseall(void);
392 FILE *__cdecl fdopen(int _FileHandle,const char *_Format);
393 int __cdecl fgetchar(void);
394 int __cdecl fileno(FILE *_File);
395 int __cdecl flushall(void);
396 int __cdecl fputchar(int _Ch);
397 int __cdecl getw(FILE *_File);
398 int __cdecl putw(int _Ch,FILE *_File);
399 int __cdecl rmtmp(void);
400 #endif
401
402 #ifdef __cplusplus
403 }
404 #endif
405
406 #pragma pack(pop)
407
408 #include <sec_api/stdio_s.h>
409
410 #endif