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 struct __finddata64_t
{
84 __time64_t time_create
;
85 __time64_t time_access
;
86 __time64_t time_write
;
88 char name
[FILENAME_MAX
];
91 #ifndef _WFINDDATA_T_DEFINED
94 time_t time_create
; /* -1 for FAT file systems */
95 time_t time_access
; /* -1 for FAT file systems */
98 wchar_t name
[FILENAME_MAX
]; /* may include spaces. */
101 struct _wfinddatai64_t
{
107 wchar_t name
[FILENAME_MAX
];
110 struct __wfinddata64_t
{
112 __time64_t time_create
;
113 __time64_t time_access
;
114 __time64_t time_write
;
116 wchar_t name
[FILENAME_MAX
];
119 #define _WFINDDATA_T_DEFINED
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.
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);
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);
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 */
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
)
160 return _lseeki64(fd
, (__int64
) offset
, whence
);
164 #endif /* __MSVCRT__ */
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);
177 #endif /* Not _NO_OLDNAMES */
183 #endif /* Not RC_INVOKED */
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
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 */
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);
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);
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);
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);
228 /* LK_... locking commands defined in sys/locking.h. */
229 _CRTIMP
int __cdecl __MINGW_NOTHROW
_locking (int, int, long);
231 _CRTIMP
long __cdecl __MINGW_NOTHROW
_lseek (int, long, int);
233 /* Optional third argument is unsigned unPermissions. */
234 _CRTIMP
int __cdecl __MINGW_NOTHROW
_open (const char*, int, ...);
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
242 _CRTIMP
int __cdecl __MINGW_NOTHROW
remove (const char*);
243 _CRTIMP
int __cdecl __MINGW_NOTHROW
rename (const char*, const char*);
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, ...);
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);
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
*);
274 #endif /* defined (__MSVCRT__) */
276 #endif /* _WIO_DEFINED */
280 * Non-underscored versions of non-ANSI functions to improve portability.
281 * These functions live in libmoldname.a.
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);
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
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)
314 /* Wide character versions. Also declared in wchar.h. */
315 /* Where do these live? Not in libmoldname.a nor in libmsvcrt.a */
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 *);
329 #endif /* Not _NO_OLDNAMES */
335 #endif /* Not RC_INVOKED */
337 #endif /* _IO_H_ not defined */