*** empty log message ***
[reactos.git] / reactos / include / crtdll / stdio.h
1 /*
2 * stdio.h
3 *
4 * Definitions of types and prototypes of functions for standard input and
5 * output.
6 *
7 * NOTE: The file manipulation functions provided by Microsoft seem to
8 * work with either slash (/) or backslash (\) as the path separator.
9 *
10 * This file is part of the Mingw32 package.
11 *
12 * Contributors:
13 * Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
14 *
15 * THIS SOFTWARE IS NOT COPYRIGHTED
16 *
17 * This source code is offered for use in the public domain. You may
18 * use, modify or distribute it freely.
19 *
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.
24 *
25 * $Revision: 1.6 $
26 * $Author: dwelch $
27 * $Date: 1999/04/14 00:46:22 $
28 *
29 */
30 /* Appropriated for Reactos Crtdll by Ariadne */
31 /* implemented clearerr feof ferror perror as macros */
32 /* added _IOCOMMIT */
33 /* added filbuf and flsbuf and fwalk */
34
35 #ifndef _STDIO_H_
36 #define _STDIO_H_
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 #define __need_size_t
43 #define __need_NULL
44 #define __need_wchar_t
45 #include <crtdll/stddef.h>
46
47
48 /* Some flags for the iobuf structure provided by djgpp stdio.h */
49 #define _IOREAD 000010
50 #define _IOWRT 000020
51 #define _IOMYBUF 000040
52 #define _IOEOF 000100
53 #define _IOERR 000200
54 #define _IOSTRG 000400
55 #define _IORW 001000
56 #define _IOAPPEND 002000
57 #define _IORMONCL 004000 /* remove on close, for temp files */
58 /* if _flag & _IORMONCL, ._name_to_remove needs freeing */
59 #define _IOUNGETC 010000 /* there is an ungetc'ed character in the buffer */
60 #define _IOCOMMIT 0x4000
61
62
63 /*
64 * I used to include stdarg.h at this point, in order to allow for the
65 * functions later on in the file which use va_list. That conflicts with
66 * using stdio.h and varargs.h in the same file, so I do the typedef myself.
67 */
68 //#ifndef _VA_LIST
69 //#define _VA_LIST
70 //typedef char* va_list;
71 //#endif
72 #include <stdarg.h>
73
74 /*
75 * FILE should be used as a pointer to an opaque data type. Do not rely on
76 * anything else, especially the size or contents of this structure!
77 */
78 #ifndef _FILE_DEFINED
79 typedef struct {
80 char *_ptr;
81 int _cnt;
82 char *_base;
83 int _flag;
84 int _file;
85 int _ungotchar;
86 int _bufsiz;
87 char *_name_to_remove;
88 } FILE;
89 #define _FILE_DEFINED
90 #endif
91
92
93 /*
94 * The three standard file pointers provided by the run time library.
95 * NOTE: These will go to the bit-bucket silently in GUI applications!
96 */
97 extern FILE (*_iob)[]; /* A pointer to an array of FILE */
98 #define stdin (&(*_iob)[0])
99 #define stdout (&(*_iob)[1])
100 #define stderr (&(*_iob)[2])
101 #define stdaux (&(*_iob)[3])
102 #define stdprn (&(*_iob)[4])
103
104 /* Returned by various functions on end of file condition or error. */
105 #define EOF (-1)
106
107
108 /*
109 * The maximum length of a file name. You should use GetVolumeInformation
110 * instead of this constant. But hey, this works.
111 *
112 * NOTE: This is used in the structure _finddata_t (see dir.h) so changing it
113 * is probably not a good idea.
114 */
115 #define FILENAME_MAX (260)
116
117 /*
118 * The maximum number of files that may be open at once. I have set this to
119 * a conservative number. The actual value may be higher.
120 */
121 #define FOPEN_MAX (20)
122
123
124 /*
125 * File Operations
126 */
127
128 FILE* fopen (const char* szFileName, const char* szMode);
129 FILE* freopen (const char* szNewFileName, const char* szNewMode,
130 FILE* fileChangeAssociation);
131 int fflush (FILE* fileFlush);
132 int fclose (FILE* fileClose);
133 #define fcloseall _fcloseall
134 int remove (const char* szFileName);
135 int rename (const char* szOldFileName, const char* szNewFileName);
136 FILE* tmpfile (void);
137
138 int _filbuf(FILE *f);
139 int _flsbuf(int c, FILE *f);
140 void _fwalk(void (*func)(FILE *)); // not exported
141 int _fcloseall( void );
142
143
144 /*
145 * The maximum size of name (including NUL) that will be put in the user
146 * supplied buffer caName.
147 * NOTE: This has not been determined by experiment, but based on the
148 * maximum file name length above it is probably reasonable. I could be
149 * wrong...
150 */
151 #define L_tmpnam (260)
152
153 char* tmpnam (char caName[]);
154 char* _tempnam (const char *szDir, const char *szPfx);
155
156 #ifndef _NO_OLDNAMES
157 #define tempnam _tempnam
158 #endif /* Not _NO_OLDNAMES */
159
160 /*
161 * The three possible buffering mode (nMode) values for setvbuf.
162 * NOTE: _IOFBF works, but _IOLBF seems to work like unbuffered...
163 * maybe I'm testing it wrong?
164 */
165 #define _IOFBF 0 /* fully buffered */
166 #define _IOLBF 1 /* line buffered */
167 #define _IONBF 2 /* unbuffered */
168
169 int setvbuf (FILE* fileSetBuffer, char* caBuffer, int nMode,
170 size_t sizeBuffer);
171
172
173 /*
174 * The buffer size as used by setbuf such that it is equivalent to
175 * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ).
176 */
177 #define BUFSIZ 512
178
179 void setbuf (FILE* fileSetBuffer, char* caBuffer);
180
181 /*
182 * Pipe Operations
183 */
184
185 int _pclose (FILE* pipeClose);
186 FILE* _popen (const char* szPipeName, const char* szMode);
187
188 #define popen _popen
189 #define pclose _pclose
190
191 /* Wide character version */
192 FILE* _wpopen (const wchar_t* szPipeName, const wchar_t* szMode);
193
194 /*
195 * Formatted Output
196 */
197
198 int fprintf (FILE* filePrintTo, const char* szFormat, ...);
199 int printf (const char* szFormat, ...);
200 int sprintf (char* caBuffer, const char* szFormat, ...);
201 int vfprintf (FILE* filePrintTo, const char* szFormat, va_list varg);
202 int vprintf (const char* szFormat, va_list varg);
203 int vsprintf (char* caBuffer, const char* szFormat, va_list varg);
204
205 /* Wide character versions */
206 int fwprintf (FILE* filePrintTo, const wchar_t* wsFormat, ...);
207 int wprintf (const wchar_t* wsFormat, ...);
208 int swprintf (wchar_t* wcaBuffer, const wchar_t* wsFormat, ...);
209 int vfwprintf (FILE* filePrintTo, const wchar_t* wsFormat, va_list varg);
210 int vwprintf (const wchar_t* wsFormat, va_list varg);
211 int vswprintf (wchar_t* wcaBuffer, const wchar_t* wsFormat, va_list varg);
212
213 /*
214 * Formatted Input
215 */
216
217 int fscanf (FILE* fileReadFrom, const char* szFormat, ...);
218 int scanf (const char* szFormat, ...);
219 int sscanf (const char* szReadFrom, const char* szFormat, ...);
220
221 /* Wide character versions */
222 int fwscanf (FILE* fileReadFrom, const wchar_t* wsFormat, ...);
223 int wscanf (const wchar_t* wsFormat, ...);
224 int swscanf (const wchar_t* wsReadFrom, const wchar_t* wsFormat, ...);
225
226 /*
227 * Character Input and Output Functions
228 */
229
230 int fgetc (FILE* fileRead);
231 char* fgets (char* caBuffer, int nBufferSize, FILE* fileRead);
232 int fputc (int c, FILE* fileWrite);
233 int fputs (const char* szOutput, FILE* fileWrite);
234 int getc (FILE* fileRead);
235 int getchar (void);
236 char* gets (char* caBuffer); /* Unsafe: how does gets know how long the
237 * buffer is? */
238 int putc (int c, FILE* fileWrite);
239 int putchar (int c);
240 int puts (const char* szOutput);
241 int ungetc (int c, FILE* fileWasRead);
242
243 /* Wide character versions */
244 int fgetwc (FILE* fileRead);
245 int fputwc (wchar_t wc, FILE* fileWrite);
246 int ungetwc (wchar_t wc, FILE* fileWasRead);
247
248 /*
249 * Not exported by CRTDLL.DLL included for reference purposes.
250 */
251 #if 0
252 wchar_t* fgetws (wchar_t* wcaBuffer, int nBufferSize, FILE* fileRead);
253 int fputws (const wchar_t* wsOutput, FILE* fileWrite);
254 int getwc (FILE* fileRead);
255 int getwchar ();
256 wchar_t* getws (wchar_t* wcaBuffer);
257 int putwc (wchar_t wc, FILE* fileWrite);
258 int putws (const wchar_t* wsOutput);
259 #endif /* 0 */
260
261 /* NOTE: putchar has no wide char equivalent even in tchar.h */
262
263
264 /*
265 * Direct Input and Output Functions
266 */
267
268 size_t fread (void* pBuffer, size_t sizeObject, size_t sizeObjCount,
269 FILE* fileRead);
270 size_t fwrite (const void* pObjArray, size_t sizeObject, size_t sizeObjCount,
271 FILE* fileWrite);
272
273
274 /*
275 * File Positioning Functions
276 */
277
278 /* Constants for nOrigin indicating the position relative to which fseek
279 * sets the file position. Enclosed in ifdefs because io.h could also
280 * define them. (Though not anymore since io.h includes this file now.) */
281 #ifndef SEEK_SET
282 #define SEEK_SET (0)
283 #endif
284
285 #ifndef SEEK_CUR
286 #define SEEK_CUR (1)
287 #endif
288
289 #ifndef SEEK_END
290 #define SEEK_END (2)
291 #endif
292
293 int fseek (FILE* fileSetPosition, long lnOffset, int nOrigin);
294 long ftell (FILE* fileGetPosition);
295 void rewind (FILE* fileRewind);
296
297 /*
298 * An opaque data type used for storing file positions... The contents of
299 * this type are unknown, but we (the compiler) need to know the size
300 * because the programmer using fgetpos and fsetpos will be setting aside
301 * storage for fpos_t structres. Actually I tested using a byte array and
302 * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
303 * Perhaps an unsigned long? TODO?
304 */
305 typedef long fpos_t;
306
307 int fgetpos (FILE* fileGetPosition, fpos_t* pfpos);
308 int fsetpos (FILE* fileSetPosition, const fpos_t* pfpos);
309
310
311 /*
312 * Error Functions
313 */
314 #if 0
315 void clearerr (FILE* fileClearErrors);
316 int feof (FILE* fileIsAtEnd);
317 int ferror (FILE* fileIsError);
318 void perror (const char* szErrorMessage);
319
320 #endif
321
322 #define clearerr(f) (((f)->_flag) &= ~(_IOERR|_IOEOF))
323 #define feof(f) (((f)->_flag&_IOEOF)!=0)
324 #define ferror(f) (((f)->_flag&_IOERR)!=0)
325 #define perror(s) (fprintf(stderr, "%s: %s\n", (s), _strerror(NULL)))
326 /*
327 * Non ANSI functions
328 */
329
330 #ifndef __STRICT_ANSI__
331 int _fgetchar (void);
332 int _fputchar (int c);
333 FILE* _fdopen (int nHandle, char* szMode);
334
335 #ifndef _NO_OLDNAMES
336 #define fgetchar _fgetchar
337 #define fputchar _fputchar
338 #define fdopen _fdopen
339 #endif /* Not _NO_OLDNAMES */
340
341 #endif /* Not __STRICT_ANSI__ */
342
343 #ifdef __cplusplus
344 }
345 #endif
346
347 #endif /* _STDIO_H_ */