Visual C++ backend for rbuild (for now just a hacked mingw backend) and related compi...
[reactos.git] / include / crt / io.h
1 /*
2 * io.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.
6 *
7 * System level I/O functions and types.
8 *
9 */
10 #ifndef _IO_H_
11 #define _IO_H_
12
13 /* All the headers include this file. */
14 #include <_mingw.h>
15
16 /* MSVC's io.h contains the stuff from dir.h, so I will too.
17 * NOTE: This also defines off_t, the file offset type, through
18 * an inclusion of sys/types.h */
19
20 #include <sys/types.h> /* To get time_t. */
21
22 /*
23 * Attributes of files as returned by _findfirst et al.
24 */
25 #define _A_NORMAL 0x00000000
26 #define _A_RDONLY 0x00000001
27 #define _A_HIDDEN 0x00000002
28 #define _A_SYSTEM 0x00000004
29 #define _A_VOLID 0x00000008
30 #define _A_SUBDIR 0x00000010
31 #define _A_ARCH 0x00000020
32
33
34 #ifndef RC_INVOKED
35
36 #ifndef _INTPTR_T_DEFINED
37 #define _INTPTR_T_DEFINED
38 #ifdef _WIN64
39 typedef __int64 intptr_t;
40 #else
41 typedef int intptr_t;
42 #endif
43 #endif
44
45 #ifndef _FSIZE_T_DEFINED
46 typedef unsigned long _fsize_t;
47 #define _FSIZE_T_DEFINED
48 #endif
49
50 /*
51 * The maximum length of a file name. You should use GetVolumeInformation
52 * instead of this constant. But hey, this works.
53 * Also defined in stdio.h.
54 */
55 #ifndef FILENAME_MAX
56 #define FILENAME_MAX (260)
57 #endif
58
59 /*
60 * The following structure is filled in by _findfirst or _findnext when
61 * they succeed in finding a match.
62 */
63 struct _finddata_t
64 {
65 unsigned attrib; /* Attributes, see constants above. */
66 time_t time_create;
67 time_t time_access; /* always midnight local time */
68 time_t time_write;
69 _fsize_t size;
70 char name[FILENAME_MAX]; /* may include spaces. */
71 };
72
73 struct _finddatai64_t {
74 unsigned attrib;
75 time_t time_create;
76 time_t time_access;
77 time_t time_write;
78 __int64 size;
79 char name[FILENAME_MAX];
80 };
81
82 struct __finddata64_t {
83 unsigned attrib;
84 __time64_t time_create;
85 __time64_t time_access;
86 __time64_t time_write;
87 _fsize_t size;
88 char name[FILENAME_MAX];
89 };
90
91 #ifndef _WFINDDATA_T_DEFINED
92 struct _wfinddata_t {
93 unsigned attrib;
94 time_t time_create; /* -1 for FAT file systems */
95 time_t time_access; /* -1 for FAT file systems */
96 time_t time_write;
97 _fsize_t size;
98 wchar_t name[FILENAME_MAX]; /* may include spaces. */
99 };
100
101 struct _wfinddatai64_t {
102 unsigned attrib;
103 time_t time_create;
104 time_t time_access;
105 time_t time_write;
106 __int64 size;
107 wchar_t name[FILENAME_MAX];
108 };
109
110 struct __wfinddata64_t {
111 unsigned attrib;
112 __time64_t time_create;
113 __time64_t time_access;
114 __time64_t time_write;
115 _fsize_t size;
116 wchar_t name[FILENAME_MAX];
117 };
118
119 #define _WFINDDATA_T_DEFINED
120 #endif
121
122 #ifdef __cplusplus
123 extern "C" {
124 #endif
125
126 /*
127 * Functions for searching for files. _findfirst returns -1 if no match
128 * is found. Otherwise it returns a handle to be used in _findnext and
129 * _findclose calls. _findnext also returns -1 if no match could be found,
130 * and 0 if a match was found. Call _findclose when you are finished.
131 */
132
133 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _findfirst (const char*, struct _finddata_t*);
134 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _findnext (intptr_t, struct _finddata_t*);
135 _CRTIMP int __cdecl __MINGW_NOTHROW _findclose (intptr_t);
136
137 _CRTIMP int __cdecl __MINGW_NOTHROW _chdir (const char*);
138 _CRTIMP char* __cdecl __MINGW_NOTHROW _getcwd (char*, int);
139 _CRTIMP int __cdecl __MINGW_NOTHROW _mkdir (const char*);
140 _CRTIMP char* __cdecl __MINGW_NOTHROW _mktemp (char*);
141 _CRTIMP int __cdecl __MINGW_NOTHROW _rmdir (const char*);
142 _CRTIMP int __cdecl __MINGW_NOTHROW _chmod (const char*, int);
143
144 #ifdef __MSVCRT__
145 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _filelengthi64(int);
146 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _findfirsti64(const char*, struct _finddatai64_t*);
147 _CRTIMP int __cdecl __MINGW_NOTHROW _findnexti64(intptr_t, struct _finddatai64_t*);
148 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _lseeki64(int, __int64, int);
149 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _telli64(int);
150 /* These require newer versions of msvcrt.dll (6.1 or higher). */
151 #if __MSVCRT_VERSION__ >= 0x0601
152 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _findfirst64(const char*, struct __finddata64_t*);
153 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _findnext64(intptr_t, struct __finddata64_t*);
154 #endif /* __MSVCRT_VERSION__ >= 0x0601 */
155
156 #ifndef __NO_MINGW_LFS
157 __CRT_INLINE off64_t lseek64 (int, off64_t, int);
158 __CRT_INLINE off64_t lseek64 (int fd, off64_t offset, int whence)
159 {
160 return _lseeki64(fd, (__int64) offset, whence);
161 }
162 #endif
163
164 #endif /* __MSVCRT__ */
165
166 #ifndef _NO_OLDNAMES
167
168 #ifndef _UWIN
169 _CRTIMP int __cdecl __MINGW_NOTHROW chdir (const char*);
170 _CRTIMP char* __cdecl __MINGW_NOTHROW getcwd (char*, int);
171 _CRTIMP int __cdecl __MINGW_NOTHROW mkdir (const char*);
172 _CRTIMP char* __cdecl __MINGW_NOTHROW mktemp (char*);
173 _CRTIMP int __cdecl __MINGW_NOTHROW rmdir (const char*);
174 _CRTIMP int __cdecl __MINGW_NOTHROW chmod (const char*, int);
175 #endif /* _UWIN */
176
177 #endif /* Not _NO_OLDNAMES */
178
179 #ifdef __cplusplus
180 }
181 #endif
182
183 #endif /* Not RC_INVOKED */
184
185 /* TODO: Maximum number of open handles has not been tested, I just set
186 * it the same as FOPEN_MAX. */
187 #define HANDLE_MAX FOPEN_MAX
188
189 /* Some defines for _access nAccessMode (MS doesn't define them, but
190 * it doesn't seem to hurt to add them). */
191 #define F_OK 0 /* Check for file existence */
192 /* Well maybe it does hurt. On newer versions of MSVCRT, an access mode
193 of 1 causes invalid parameter error. */
194 #define X_OK 1 /* MS access() doesn't check for execute permission. */
195 #define W_OK 2 /* Check for write permission */
196 #define R_OK 4 /* Check for read permission */
197
198 #ifndef RC_INVOKED
199
200 #ifdef __cplusplus
201 extern "C" {
202 #endif
203
204 _CRTIMP int __cdecl __MINGW_NOTHROW _access (const char*, int);
205 _CRTIMP int __cdecl __MINGW_NOTHROW _chsize (int, long);
206 _CRTIMP int __cdecl __MINGW_NOTHROW _close (int);
207 _CRTIMP int __cdecl __MINGW_NOTHROW _commit(int);
208
209 /* NOTE: The only significant bit in unPermissions appears to be bit 7 (0x80),
210 * the "owner write permission" bit (on FAT). */
211 _CRTIMP int __cdecl __MINGW_NOTHROW _creat (const char*, int);
212
213 _CRTIMP int __cdecl __MINGW_NOTHROW _dup (int);
214 _CRTIMP int __cdecl __MINGW_NOTHROW _dup2 (int, int);
215 _CRTIMP long __cdecl __MINGW_NOTHROW _filelength (int);
216 _CRTIMP long __cdecl __MINGW_NOTHROW _get_osfhandle (int);
217 _CRTIMP int __cdecl __MINGW_NOTHROW _isatty (int);
218
219 /* In a very odd turn of events this function is excluded from those
220 * files which define _STREAM_COMPAT. This is required in order to
221 * build GNU libio because of a conflict with _eof in streambuf.h
222 * line 107. Actually I might just be able to change the name of
223 * the enum member in streambuf.h... we'll see. TODO */
224 #ifndef _STREAM_COMPAT
225 _CRTIMP int __cdecl __MINGW_NOTHROW _eof (int);
226 #endif
227
228 /* LK_... locking commands defined in sys/locking.h. */
229 _CRTIMP int __cdecl __MINGW_NOTHROW _locking (int, int, long);
230
231 _CRTIMP long __cdecl __MINGW_NOTHROW _lseek (int, long, int);
232
233 /* Optional third argument is unsigned unPermissions. */
234 _CRTIMP int __cdecl __MINGW_NOTHROW _open (const char*, int, ...);
235
236 _CRTIMP int __cdecl __MINGW_NOTHROW _open_osfhandle (long, int);
237 _CRTIMP int __cdecl __MINGW_NOTHROW _pipe (int *, unsigned int, int);
238 _CRTIMP int __cdecl __MINGW_NOTHROW _read (int, void*, unsigned int);
239 _CRTIMP int __cdecl __MINGW_NOTHROW _setmode (int, int);
240 /* MS puts remove & rename (but not wide versions) in io.h as well
241 as in stdio.h. */
242 _CRTIMP int __cdecl __MINGW_NOTHROW remove (const char*);
243 _CRTIMP int __cdecl __MINGW_NOTHROW rename (const char*, const char*);
244
245 /* SH_... flags for nShFlags defined in share.h
246 * Optional fourth argument is unsigned unPermissions */
247 _CRTIMP int __cdecl __MINGW_NOTHROW _sopen (const char*, int, int, ...);
248
249 _CRTIMP long __cdecl __MINGW_NOTHROW _tell (int);
250 /* Should umask be in sys/stat.h and/or sys/types.h instead? */
251 _CRTIMP int __cdecl __MINGW_NOTHROW _umask (int);
252 _CRTIMP int __cdecl __MINGW_NOTHROW _unlink (const char*);
253 _CRTIMP int __cdecl __MINGW_NOTHROW _write (int, const void*, unsigned int);
254
255 /* Wide character versions. Also declared in wchar.h. */
256 /* Not in crtdll.dll */
257 #if !defined (_WIO_DEFINED)
258 #if defined (__MSVCRT__)
259 _CRTIMP int __cdecl __MINGW_NOTHROW _waccess(const wchar_t*, int);
260 _CRTIMP int __cdecl __MINGW_NOTHROW _wchmod(const wchar_t*, int);
261 _CRTIMP int __cdecl __MINGW_NOTHROW _wcreat(const wchar_t*, int);
262 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wfindfirst(const wchar_t*, struct _wfinddata_t*);
263 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wfindnext(intptr_t, struct _wfinddata_t *);
264 _CRTIMP int __cdecl __MINGW_NOTHROW _wunlink(const wchar_t*);
265 _CRTIMP int __cdecl __MINGW_NOTHROW _wopen(const wchar_t*, int, ...);
266 _CRTIMP int __cdecl __MINGW_NOTHROW _wsopen(const wchar_t*, int, int, ...);
267 _CRTIMP wchar_t * __cdecl __MINGW_NOTHROW _wmktemp(wchar_t*);
268 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wfindfirsti64(const wchar_t*, struct _wfinddatai64_t*);
269 _CRTIMP int __cdecl __MINGW_NOTHROW _wfindnexti64(intptr_t, struct _wfinddatai64_t*);
270 #if __MSVCRT_VERSION__ >= 0x0601
271 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wfindfirst64(const wchar_t*, struct __wfinddata64_t*);
272 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wfindnext64(intptr_t, struct __wfinddata64_t*);
273 #endif
274 #endif /* defined (__MSVCRT__) */
275 #define _WIO_DEFINED
276 #endif /* _WIO_DEFINED */
277
278 #ifndef _NO_OLDNAMES
279 /*
280 * Non-underscored versions of non-ANSI functions to improve portability.
281 * These functions live in libmoldname.a.
282 */
283
284 #ifndef _UWIN
285 _CRTIMP int __cdecl __MINGW_NOTHROW access (const char*, int);
286 _CRTIMP int __cdecl __MINGW_NOTHROW chsize (int, long );
287 _CRTIMP int __cdecl __MINGW_NOTHROW close (int);
288 _CRTIMP int __cdecl __MINGW_NOTHROW creat (const char*, int);
289 _CRTIMP int __cdecl __MINGW_NOTHROW dup (int);
290 _CRTIMP int __cdecl __MINGW_NOTHROW dup2 (int, int);
291 _CRTIMP int __cdecl __MINGW_NOTHROW eof (int);
292 _CRTIMP long __cdecl __MINGW_NOTHROW filelength (int);
293 _CRTIMP int __cdecl __MINGW_NOTHROW isatty (int);
294 _CRTIMP long __cdecl __MINGW_NOTHROW lseek (int, long, int);
295 _CRTIMP int __cdecl __MINGW_NOTHROW open (const char*, int, ...);
296 _CRTIMP int __cdecl __MINGW_NOTHROW read (int, void*, unsigned int);
297 _CRTIMP int __cdecl __MINGW_NOTHROW setmode (int, int);
298 _CRTIMP int __cdecl __MINGW_NOTHROW sopen (const char*, int, int, ...);
299 _CRTIMP long __cdecl __MINGW_NOTHROW tell (int);
300 _CRTIMP int __cdecl __MINGW_NOTHROW umask (int);
301 _CRTIMP int __cdecl __MINGW_NOTHROW unlink (const char*);
302 _CRTIMP int __cdecl __MINGW_NOTHROW write (int, const void*, unsigned int);
303 #endif /* _UWIN */
304
305 #ifdef __USE_MINGW_ACCESS
306 /* Old versions of MSVCRT access() just ignored X_OK, while the version
307 shipped with Vista, returns an error code. This will restore the
308 old behaviour */
309 static inline int __mingw_access (const char* __fname, int __mode)
310 { return _access (__fname, __mode & ~X_OK); }
311 #define access(__f,__m) __mingw_access (__f, __m)
312 #endif
313
314 /* Wide character versions. Also declared in wchar.h. */
315 /* Where do these live? Not in libmoldname.a nor in libmsvcrt.a */
316 #if 0
317 int waccess(const wchar_t *, int);
318 int wchmod(const wchar_t *, int);
319 int wcreat(const wchar_t *, int);
320 long wfindfirst(wchar_t *, struct _wfinddata_t *);
321 int wfindnext(long, struct _wfinddata_t *);
322 int wunlink(const wchar_t *);
323 int wrename(const wchar_t *, const wchar_t *);
324 int wopen(const wchar_t *, int, ...);
325 int wsopen(const wchar_t *, int, int, ...);
326 wchar_t * wmktemp(wchar_t *);
327 #endif
328
329 #endif /* Not _NO_OLDNAMES */
330
331 #ifdef __cplusplus
332 }
333 #endif
334
335 #endif /* Not RC_INVOKED */
336
337 #endif /* _IO_H_ not defined */