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