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. */
21 #include <stdint.h> /* For intptr_t. */
24 * Attributes of files as returned by _findfirst et al.
26 #define _A_NORMAL 0x00000000
27 #define _A_RDONLY 0x00000001
28 #define _A_HIDDEN 0x00000002
29 #define _A_SYSTEM 0x00000004
30 #define _A_VOLID 0x00000008
31 #define _A_SUBDIR 0x00000010
32 #define _A_ARCH 0x00000020
37 #ifndef _FSIZE_T_DEFINED
38 typedef unsigned long _fsize_t
;
39 #define _FSIZE_T_DEFINED
43 * The maximum length of a file name. You should use GetVolumeInformation
44 * instead of this constant. But hey, this works.
45 * Also defined in stdio.h.
48 #define FILENAME_MAX (260)
52 * The following structure is filled in by _findfirst or _findnext when
53 * they succeed in finding a match.
57 unsigned attrib
; /* Attributes, see constants above. */
59 time_t time_access
; /* always midnight local time */
62 char name
[FILENAME_MAX
]; /* may include spaces. */
65 struct _finddatai64_t
{
71 char name
[FILENAME_MAX
];
74 struct __finddata64_t
{
76 __time64_t time_create
;
77 __time64_t time_access
;
78 __time64_t time_write
;
80 char name
[FILENAME_MAX
];
83 #ifndef _WFINDDATA_T_DEFINED
86 time_t time_create
; /* -1 for FAT file systems */
87 time_t time_access
; /* -1 for FAT file systems */
90 wchar_t name
[FILENAME_MAX
]; /* may include spaces. */
93 struct _wfinddatai64_t
{
99 wchar_t name
[FILENAME_MAX
];
102 struct __wfinddata64_t
{
104 __time64_t time_create
;
105 __time64_t time_access
;
106 __time64_t time_write
;
108 wchar_t name
[FILENAME_MAX
];
111 #define _WFINDDATA_T_DEFINED
119 * Functions for searching for files. _findfirst returns -1 if no match
120 * is found. Otherwise it returns a handle to be used in _findnext and
121 * _findclose calls. _findnext also returns -1 if no match could be found,
122 * and 0 if a match was found. Call _findclose when you are finished.
124 /* FIXME: Should these all use intptr_t, as per recent MSDN docs? */
125 _CRTIMP
long __cdecl
_findfirst (const char*, struct _finddata_t
*);
126 _CRTIMP
int __cdecl
_findnext (long, struct _finddata_t
*);
127 _CRTIMP
int __cdecl
_findclose (long);
129 _CRTIMP
int __cdecl
_chdir (const char*);
130 _CRTIMP
char* __cdecl
_getcwd (char*, int);
131 _CRTIMP
int __cdecl
_mkdir (const char*);
132 _CRTIMP
char* __cdecl
_mktemp (char*);
133 _CRTIMP
int __cdecl
_rmdir (const char*);
134 _CRTIMP
int __cdecl
_chmod (const char*, int);
137 _CRTIMP __int64 __cdecl
_filelengthi64(int);
138 _CRTIMP
long __cdecl
_findfirsti64(const char*, struct _finddatai64_t
*);
139 _CRTIMP
int __cdecl
_findnexti64(long, struct _finddatai64_t
*);
140 _CRTIMP __int64 __cdecl
_lseeki64(int, __int64
, int);
141 _CRTIMP __int64 __cdecl
_telli64(int);
142 /* These require newer versions of msvcrt.dll (6.1 or higher). */
143 #if __MSVCRT_VERSION__ >= 0x0601
144 _CRTIMP
intptr_t __cdecl
_findfirst64(const char*, struct __finddata64_t
*);
145 _CRTIMP
intptr_t __cdecl
_findnext64(intptr_t, struct __finddata64_t
*);
146 #endif /* __MSVCRT_VERSION__ >= 0x0601 */
148 #ifndef __NO_MINGW_LFS
149 __CRT_INLINE off64_t
lseek64 (int fd
, off64_t offset
, int whence
)
151 return _lseeki64(fd
, (__int64
) offset
, whence
);
155 #endif /* __MSVCRT__ */
160 _CRTIMP
int __cdecl
chdir (const char*);
161 _CRTIMP
char* __cdecl
getcwd (char*, int);
162 _CRTIMP
int __cdecl
mkdir (const char*);
163 _CRTIMP
char* __cdecl
mktemp (char*);
164 _CRTIMP
int __cdecl
rmdir (const char*);
165 _CRTIMP
int __cdecl
chmod (const char*, int);
168 #endif /* Not _NO_OLDNAMES */
174 #endif /* Not RC_INVOKED */
176 /* TODO: Maximum number of open handles has not been tested, I just set
177 * it the same as FOPEN_MAX. */
178 #define HANDLE_MAX FOPEN_MAX
180 /* Some defines for _access nAccessMode (MS doesn't define them, but
181 * it doesn't seem to hurt to add them). */
182 #define F_OK 0 /* Check for file existence */
183 /* Well maybe it does hurt. On newer versions of MSVCRT, an access mode
184 of 1 causes invalid parameter error. */
185 #define X_OK 1 /* MS access() doesn't check for execute permission. */
186 #define W_OK 2 /* Check for write permission */
187 #define R_OK 4 /* Check for read permission */
195 _CRTIMP
int __cdecl
_access (const char*, int);
196 _CRTIMP
int __cdecl
_chsize (int, long);
197 _CRTIMP
int __cdecl
_close (int);
198 _CRTIMP
int __cdecl
_commit(int);
200 /* NOTE: The only significant bit in unPermissions appears to be bit 7 (0x80),
201 * the "owner write permission" bit (on FAT). */
202 _CRTIMP
int __cdecl
_creat (const char*, int);
204 _CRTIMP
int __cdecl
_dup (int);
205 _CRTIMP
int __cdecl
_dup2 (int, int);
206 _CRTIMP
long __cdecl
_filelength (int);
207 _CRTIMP
long __cdecl
_get_osfhandle (int);
208 _CRTIMP
int __cdecl
_isatty (int);
210 /* In a very odd turn of events this function is excluded from those
211 * files which define _STREAM_COMPAT. This is required in order to
212 * build GNU libio because of a conflict with _eof in streambuf.h
213 * line 107. Actually I might just be able to change the name of
214 * the enum member in streambuf.h... we'll see. TODO */
215 #ifndef _STREAM_COMPAT
216 _CRTIMP
int __cdecl
_eof (int);
219 /* LK_... locking commands defined in sys/locking.h. */
220 _CRTIMP
int __cdecl
_locking (int, int, long);
222 _CRTIMP
long __cdecl
_lseek (int, long, int);
224 /* Optional third argument is unsigned unPermissions. */
225 _CRTIMP
int __cdecl
_open (const char*, int, ...);
227 _CRTIMP
int __cdecl
_open_osfhandle (long, int);
228 _CRTIMP
int __cdecl
_pipe (int *, unsigned int, int);
229 _CRTIMP
int __cdecl
_read (int, void*, unsigned int);
230 _CRTIMP
int __cdecl
_setmode (int, int);
231 /* MS puts remove & rename (but not wide versions) in io.h as well
233 _CRTIMP
int __cdecl
remove (const char*);
234 _CRTIMP
int __cdecl
rename (const char*, const char*);
236 /* SH_... flags for nShFlags defined in share.h
237 * Optional fourth argument is unsigned unPermissions */
238 _CRTIMP
int __cdecl
_sopen (const char*, int, int, ...);
240 _CRTIMP
long __cdecl
_tell (int);
241 /* Should umask be in sys/stat.h and/or sys/types.h instead? */
242 _CRTIMP
int __cdecl
_umask (int);
243 _CRTIMP
int __cdecl
_unlink (const char*);
244 _CRTIMP
int __cdecl
_write (int, const void*, unsigned int);
246 /* Wide character versions. Also declared in wchar.h. */
247 /* Not in crtdll.dll */
248 #if !defined (_WIO_DEFINED)
249 #if defined (__MSVCRT__)
250 _CRTIMP
int __cdecl
_waccess(const wchar_t*, int);
251 _CRTIMP
int __cdecl
_wchmod(const wchar_t*, int);
252 _CRTIMP
int __cdecl
_wcreat(const wchar_t*, int);
253 _CRTIMP
long __cdecl
_wfindfirst(const wchar_t*, struct _wfinddata_t
*);
254 _CRTIMP
int __cdecl
_wfindnext(long, struct _wfinddata_t
*);
255 _CRTIMP
int __cdecl
_wunlink(const wchar_t*);
256 _CRTIMP
int __cdecl
_wopen(const wchar_t*, int, ...);
257 _CRTIMP
int __cdecl
_wsopen(const wchar_t*, int, int, ...);
258 _CRTIMP
wchar_t * __cdecl
_wmktemp(wchar_t*);
259 _CRTIMP
long __cdecl
_wfindfirsti64(const wchar_t*, struct _wfinddatai64_t
*);
260 _CRTIMP
int __cdecl
_wfindnexti64(long, struct _wfinddatai64_t
*);
261 #if __MSVCRT_VERSION__ >= 0x0601
262 _CRTIMP
intptr_t __cdecl
_wfindfirst64(const wchar_t*, struct __wfinddata64_t
*);
263 _CRTIMP
intptr_t __cdecl
_wfindnext64(intptr_t, struct __wfinddata64_t
*);
265 #endif /* defined (__MSVCRT__) */
267 #endif /* _WIO_DEFINED */
271 * Non-underscored versions of non-ANSI functions to improve portability.
272 * These functions live in libmoldname.a.
276 _CRTIMP
int __cdecl
access (const char*, int);
277 _CRTIMP
int __cdecl
chsize (int, long );
278 _CRTIMP
int __cdecl
close (int);
279 _CRTIMP
int __cdecl
creat (const char*, int);
280 _CRTIMP
int __cdecl
dup (int);
281 _CRTIMP
int __cdecl
dup2 (int, int);
282 _CRTIMP
int __cdecl
eof (int);
283 _CRTIMP
long __cdecl
filelength (int);
284 _CRTIMP
int __cdecl
isatty (int);
285 _CRTIMP
long __cdecl
lseek (int, long, int);
286 _CRTIMP
int __cdecl
open (const char*, int, ...);
287 _CRTIMP
int __cdecl
read (int, void*, unsigned int);
288 _CRTIMP
int __cdecl
setmode (int, int);
289 _CRTIMP
int __cdecl
sopen (const char*, int, int, ...);
290 _CRTIMP
long __cdecl
tell (int);
291 _CRTIMP
int __cdecl
umask (int);
292 _CRTIMP
int __cdecl
unlink (const char*);
293 _CRTIMP
int __cdecl
write (int, const void*, unsigned int);
296 #ifdef __USE_MINGW_ACCESS
297 /* Old versions of MSVCRT access() just ignored X_OK, while the version
298 shipped with Vista, returns an error code. This will restore the
300 static inline int __mingw_access (const char* __fname
, int __mode
)
301 { return _access (__fname
, __mode
& ~X_OK
); }
302 #define access(__f,__m) __mingw_access (__f, __m)
305 /* Wide character versions. Also declared in wchar.h. */
306 /* Where do these live? Not in libmoldname.a nor in libmsvcrt.a */
308 int waccess(const wchar_t *, int);
309 int wchmod(const wchar_t *, int);
310 int wcreat(const wchar_t *, int);
311 long wfindfirst(wchar_t *, struct _wfinddata_t
*);
312 int wfindnext(long, struct _wfinddata_t
*);
313 int wunlink(const wchar_t *);
314 int wrename(const wchar_t *, const wchar_t *);
315 int wopen(const wchar_t *, int, ...);
316 int wsopen(const wchar_t *, int, int, ...);
317 wchar_t * wmktemp(wchar_t *);
320 #endif /* Not _NO_OLDNAMES */
326 #endif /* Not RC_INVOKED */
328 #endif /* _IO_H_ not defined */