|
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 #if __MSVCRT_VERSION__ >= 0x0601 |
|
83 struct __finddata64_t { |
|
84 unsigned attrib; |
|
85 __time64_t time_create; |
|
86 __time64_t time_access; |
|
87 __time64_t time_write; |
|
88 /* 8 bytes are returned so it can't be _fsize_t */ |
|
89 __int64 size; |
|
90 char name[FILENAME_MAX]; |
|
91 }; |
|
92 #endif |
|
93 |
|
94 #ifndef _WFINDDATA_T_DEFINED |
|
95 struct _wfinddata_t { |
|
96 unsigned attrib; |
|
97 time_t time_create; /* -1 for FAT file systems */ |
|
98 time_t time_access; /* -1 for FAT file systems */ |
|
99 time_t time_write; |
|
100 _fsize_t size; |
|
101 wchar_t name[FILENAME_MAX]; /* may include spaces. */ |
|
102 }; |
|
103 |
|
104 struct _wfinddatai64_t { |
|
105 unsigned attrib; |
|
106 time_t time_create; |
|
107 time_t time_access; |
|
108 time_t time_write; |
|
109 __int64 size; |
|
110 wchar_t name[FILENAME_MAX]; |
|
111 }; |
|
112 |
|
113 #if __MSVCRT_VERSION__ >= 0x0601 |
|
114 struct __wfinddata64_t { |
|
115 unsigned attrib; |
|
116 __time64_t time_create; |
|
117 __time64_t time_access; |
|
118 __time64_t time_write; |
|
119 /* 8 bytes are returned so it can't be _fsize_t */ |
|
120 __int64 size; |
|
121 wchar_t name[FILENAME_MAX]; |
|
122 }; |
|
123 #endif |
|
124 |
|
125 #define _WFINDDATA_T_DEFINED |
|
126 #endif |
|
127 |
|
128 #ifdef __cplusplus |
|
129 extern "C" { |
|
130 #endif |
|
131 |
|
132 /* |
|
133 * Functions for searching for files. _findfirst returns -1 if no match |
|
134 * is found. Otherwise it returns a handle to be used in _findnext and |
|
135 * _findclose calls. _findnext also returns -1 if no match could be found, |
|
136 * and 0 if a match was found. Call _findclose when you are finished. |
|
137 */ |
|
138 /* FIXME: Should these all use intptr_t, as per recent MSDN docs? */ |
|
139 _CRTIMP long __cdecl __MINGW_NOTHROW _findfirst (const char*, struct _finddata_t*); |
|
140 _CRTIMP int __cdecl __MINGW_NOTHROW _findnext (long, struct _finddata_t*); |
|
141 _CRTIMP int __cdecl __MINGW_NOTHROW _findclose (long); |
|
142 |
|
143 _CRTIMP int __cdecl __MINGW_NOTHROW _chdir (const char*); |
|
144 _CRTIMP char* __cdecl __MINGW_NOTHROW _getcwd (char*, int); |
|
145 _CRTIMP int __cdecl __MINGW_NOTHROW _mkdir (const char*); |
|
146 _CRTIMP char* __cdecl __MINGW_NOTHROW _mktemp (char*); |
|
147 _CRTIMP int __cdecl __MINGW_NOTHROW _rmdir (const char*); |
|
148 _CRTIMP int __cdecl __MINGW_NOTHROW _chmod (const char*, int); |
|
149 |
|
150 #ifdef __MSVCRT__ |
|
151 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _filelengthi64(int); |
|
152 _CRTIMP long __cdecl __MINGW_NOTHROW _findfirsti64(const char*, struct _finddatai64_t*); |
|
153 _CRTIMP int __cdecl __MINGW_NOTHROW _findnexti64(long, struct _finddatai64_t*); |
|
154 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _lseeki64(int, __int64, int); |
|
155 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _telli64(int); |
|
156 /* These require newer versions of msvcrt.dll (6.1 or higher). */ |
|
157 #if __MSVCRT_VERSION__ >= 0x0601 |
|
158 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _findfirst64(const char*, struct __finddata64_t*); |
|
159 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _findnext64(intptr_t, struct __finddata64_t*); |
|
160 #endif /* __MSVCRT_VERSION__ >= 0x0601 */ |
|
161 #ifndef __NO_MINGW_LFS |
|
162 __CRT_INLINE off64_t lseek64 (int, off64_t, int); |
|
163 __CRT_INLINE off64_t lseek64 (int fd, off64_t offset, int whence) |
|
164 { |
|
165 return _lseeki64(fd, (__int64) offset, whence); |
|
166 } |
|
167 #endif |
|
168 |
|
169 #endif /* __MSVCRT__ */ |
|
170 |
|
171 #ifndef _NO_OLDNAMES |
|
172 |
|
173 #ifndef _UWIN |
|
174 _CRTIMP int __cdecl __MINGW_NOTHROW chdir (const char*); |
|
175 _CRTIMP char* __cdecl __MINGW_NOTHROW getcwd (char*, int); |
|
176 _CRTIMP int __cdecl __MINGW_NOTHROW mkdir (const char*); |
|
177 _CRTIMP char* __cdecl __MINGW_NOTHROW mktemp (char*); |
|
178 _CRTIMP int __cdecl __MINGW_NOTHROW rmdir (const char*); |
|
179 _CRTIMP int __cdecl __MINGW_NOTHROW chmod (const char*, int); |
|
180 #endif /* _UWIN */ |
|
181 |
|
182 #endif /* Not _NO_OLDNAMES */ |
|
183 |
|
184 #ifdef __cplusplus |
|
185 } |
|
186 #endif |
|
187 |
|
188 #endif /* Not RC_INVOKED */ |
|
189 |
|
190 /* TODO: Maximum number of open handles has not been tested, I just set |
|
191 * it the same as FOPEN_MAX. */ |
|
192 #define HANDLE_MAX FOPEN_MAX |
|
193 |
|
194 /* Some defines for _access nAccessMode (MS doesn't define them, but |
|
195 * it doesn't seem to hurt to add them). */ |
|
196 #define F_OK 0 /* Check for file existence */ |
|
197 /* Well maybe it does hurt. On newer versions of MSVCRT, an access mode |
|
198 of 1 causes invalid parameter error. */ |
|
199 #define X_OK 1 /* MS access() doesn't check for execute permission. */ |
|
200 #define W_OK 2 /* Check for write permission */ |
|
201 #define R_OK 4 /* Check for read permission */ |
|
202 |
|
203 #ifndef RC_INVOKED |
|
204 |
|
205 #ifdef __cplusplus |
|
206 extern "C" { |
|
207 #endif |
|
208 |
|
209 _CRTIMP int __cdecl __MINGW_NOTHROW _access (const char*, int); |
|
210 _CRTIMP int __cdecl __MINGW_NOTHROW _chsize (int, long); |
|
211 _CRTIMP int __cdecl __MINGW_NOTHROW _close (int); |
|
212 _CRTIMP int __cdecl __MINGW_NOTHROW _commit(int); |
|
213 |
|
214 /* NOTE: The only significant bit in unPermissions appears to be bit 7 (0x80), |
|
215 * the "owner write permission" bit (on FAT). */ |
|
216 _CRTIMP int __cdecl __MINGW_NOTHROW _creat (const char*, int); |
|
217 |
|
218 _CRTIMP int __cdecl __MINGW_NOTHROW _dup (int); |
|
219 _CRTIMP int __cdecl __MINGW_NOTHROW _dup2 (int, int); |
|
220 _CRTIMP long __cdecl __MINGW_NOTHROW _filelength (int); |
|
221 _CRTIMP long __cdecl __MINGW_NOTHROW _get_osfhandle (int); |
|
222 _CRTIMP int __cdecl __MINGW_NOTHROW _isatty (int); |
|
223 |
|
224 /* In a very odd turn of events this function is excluded from those |
|
225 * files which define _STREAM_COMPAT. This is required in order to |
|
226 * build GNU libio because of a conflict with _eof in streambuf.h |
|
227 * line 107. Actually I might just be able to change the name of |
|
228 * the enum member in streambuf.h... we'll see. TODO */ |
|
229 #ifndef _STREAM_COMPAT |
|
230 _CRTIMP int __cdecl __MINGW_NOTHROW _eof (int); |
|
231 #endif |
|
232 |
|
233 /* LK_... locking commands defined in sys/locking.h. */ |
|
234 _CRTIMP int __cdecl __MINGW_NOTHROW _locking (int, int, long); |
|
235 |
|
236 _CRTIMP long __cdecl __MINGW_NOTHROW _lseek (int, long, int); |
|
237 |
|
238 /* Optional third argument is unsigned unPermissions. */ |
|
239 _CRTIMP int __cdecl __MINGW_NOTHROW _open (const char*, int, ...); |
|
240 |
|
241 _CRTIMP int __cdecl __MINGW_NOTHROW _open_osfhandle (long, int); |
|
242 _CRTIMP int __cdecl __MINGW_NOTHROW _pipe (int *, unsigned int, int); |
|
243 _CRTIMP int __cdecl __MINGW_NOTHROW _read (int, void*, unsigned int); |
|
244 _CRTIMP int __cdecl __MINGW_NOTHROW _setmode (int, int); |
|
245 /* MS puts remove & rename (but not wide versions) in io.h as well |
|
246 as in stdio.h. */ |
|
247 _CRTIMP int __cdecl __MINGW_NOTHROW remove (const char*); |
|
248 _CRTIMP int __cdecl __MINGW_NOTHROW rename (const char*, const char*); |
|
249 |
|
250 /* SH_... flags for nShFlags defined in share.h |
|
251 * Optional fourth argument is unsigned unPermissions */ |
|
252 _CRTIMP int __cdecl __MINGW_NOTHROW _sopen (const char*, int, int, ...); |
|
253 |
|
254 _CRTIMP long __cdecl __MINGW_NOTHROW _tell (int); |
|
255 /* Should umask be in sys/stat.h and/or sys/types.h instead? */ |
|
256 _CRTIMP int __cdecl __MINGW_NOTHROW _umask (int); |
|
257 _CRTIMP int __cdecl __MINGW_NOTHROW _unlink (const char*); |
|
258 _CRTIMP int __cdecl __MINGW_NOTHROW _write (int, const void*, unsigned int); |
|
259 |
|
260 /* Wide character versions. Also declared in wchar.h. */ |
|
261 /* Not in crtdll.dll */ |
|
262 #if !defined (_WIO_DEFINED) |
|
263 #if defined (__MSVCRT__) |
|
264 _CRTIMP int __cdecl __MINGW_NOTHROW _waccess(const wchar_t*, int); |
|
265 _CRTIMP int __cdecl __MINGW_NOTHROW _wchmod(const wchar_t*, int); |
|
266 _CRTIMP int __cdecl __MINGW_NOTHROW _wcreat(const wchar_t*, int); |
|
267 _CRTIMP long __cdecl __MINGW_NOTHROW _wfindfirst(const wchar_t*, struct _wfinddata_t*); |
|
268 _CRTIMP int __cdecl __MINGW_NOTHROW _wfindnext(long, struct _wfinddata_t *); |
|
269 _CRTIMP int __cdecl __MINGW_NOTHROW _wunlink(const wchar_t*); |
|
270 _CRTIMP int __cdecl __MINGW_NOTHROW _wopen(const wchar_t*, int, ...); |
|
271 _CRTIMP int __cdecl __MINGW_NOTHROW _wsopen(const wchar_t*, int, int, ...); |
|
272 _CRTIMP wchar_t * __cdecl __MINGW_NOTHROW _wmktemp(wchar_t*); |
|
273 _CRTIMP long __cdecl __MINGW_NOTHROW _wfindfirsti64(const wchar_t*, struct _wfinddatai64_t*); |
|
274 _CRTIMP int __cdecl __MINGW_NOTHROW _wfindnexti64(long, struct _wfinddatai64_t*); |
|
275 #if __MSVCRT_VERSION__ >= 0x0601 |
|
276 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wfindfirst64(const wchar_t*, struct __wfinddata64_t*); |
|
277 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wfindnext64(intptr_t, struct __wfinddata64_t*); |
|
278 #endif |
|
279 #endif /* defined (__MSVCRT__) */ |
|
280 #define _WIO_DEFINED |
|
281 #endif /* _WIO_DEFINED */ |
|
282 |
|
283 #ifndef _NO_OLDNAMES |
|
284 /* |
|
285 * Non-underscored versions of non-ANSI functions to improve portability. |
|
286 * These functions live in libmoldname.a. |
|
287 */ |
|
288 |
|
289 #ifndef _UWIN |
|
290 _CRTIMP int __cdecl __MINGW_NOTHROW access (const char*, int); |
|
291 _CRTIMP int __cdecl __MINGW_NOTHROW chsize (int, long ); |
|
292 _CRTIMP int __cdecl __MINGW_NOTHROW close (int); |
|
293 _CRTIMP int __cdecl __MINGW_NOTHROW creat (const char*, int); |
|
294 _CRTIMP int __cdecl __MINGW_NOTHROW dup (int); |
|
295 _CRTIMP int __cdecl __MINGW_NOTHROW dup2 (int, int); |
|
296 _CRTIMP int __cdecl __MINGW_NOTHROW eof (int); |
|
297 _CRTIMP long __cdecl __MINGW_NOTHROW filelength (int); |
|
298 _CRTIMP int __cdecl __MINGW_NOTHROW isatty (int); |
|
299 _CRTIMP long __cdecl __MINGW_NOTHROW lseek (int, long, int); |
|
300 _CRTIMP int __cdecl __MINGW_NOTHROW open (const char*, int, ...); |
|
301 _CRTIMP int __cdecl __MINGW_NOTHROW read (int, void*, unsigned int); |
|
302 _CRTIMP int __cdecl __MINGW_NOTHROW setmode (int, int); |
|
303 _CRTIMP int __cdecl __MINGW_NOTHROW sopen (const char*, int, int, ...); |
|
304 _CRTIMP long __cdecl __MINGW_NOTHROW tell (int); |
|
305 _CRTIMP int __cdecl __MINGW_NOTHROW umask (int); |
|
306 _CRTIMP int __cdecl __MINGW_NOTHROW unlink (const char*); |
|
307 _CRTIMP int __cdecl __MINGW_NOTHROW write (int, const void*, unsigned int); |
|
308 #endif /* _UWIN */ |
|
309 |
|
310 #ifdef __USE_MINGW_ACCESS |
|
311 /* Old versions of MSVCRT access() just ignored X_OK, while the version |
|
312 shipped with Vista, returns an error code. This will restore the |
|
313 old behaviour */ |
|
314 static inline int __mingw_access (const char* __fname, int __mode) |
|
315 { return _access (__fname, __mode & ~X_OK); } |
|
316 #define access(__f,__m) __mingw_access (__f, __m) |
|
317 #endif |
|
318 |
|
319 /* Wide character versions. Also declared in wchar.h. */ |
|
320 /* Where do these live? Not in libmoldname.a nor in libmsvcrt.a */ |
|
321 #if 0 |
|
322 int waccess(const wchar_t *, int); |
|
323 int wchmod(const wchar_t *, int); |
|
324 int wcreat(const wchar_t *, int); |
|
325 long wfindfirst(wchar_t *, struct _wfinddata_t *); |
|
326 int wfindnext(long, struct _wfinddata_t *); |
|
327 int wunlink(const wchar_t *); |
|
328 int wrename(const wchar_t *, const wchar_t *); |
|
329 int wopen(const wchar_t *, int, ...); |
|
330 int wsopen(const wchar_t *, int, int, ...); |
|
331 wchar_t * wmktemp(wchar_t *); |
|
332 #endif |
|
333 |
|
334 #endif /* Not _NO_OLDNAMES */ |
|
335 |
|
336 #ifdef __cplusplus |
|
337 } |
|
338 #endif |
|
339 |
|
340 #endif /* Not RC_INVOKED */ |
|
341 |
|
342 #endif /* _IO_H_ not defined */ |