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.
7 * System level I/O functions and types.
13 /* All the headers include this file. */
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 */
20 #include <sys/types.h> /* To get time_t. */
23 * Attributes of files as returned by _findfirst et al.
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
36 #ifndef _INTPTR_T_DEFINED
37 #define _INTPTR_T_DEFINED
39 typedef __int64
intptr_t;
45 #ifndef _FSIZE_T_DEFINED
46 typedef unsigned long _fsize_t
;
47 #define _FSIZE_T_DEFINED
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.
56 #define FILENAME_MAX (260)
60 * The following structure is filled in by _findfirst or _findnext when
61 * they succeed in finding a match.
65 unsigned attrib
; /* Attributes, see constants above. */
67 time_t time_access
; /* always midnight local time */
70 char name
[FILENAME_MAX
]; /* may include spaces. */
73 struct _finddatai64_t
{
79 char name
[FILENAME_MAX
];
82 #if __MSVCRT_VERSION__ >= 0x0601
83 struct __finddata64_t
{
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 */
90 char name
[FILENAME_MAX
];
94 #ifndef _WFINDDATA_T_DEFINED
97 time_t time_create
; /* -1 for FAT file systems */
98 time_t time_access
; /* -1 for FAT file systems */
101 wchar_t name
[FILENAME_MAX
]; /* may include spaces. */
104 struct _wfinddatai64_t
{
110 wchar_t name
[FILENAME_MAX
];
113 #if __MSVCRT_VERSION__ >= 0x0601
114 struct __wfinddata64_t
{
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 */
121 wchar_t name
[FILENAME_MAX
];
125 #define _WFINDDATA_T_DEFINED
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.
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);
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);
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
)
165 return _lseeki64(fd
, (__int64
) offset
, whence
);
169 #endif /* __MSVCRT__ */
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);
182 #endif /* Not _NO_OLDNAMES */
188 #endif /* Not RC_INVOKED */
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
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 */
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);
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);
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);
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);
233 /* LK_... locking commands defined in sys/locking.h. */
234 _CRTIMP
int __cdecl __MINGW_NOTHROW
_locking (int, int, long);
236 _CRTIMP
long __cdecl __MINGW_NOTHROW
_lseek (int, long, int);
238 /* Optional third argument is unsigned unPermissions. */
239 _CRTIMP
int __cdecl __MINGW_NOTHROW
_open (const char*, int, ...);
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
247 _CRTIMP
int __cdecl __MINGW_NOTHROW
remove (const char*);
248 _CRTIMP
int __cdecl __MINGW_NOTHROW
rename (const char*, const char*);
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, ...);
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);
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
*);
279 #endif /* defined (__MSVCRT__) */
281 #endif /* _WIO_DEFINED */
285 * Non-underscored versions of non-ANSI functions to improve portability.
286 * These functions live in libmoldname.a.
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);
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
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)
319 /* Wide character versions. Also declared in wchar.h. */
320 /* Where do these live? Not in libmoldname.a nor in libmsvcrt.a */
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 *);
334 #endif /* Not _NO_OLDNAMES */
340 #endif /* Not RC_INVOKED */
342 #endif /* _IO_H_ not defined */