Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / mingw / include / stdio.h
blob23914a3ff12524c8e6950c4c78aa09716186f697
1 /*
2 * stdio.h
3 * This file has no copyright assigned and is placed in the Public Domain.
4 * This file is a part of the mingw-runtime package.
5 * No warranty is given; refer to the file DISCLAIMER within the package.
7 * Definitions of types and prototypes of functions for standard input and
8 * output.
10 * NOTE: The file manipulation functions provided by Microsoft seem to
11 * work with either slash (/) or backslash (\) as the directory separator.
15 #ifndef _STDIO_H_
16 #define _STDIO_H_
18 /* All the headers include this file. */
19 #include <_mingw.h>
21 #ifndef RC_INVOKED
22 #define __need_size_t
23 #define __need_NULL
24 #define __need_wchar_t
25 #define __need_wint_t
26 #include <stddef.h>
27 #define __need___va_list
28 #include <stdarg.h>
29 #endif /* Not RC_INVOKED */
32 /* Flags for the iobuf structure */
33 #define _IOREAD 1 /* currently reading */
34 #define _IOWRT 2 /* currently writing */
35 #define _IORW 0x0080 /* opened as "r+w" */
39 * The three standard file pointers provided by the run time library.
40 * NOTE: These will go to the bit-bucket silently in GUI applications!
42 #define STDIN_FILENO 0
43 #define STDOUT_FILENO 1
44 #define STDERR_FILENO 2
46 /* Returned by various functions on end of file condition or error. */
47 #define EOF (-1)
50 * The maximum length of a file name. You should use GetVolumeInformation
51 * instead of this constant. But hey, this works.
52 * Also defined in io.h.
54 #ifndef FILENAME_MAX
55 #define FILENAME_MAX (260)
56 #endif
59 * The maximum number of files that may be open at once. I have set this to
60 * a conservative number. The actual value may be higher.
62 #define FOPEN_MAX (20)
64 /* After creating this many names, tmpnam and tmpfile return NULL */
65 #define TMP_MAX 32767
67 * Tmpnam, tmpfile and, sometimes, _tempnam try to create
68 * temp files in the root directory of the current drive
69 * (not in pwd, as suggested by some older MS doc's).
70 * Redefining these macros does not effect the CRT functions.
72 #define _P_tmpdir "\\"
73 #ifndef __STRICT_ANSI__
74 #define P_tmpdir _P_tmpdir
75 #endif
76 #define _wP_tmpdir L"\\"
79 * The maximum size of name (including NUL) that will be put in the user
80 * supplied buffer caName for tmpnam.
81 * Inferred from the size of the static buffer returned by tmpnam
82 * when passed a NULL argument. May actually be smaller.
84 #define L_tmpnam (16)
86 #define _IOFBF 0x0000 /* full buffered */
87 #define _IOLBF 0x0040 /* line buffered */
88 #define _IONBF 0x0004 /* not buffered */
90 #define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */
91 #define _IOEOF 0x0010 /* EOF reached on read */
92 #define _IOERR 0x0020 /* I/O error from system */
93 #define _IOSTRG 0x0040 /* Strange or no file descriptor */
94 #ifdef _POSIX_SOURCE
95 # define _IOAPPEND 0x0200
96 #endif
98 * The buffer size as used by setbuf such that it is equivalent to
99 * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ).
101 #define BUFSIZ 512
103 /* Constants for nOrigin indicating the position relative to which fseek
104 * sets the file position. Defined unconditionally since ISO and POSIX
105 * say they are defined here. */
106 #define SEEK_SET 0
107 #define SEEK_CUR 1
108 #define SEEK_END 2
110 #ifndef RC_INVOKED
112 #ifndef __VALIST
113 #ifdef __GNUC__
114 #define __VALIST __gnuc_va_list
115 #else
116 #define __VALIST char*
117 #endif
118 #endif /* defined __VALIST */
121 * The structure underlying the FILE type.
123 * Some believe that nobody in their right mind should make use of the
124 * internals of this structure. Provided by Pedro A. Aranda Gutiirrez
125 * <paag@tid.es>.
127 #ifndef _FILE_DEFINED
128 #define _FILE_DEFINED
129 typedef struct _iobuf
131 char* _ptr;
132 int _cnt;
133 char* _base;
134 int _flag;
135 int _file;
136 int _charbuf;
137 int _bufsiz;
138 char* _tmpfname;
139 } FILE;
140 #endif /* Not _FILE_DEFINED */
144 * The standard file handles
146 #ifndef __DECLSPEC_SUPPORTED
148 extern FILE (*_imp___iob)[]; /* A pointer to an array of FILE */
150 #define _iob (*_imp___iob) /* An array of FILE */
152 #else /* __DECLSPEC_SUPPORTED */
154 __MINGW_IMPORT FILE _iob[]; /* An array of FILE imported from DLL. */
156 #endif /* __DECLSPEC_SUPPORTED */
158 #define stdin (&_iob[STDIN_FILENO])
159 #define stdout (&_iob[STDOUT_FILENO])
160 #define stderr (&_iob[STDERR_FILENO])
162 #ifdef __cplusplus
163 extern "C" {
164 #endif
167 * File Operations
169 _CRTIMP FILE* __cdecl fopen (const char*, const char*);
170 _CRTIMP FILE* __cdecl freopen (const char*, const char*, FILE*);
171 _CRTIMP int __cdecl fflush (FILE*);
172 _CRTIMP int __cdecl fclose (FILE*);
173 /* MS puts remove & rename (but not wide versions) in io.h also */
174 _CRTIMP int __cdecl remove (const char*);
175 _CRTIMP int __cdecl rename (const char*, const char*);
176 _CRTIMP FILE* __cdecl tmpfile (void);
177 _CRTIMP char* __cdecl tmpnam (char*);
179 #ifndef __STRICT_ANSI__
180 _CRTIMP char* __cdecl _tempnam (const char*, const char*);
181 _CRTIMP int __cdecl _rmtmp(void);
182 _CRTIMP int __cdecl _unlink (const char*);
184 #ifndef NO_OLDNAMES
185 _CRTIMP char* __cdecl tempnam (const char*, const char*);
186 _CRTIMP int __cdecl rmtmp(void);
187 _CRTIMP int __cdecl unlink (const char*);
188 #endif
189 #endif /* __STRICT_ANSI__ */
191 _CRTIMP int __cdecl setvbuf (FILE*, char*, int, size_t);
193 _CRTIMP void __cdecl setbuf (FILE*, char*);
196 * Formatted Output
199 _CRTIMP int __cdecl fprintf (FILE*, const char*, ...);
200 _CRTIMP int __cdecl printf (const char*, ...);
201 _CRTIMP int __cdecl sprintf (char*, const char*, ...);
202 _CRTIMP int __cdecl _snprintf (char*, size_t, const char*, ...);
203 _CRTIMP int __cdecl vfprintf (FILE*, const char*, __VALIST);
204 _CRTIMP int __cdecl vprintf (const char*, __VALIST);
205 _CRTIMP int __cdecl vsprintf (char*, const char*, __VALIST);
206 _CRTIMP int __cdecl _vsnprintf (char*, size_t, const char*, __VALIST);
208 #ifndef __NO_ISOCEXT /* externs in libmingwex.a */
209 int __cdecl snprintf(char* s, size_t n, const char* format, ...);
210 __CRT_INLINE int __cdecl
211 vsnprintf (char* s, size_t n, const char* format, __VALIST arg)
212 { return _vsnprintf ( s, n, format, arg); }
213 int __cdecl vscanf (const char * __restrict__, __VALIST);
214 int __cdecl vfscanf (FILE * __restrict__, const char * __restrict__,
215 __VALIST);
216 int __cdecl vsscanf (const char * __restrict__,
217 const char * __restrict__, __VALIST);
218 #endif
221 * Formatted Input
224 _CRTIMP int __cdecl fscanf (FILE*, const char*, ...);
225 _CRTIMP int __cdecl scanf (const char*, ...);
226 _CRTIMP int __cdecl sscanf (const char*, const char*, ...);
228 * Character Input and Output Functions
231 _CRTIMP int __cdecl fgetc (FILE*);
232 _CRTIMP char* __cdecl fgets (char*, int, FILE*);
233 _CRTIMP int __cdecl fputc (int, FILE*);
234 _CRTIMP int __cdecl fputs (const char*, FILE*);
235 _CRTIMP char* __cdecl gets (char*);
236 _CRTIMP int __cdecl puts (const char*);
237 _CRTIMP int __cdecl ungetc (int, FILE*);
239 /* Traditionally, getc and putc are defined as macros. but the
240 standard doesn't say that they must be macros.
241 We use inline functions here to allow the fast versions
242 to be used in C++ with namespace qualification, eg., ::getc.
244 _filbuf and _flsbuf are not thread-safe. */
245 _CRTIMP int __cdecl _filbuf (FILE*);
246 _CRTIMP int __cdecl _flsbuf (int, FILE*);
248 #if !defined _MT
250 __CRT_INLINE int __cdecl getc (FILE* __F)
252 return (--__F->_cnt >= 0)
253 ? (int) (unsigned char) *__F->_ptr++
254 : _filbuf (__F);
257 __CRT_INLINE int __cdecl putc (int __c, FILE* __F)
259 return (--__F->_cnt >= 0)
260 ? (int) (unsigned char) (*__F->_ptr++ = (char)__c)
261 : _flsbuf (__c, __F);
264 __CRT_INLINE int __cdecl getchar (void)
266 return (--stdin->_cnt >= 0)
267 ? (int) (unsigned char) *stdin->_ptr++
268 : _filbuf (stdin);
271 __CRT_INLINE int __cdecl putchar(int __c)
273 return (--stdout->_cnt >= 0)
274 ? (int) (unsigned char) (*stdout->_ptr++ = (char)__c)
275 : _flsbuf (__c, stdout);}
277 #else /* Use library functions. */
279 _CRTIMP int __cdecl getc (FILE*);
280 _CRTIMP int __cdecl putc (int, FILE*);
281 _CRTIMP int __cdecl getchar (void);
282 _CRTIMP int __cdecl putchar (int);
284 #endif
287 * Direct Input and Output Functions
290 _CRTIMP size_t __cdecl fread (void*, size_t, size_t, FILE*);
291 _CRTIMP size_t __cdecl fwrite (const void*, size_t, size_t, FILE*);
294 * File Positioning Functions
297 _CRTIMP int __cdecl fseek (FILE*, long, int);
298 _CRTIMP long __cdecl ftell (FILE*);
299 _CRTIMP void __cdecl rewind (FILE*);
301 #if __MSVCRT_VERSION__ >= 0x800
302 _CRTIMP int __cdecl _fseek_nolock (FILE*, long, int);
303 _CRTIMP long __cdecl _ftell_nolock (FILE*);
305 _CRTIMP int __cdecl _fseeki64 (FILE*, __int64, int);
306 _CRTIMP __int64 __cdecl _ftelli64 (FILE*);
307 _CRTIMP int __cdecl _fseeki64_nolock (FILE*, __int64, int);
308 _CRTIMP __int64 __cdecl _ftelli64_nolock (FILE*);
309 #endif
311 #ifdef __USE_MINGW_FSEEK /* These are in libmingwex.a */
313 * Workaround for limitations on win9x where a file contents are
314 * not zero'd out if you seek past the end and then write.
317 int __cdecl __mingw_fseek (FILE *, long, int);
318 size_t __cdecl __mingw_fwrite (const void*, size_t, size_t, FILE*);
319 #define fseek(fp, offset, whence) __mingw_fseek(fp, offset, whence)
320 #define fwrite(buffer, size, count, fp) __mingw_fwrite(buffer, size, count, fp)
321 #endif /* __USE_MINGW_FSEEK */
324 * An opaque data type used for storing file positions... The contents of
325 * this type are unknown, but we (the compiler) need to know the size
326 * because the programmer using fgetpos and fsetpos will be setting aside
327 * storage for fpos_t structres. Actually I tested using a byte array and
328 * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
329 * Perhaps an unsigned long? TODO? It's definitely a 64-bit number in
330 * MSVCRT however, and for now `long long' will do.
332 #ifdef __MSVCRT__
333 typedef long long fpos_t;
334 #else
335 typedef long fpos_t;
336 #endif
338 _CRTIMP int __cdecl fgetpos (FILE*, fpos_t*);
339 _CRTIMP int __cdecl fsetpos (FILE*, const fpos_t*);
342 * Error Functions
345 _CRTIMP int __cdecl feof (FILE*);
346 _CRTIMP int __cdecl ferror (FILE*);
348 #ifdef __cplusplus
349 inline int __cdecl feof (FILE* __F)
350 { return __F->_flag & _IOEOF; }
351 inline int __cdecl ferror (FILE* __F)
352 { return __F->_flag & _IOERR; }
353 #else
354 #define feof(__F) ((__F)->_flag & _IOEOF)
355 #define ferror(__F) ((__F)->_flag & _IOERR)
356 #endif
358 _CRTIMP void __cdecl clearerr (FILE*);
359 _CRTIMP void __cdecl perror (const char*);
362 #ifndef __STRICT_ANSI__
364 * Pipes
366 _CRTIMP FILE* __cdecl _popen (const char*, const char*);
367 _CRTIMP int __cdecl _pclose (FILE*);
369 #ifndef NO_OLDNAMES
370 _CRTIMP FILE* __cdecl popen (const char*, const char*);
371 _CRTIMP int __cdecl pclose (FILE*);
372 #endif
375 * Other Non ANSI functions
377 _CRTIMP int __cdecl _flushall (void);
378 _CRTIMP int __cdecl _fgetchar (void);
379 _CRTIMP int __cdecl _fputchar (int);
380 _CRTIMP FILE* __cdecl _fdopen (int, const char*);
381 _CRTIMP int __cdecl _fileno (FILE*);
382 _CRTIMP int __cdecl _fcloseall(void);
383 _CRTIMP FILE* __cdecl _fsopen(const char*, const char*, int);
384 #ifdef __MSVCRT__
385 _CRTIMP int __cdecl _getmaxstdio(void);
386 _CRTIMP int __cdecl _setmaxstdio(int);
387 #endif
389 #if __MSVCRT_VERSION__ >= 0x800
390 _CRTIMP int __cdecl _set_printf_count_output(int);
391 _CRTIMP int __cdecl _get_printf_count_output(void);
392 #endif
394 #ifndef _NO_OLDNAMES
395 _CRTIMP int __cdecl fgetchar (void);
396 _CRTIMP int __cdecl fputchar (int);
397 _CRTIMP FILE* __cdecl fdopen (int, const char*);
398 _CRTIMP int __cdecl fileno (FILE*);
399 #endif /* Not _NO_OLDNAMES */
401 #define _fileno(__F) ((__F)->_file)
402 #ifndef _NO_OLDNAMES
403 #define fileno(__F) ((__F)->_file)
404 #endif
406 #if defined (__MSVCRT__) && !defined (__NO_MINGW_LFS)
407 #include <sys/types.h>
408 __CRT_INLINE FILE* __cdecl fopen64 (const char* filename, const char* mode)
410 return fopen (filename, mode);
413 int __cdecl fseeko64 (FILE*, off64_t, int);
415 #ifdef __USE_MINGW_FSEEK
416 int __cdecl __mingw_fseeko64 (FILE *, off64_t, int);
417 #define fseeko64(fp, offset, whence) __mingw_fseeko64(fp, offset, whence)
418 #endif
420 __CRT_INLINE off64_t __cdecl ftello64 (FILE * stream)
422 fpos_t pos;
423 if (fgetpos(stream, &pos))
424 return -1LL;
425 else
426 return ((off64_t) pos);
428 #endif /* __NO_MINGW_LFS */
430 #endif /* Not __STRICT_ANSI__ */
432 /* Wide versions */
434 #ifndef _WSTDIO_DEFINED
435 /* also in wchar.h - keep in sync */
436 _CRTIMP int __cdecl fwprintf (FILE*, const wchar_t*, ...);
437 _CRTIMP int __cdecl wprintf (const wchar_t*, ...);
438 _CRTIMP int __cdecl swprintf (wchar_t*, const wchar_t*, ...);
439 _CRTIMP int __cdecl _snwprintf (wchar_t*, size_t, const wchar_t*, ...);
440 _CRTIMP int __cdecl vfwprintf (FILE*, const wchar_t*, __VALIST);
441 _CRTIMP int __cdecl vwprintf (const wchar_t*, __VALIST);
442 _CRTIMP int __cdecl vswprintf (wchar_t*, const wchar_t*, __VALIST);
443 _CRTIMP int __cdecl _vsnwprintf (wchar_t*, size_t, const wchar_t*, __VALIST);
444 _CRTIMP int __cdecl fwscanf (FILE*, const wchar_t*, ...);
445 _CRTIMP int __cdecl wscanf (const wchar_t*, ...);
446 _CRTIMP int __cdecl swscanf (const wchar_t*, const wchar_t*, ...);
447 _CRTIMP wint_t __cdecl fgetwc (FILE*);
448 _CRTIMP wint_t __cdecl fputwc (wchar_t, FILE*);
449 _CRTIMP wint_t __cdecl ungetwc (wchar_t, FILE*);
451 #ifdef __MSVCRT__
452 _CRTIMP wchar_t* __cdecl fgetws (wchar_t*, int, FILE*);
453 _CRTIMP int __cdecl fputws (const wchar_t*, FILE*);
454 _CRTIMP wint_t __cdecl getwc (FILE*);
455 _CRTIMP wint_t __cdecl getwchar (void);
456 _CRTIMP wchar_t* __cdecl _getws (wchar_t*);
457 _CRTIMP wint_t __cdecl putwc (wint_t, FILE*);
458 _CRTIMP int __cdecl _putws (const wchar_t*);
459 _CRTIMP wint_t __cdecl putwchar (wint_t);
460 _CRTIMP FILE* __cdecl _wfdopen(int, wchar_t *);
461 _CRTIMP FILE* __cdecl _wfopen (const wchar_t*, const wchar_t*);
462 _CRTIMP FILE* __cdecl _wfreopen (const wchar_t*, const wchar_t*, FILE*);
463 _CRTIMP FILE* __cdecl _wfsopen (const wchar_t*, const wchar_t*, int);
464 _CRTIMP wchar_t* __cdecl _wtmpnam (wchar_t*);
465 _CRTIMP wchar_t* __cdecl _wtempnam (const wchar_t*, const wchar_t*);
466 _CRTIMP int __cdecl _wrename (const wchar_t*, const wchar_t*);
467 _CRTIMP int __cdecl _wremove (const wchar_t*);
468 _CRTIMP void __cdecl _wperror (const wchar_t*);
469 _CRTIMP FILE* __cdecl _wpopen (const wchar_t*, const wchar_t*);
470 #endif /* __MSVCRT__ */
472 #ifndef __NO_ISOCEXT /* externs in libmingwex.a */
473 int __cdecl snwprintf (wchar_t* s, size_t n, const wchar_t* format, ...);
474 __CRT_INLINE int __cdecl
475 vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg)
476 { return _vsnwprintf ( s, n, format, arg);}
477 int __cdecl vwscanf (const wchar_t * __restrict__, __VALIST);
478 int __cdecl vfwscanf (FILE * __restrict__,
479 const wchar_t * __restrict__, __VALIST);
480 int __cdecl vswscanf (const wchar_t * __restrict__,
481 const wchar_t * __restrict__, __VALIST);
482 #endif
484 #define _WSTDIO_DEFINED
485 #endif /* _WSTDIO_DEFINED */
487 #ifndef __STRICT_ANSI__
488 #ifdef __MSVCRT__
489 #ifndef NO_OLDNAMES
490 _CRTIMP FILE* __cdecl wpopen (const wchar_t*, const wchar_t*);
491 #endif /* not NO_OLDNAMES */
492 #endif /* MSVCRT runtime */
495 * Other Non ANSI wide functions
497 _CRTIMP wint_t __cdecl _fgetwchar (void);
498 _CRTIMP wint_t __cdecl _fputwchar (wint_t);
499 _CRTIMP int __cdecl _getw (FILE*);
500 _CRTIMP int __cdecl _putw (int, FILE*);
502 #ifndef _NO_OLDNAMES
503 _CRTIMP wint_t __cdecl fgetwchar (void);
504 _CRTIMP wint_t __cdecl fputwchar (wint_t);
505 _CRTIMP int __cdecl getw (FILE*);
506 _CRTIMP int __cdecl putw (int, FILE*);
507 #endif /* Not _NO_OLDNAMES */
509 #endif /* __STRICT_ANSI */
511 #ifdef __cplusplus
513 #endif
515 #endif /* Not RC_INVOKED */
517 #endif /* _STDIO_H_ */