4 * Definitions of types and prototypes of functions for standard input and
7 * NOTE: The file manipulation functions provided by Microsoft seem to
8 * work with either slash (/) or backslash (\) as the path separator.
10 * This file is part of the Mingw32 package.
13 * Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
15 * THIS SOFTWARE IS NOT COPYRIGHTED
17 * This source code is offered for use in the public domain. You may
18 * use, modify or distribute it freely.
20 * This code is distributed in the hope that it will be useful but
21 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
22 * DISCLAMED. This includes but is not limited to warranties of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
30 /* Appropriated for Reactos Crtdll by Ariadne */
31 /* implemented clearerr feof ferror perror as macros */
33 /* added filbuf and flsbuf and fwalk */
44 #define __need_wchar_t
46 #include <crtdll/stddef.h>
49 /* Some flags for the iobuf structure provided by djgpp stdio.h */
50 #define _IOREAD 0x000010
51 #define _IOWRT 0x000020
52 #define _IOMYBUF 0x000040
53 #define _IOEOF 0x000100
54 #define _IOERR 0x000200
55 #define _IOSTRG 0x000400
57 #define _IOAPPEND 0x002000
58 #define _IORMONCL 0x004000 /* remove on close, for temp files */
59 /* if _flag & _IORMONCL, ._name_to_remove needs freeing */
60 #define _IOUNGETC 0x010000 /* there is an ungetc'ed character in the buffer */
61 #define _IOCOMMIT 0x008000
63 #define _IODIRTY 0x000080
64 #define _IOAHEAD 0x000008
65 #define _IORW (_IOREAD | _IOWRITE )
69 * I used to include stdarg.h at this point, in order to allow for the
70 * functions later on in the file which use va_list. That conflicts with
71 * using stdio.h and varargs.h in the same file, so I do the typedef myself.
75 //typedef char* va_list;
80 * FILE should be used as a pointer to an opaque data type. Do not rely on
81 * anything else, especially the size or contents of this structure!
92 char *_name_to_remove;
97 //#define _fillsize _bufsiz
100 * The three standard file pointers provided by the run time library.
101 * NOTE: These will go to the bit-bucket silently in GUI applications!
103 extern FILE _iob[]; /* an array of FILE */
104 #define stdin (&_iob[0])
105 #define stdout (&_iob[1])
106 #define stderr (&_iob[2])
107 #define stdaux (&_iob[3])
108 #define stdprn (&_iob[4])
110 /* Returned by various functions on end of file condition or error. */
115 * The maximum length of a file name. You should use GetVolumeInformation
116 * instead of this constant. But hey, this works.
118 * NOTE: This is used in the structure _finddata_t (see dir.h) so changing it
119 * is probably not a good idea.
121 #define FILENAME_MAX (260)
124 * The maximum number of files that may be open at once. I have set this to
125 * a conservative number. The actual value may be higher.
127 #define FOPEN_MAX (20)
134 FILE* fopen (const char* szFileName, const char* szMode);
135 FILE* freopen (const char* szNewFileName, const char* szNewMode,
136 FILE* fileChangeAssociation);
137 int fflush (FILE* fileFlush);
138 int fclose (FILE* fileClose);
139 #define fcloseall _fcloseall
140 int remove (const char* szFileName);
141 int rename (const char* szOldFileName, const char* szNewFileName);
142 FILE* tmpfile (void);
144 int _filbuf(FILE *f);
145 int _flsbuf(int c, FILE *f);
146 void _fwalk(void (*func)(FILE *)); // not exported
147 int _fcloseall( void );
151 * The maximum size of name (including NUL) that will be put in the user
152 * supplied buffer caName.
153 * NOTE: This has not been determined by experiment, but based on the
154 * maximum file name length above it is probably reasonable. I could be
157 #define L_tmpnam (260)
159 char* tmpnam (char caName[]);
160 char* _tempnam (const char *szDir, const char *szPfx);
163 #define tempnam _tempnam
164 #endif /* Not _NO_OLDNAMES */
167 * The three possible buffering mode (nMode) values for setvbuf.
168 * NOTE: _IOFBF works, but _IOLBF seems to work like unbuffered...
169 * maybe I'm testing it wrong?
171 #define _IOFBF 0 /* fully buffered */
172 #define _IOLBF 1 /* line buffered */
173 #define _IONBF 2 /* unbuffered */
175 int setvbuf (FILE* fileSetBuffer, char* caBuffer, int nMode,
180 * The buffer size as used by setbuf such that it is equivalent to
181 * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ).
185 void setbuf (FILE* fileSetBuffer, char* caBuffer);
191 int _pclose (FILE* pipeClose);
192 FILE* _popen (const char* szPipeName, const char* szMode);
195 #define pclose _pclose
197 /* Wide character version */
198 FILE* _wpopen (const wchar_t* szPipeName, const wchar_t* szMode);
204 int fprintf (FILE* filePrintTo, const char* szFormat, ...);
205 int printf (const char* szFormat, ...);
206 int sprintf (char* caBuffer, const char* szFormat, ...);
207 int vfprintf (FILE* filePrintTo, const char* szFormat, va_list varg);
208 int vprintf (const char* szFormat, va_list varg);
209 int vsprintf (char* caBuffer, const char* szFormat, va_list varg);
211 /* Wide character versions */
212 int fwprintf (FILE* filePrintTo, const wchar_t* wsFormat, ...);
213 int wprintf (const wchar_t* wsFormat, ...);
214 int swprintf (wchar_t* wcaBuffer, const wchar_t* wsFormat, ...);
215 int vfwprintf (FILE* filePrintTo, const wchar_t* wsFormat, va_list varg);
216 int vwprintf (const wchar_t* wsFormat, va_list varg);
217 int vswprintf (wchar_t* wcaBuffer, const wchar_t* wsFormat, va_list varg);
223 int fscanf (FILE* fileReadFrom, const char* szFormat, ...);
224 int scanf (const char* szFormat, ...);
225 int sscanf (const char* szReadFrom, const char* szFormat, ...);
227 /* Wide character versions */
228 int fwscanf (FILE* fileReadFrom, const wchar_t* wsFormat, ...);
229 int wscanf (const wchar_t* wsFormat, ...);
230 int swscanf (const wchar_t* wsReadFrom, const wchar_t* wsFormat, ...);
233 * Character Input and Output Functions
236 int fgetc (FILE* fileRead);
237 char* fgets (char* caBuffer, int nBufferSize, FILE* fileRead);
238 int fputc (int c, FILE* fileWrite);
239 int fputs (const char* szOutput, FILE* fileWrite);
240 int getc (FILE* fileRead);
242 char* gets (char* caBuffer); /* Unsafe: how does gets know how long the
244 int putc (int c, FILE* fileWrite);
246 int puts (const char* szOutput);
247 int ungetc (int c, FILE* fileWasRead);
249 /* Wide character versions */
250 wint_t fgetwc (FILE* fileRead);
251 wint_t fputwc (wchar_t wc, FILE* fileWrite);
252 wint_t getwc(FILE *fileRead); // not exported
253 wint_t ungetwc (wchar_t wc, FILE* fileWasRead);
255 wint_t _filwbuf(FILE *f);
256 wint_t _flswbuf(wchar_t c, FILE *f);
259 * Not exported by CRTDLL.DLL included for reference purposes.
262 wchar_t* fgetws (wchar_t* wcaBuffer, int nBufferSize, FILE* fileRead);
263 int fputws (const wchar_t* wsOutput, FILE* fileWrite);
264 int getwc (FILE* fileRead);
266 wchar_t* getws (wchar_t* wcaBuffer);
267 int putwc (wchar_t wc, FILE* fileWrite);
268 int putws (const wchar_t* wsOutput);
271 /* NOTE: putchar has no wide char equivalent even in tchar.h */
275 * Direct Input and Output Functions
278 size_t fread (void* pBuffer, size_t sizeObject, size_t sizeObjCount,
280 size_t fwrite (const void* pObjArray, size_t sizeObject, size_t sizeObjCount,
285 * File Positioning Functions
288 /* Constants for nOrigin indicating the position relative to which fseek
289 * sets the file position. Enclosed in ifdefs because io.h could also
290 * define them. (Though not anymore since io.h includes this file now.) */
303 int fseek (FILE* fileSetPosition, long lnOffset, int nOrigin);
304 long ftell (FILE* fileGetPosition);
305 void rewind (FILE* fileRewind);
308 * An opaque data type used for storing file positions... The contents of
309 * this type are unknown, but we (the compiler) need to know the size
310 * because the programmer using fgetpos and fsetpos will be setting aside
311 * storage for fpos_t structres. Actually I tested using a byte array and
312 * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
313 * Perhaps an unsigned long? TODO?
317 int fgetpos (FILE* fileGetPosition, fpos_t* pfpos);
318 int fsetpos (FILE* fileSetPosition, const fpos_t* pfpos);
325 void clearerr (FILE* fileClearErrors);
326 int feof (FILE* fileIsAtEnd);
327 int ferror (FILE* fileIsError);
328 void perror (const char* szErrorMessage);
332 #define clearerr(f) (((f)->_flag) &= ~(_IOERR|_IOEOF))
333 #define feof(f) (((f)->_flag&_IOEOF)!=0)
334 #define ferror(f) (((f)->_flag&_IOERR)!=0)
335 #define perror(s) (fprintf(stderr, "%s: %s\n", (s), _strerror(NULL)))
340 #ifndef __STRICT_ANSI__
341 int _fgetchar (void);
342 int _fputchar (int c);
343 FILE* _fdopen (int nHandle, char* szMode);
346 #define fgetchar _fgetchar
347 #define fputchar _fputchar
348 #define fdopen _fdopen
349 #endif /* Not _NO_OLDNAMES */
351 #endif /* Not __STRICT_ANSI__ */
357 #endif /* _STDIO_H_ */