1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the mingw-w64 runtime package.
4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5  */
6 #ifndef _IO_H_
7 #define _IO_H_
8 
9 #include <crtdefs.h>
10 #include <string.h>
11 
12 #if defined(__LIBMSVCRT__)
13 /* When building mingw-w64, this should be blank.  */
14 #define _SECIMP
15 #else
16 #ifndef _SECIMP
17 #define _SECIMP __declspec(dllimport)
18 #endif /* _SECIMP */
19 #endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
20 
21 #pragma pack(push,_CRT_PACKING)
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 _CRTIMP char* __cdecl _getcwd (char*, int);
28 #ifndef _FSIZE_T_DEFINED
29   typedef unsigned long _fsize_t;
30 #define _FSIZE_T_DEFINED
31 #endif
32 
33 #ifndef _FINDDATA_T_DEFINED
34 
35   struct _finddata32_t {
36     unsigned attrib;
37     __time32_t time_create;
38     __time32_t time_access;
39     __time32_t time_write;
40     _fsize_t size;
41     char name[260];
42   };
43 
44   struct _finddata32i64_t {
45     unsigned attrib;
46     __time32_t time_create;
47     __time32_t time_access;
48     __time32_t time_write;
49     __MINGW_EXTENSION __int64 size;
50     char name[260];
51   };
52 
53   struct _finddata64i32_t {
54     unsigned attrib;
55     __time64_t time_create;
56     __time64_t time_access;
57     __time64_t time_write;
58     _fsize_t size;
59     char name[260];
60   };
61 
62   struct __finddata64_t {
63     unsigned attrib;
64     __time64_t time_create;
65     __time64_t time_access;
66     __time64_t time_write;
67     __MINGW_EXTENSION __int64 size;
68     char name[260];
69   };
70 
71 #ifdef _USE_32BIT_TIME_T
72 #define _finddata_t _finddata32_t
73 #define _finddatai64_t _finddata32i64_t
74 
75 #define _findfirst _findfirst32
76 #define _findnext _findnext32
77 #define _findfirsti64 _findfirst32i64
78 #define _findnexti64 _findnext32i64
79 #else
80 #define _finddata_t _finddata64i32_t
81 #define _finddatai64_t __finddata64_t
82 
83 #define _findfirst _findfirst64i32
84 #define _findnext _findnext64i32
85 #define _findfirsti64 _findfirst64
86 #define _findnexti64 _findnext64
87 #endif /* _USE_32BIT_TIME_T */
88 
89 #define _FINDDATA_T_DEFINED
90 #endif /* _FINDDATA_T_DEFINED */
91 
92 #ifndef _WFINDDATA_T_DEFINED
93 
94   struct _wfinddata32_t {
95     unsigned attrib;
96     __time32_t time_create;
97     __time32_t time_access;
98     __time32_t time_write;
99     _fsize_t size;
100     wchar_t name[260];
101   };
102 
103   struct _wfinddata32i64_t {
104     unsigned attrib;
105     __time32_t time_create;
106     __time32_t time_access;
107     __time32_t time_write;
108     __MINGW_EXTENSION __int64 size;
109     wchar_t name[260];
110   };
111 
112   struct _wfinddata64i32_t {
113     unsigned attrib;
114     __time64_t time_create;
115     __time64_t time_access;
116     __time64_t time_write;
117     _fsize_t size;
118     wchar_t name[260];
119   };
120 
121   struct _wfinddata64_t {
122     unsigned attrib;
123     __time64_t time_create;
124     __time64_t time_access;
125     __time64_t time_write;
126     __MINGW_EXTENSION __int64 size;
127     wchar_t name[260];
128   };
129 
130 #ifdef _USE_32BIT_TIME_T
131 #define _wfinddata_t _wfinddata32_t
132 #define _wfinddatai64_t _wfinddata32i64_t
133 
134 #define _wfindfirst _wfindfirst32
135 #define _wfindnext _wfindnext32
136 #define _wfindfirst32i64 _wfindfirsti64
137 #define _wfindnext32i64 _wfindnexti64
138 #else
139 #define _wfinddata_t _wfinddata64i32_t
140 #define _wfinddatai64_t _wfinddata64_t
141 
142 #define _wfindfirst _wfindfirst64i32
143 #define _wfindnext _wfindnext64i32
144 #define _wfindfirsti64 _wfindfirst64
145 #define _wfindnexti64 _wfindnext64
146 #endif /* _USE_32BIT_TIME_T */
147 
148 #define _WFINDDATA_T_DEFINED
149 #endif /* _WFINDDATA_T_DEFINED */
150 
151 #define _A_NORMAL 0x00
152 #define _A_RDONLY 0x01
153 #define _A_HIDDEN 0x02
154 #define _A_SYSTEM 0x04
155 #define _A_SUBDIR 0x10
156 #define _A_ARCH 0x20
157 
158 #ifndef _SIZE_T_DEFINED
159 #define _SIZE_T_DEFINED
160 #undef size_t
161 #ifdef _WIN64
162   __MINGW_EXTENSION typedef unsigned __int64 size_t;
163 #else
164   typedef unsigned int size_t;
165 #endif /* _WIN64 */
166 #endif /* _SIZE_T_DEFINED */
167 
168 #ifndef _SSIZE_T_DEFINED
169 #define _SSIZE_T_DEFINED
170 #undef ssize_t
171 #ifdef _WIN64
172   __MINGW_EXTENSION typedef __int64 ssize_t;
173 #else
174   typedef int ssize_t;
175 #endif /* _WIN64 */
176 #endif /* _SSIZE_T_DEFINED */
177 
178 #include <_mingw_off_t.h>
179 
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 #define	X_OK	1	/* Check for execute permission. */
184 #define	W_OK	2	/* Check for write permission */
185 #define	R_OK	4	/* Check for read permission */
186 
187   _CRTIMP int __cdecl _access(const char *_Filename,int _AccessMode);
188   _SECIMP errno_t __cdecl _access_s(const char *_Filename,int _AccessMode);
189   _CRTIMP int __cdecl _chmod(const char *_Filename,int _Mode);
190   _CRTIMP int __cdecl _chsize(int _FileHandle,long _Size) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
191   _SECIMP errno_t __cdecl _chsize_s (int _FileHandle,__int64 _Size);
192   _CRTIMP int __cdecl _close(int _FileHandle);
193   _CRTIMP int __cdecl _commit(int _FileHandle);
194   _CRTIMP int __cdecl _creat(const char *_Filename,int _PermissionMode) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
195   _CRTIMP int __cdecl _dup(int _FileHandle);
196   _CRTIMP int __cdecl _dup2(int _FileHandleSrc,int _FileHandleDst);
197   _CRTIMP int __cdecl _eof(int _FileHandle);
198   _CRTIMP long __cdecl _filelength(int _FileHandle);
199   _CRTIMP intptr_t __cdecl _findfirst32(const char *_Filename,struct _finddata32_t *_FindData);
200   _CRTIMP int __cdecl _findnext32(intptr_t _FindHandle,struct _finddata32_t *_FindData);
201   _CRTIMP int __cdecl _findclose(intptr_t _FindHandle);
202   _CRTIMP int __cdecl _isatty(int _FileHandle);
203   _CRTIMP int __cdecl _locking(int _FileHandle,int _LockMode,long _NumOfBytes);
204   _CRTIMP long __cdecl _lseek(int _FileHandle,long _Offset,int _Origin);
205   _off64_t lseek64(int fd,_off64_t offset, int whence);
206   _CRTIMP char *__cdecl _mktemp(char *_TemplateName) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
207   _SECIMP errno_t __cdecl _mktemp_s (char *_TemplateName,size_t _Size);
208   _CRTIMP int __cdecl _pipe(int *_PtHandles,unsigned int _PipeSize,int _TextMode);
209   _CRTIMP int __cdecl _read(int _FileHandle,void *_DstBuf,unsigned int _MaxCharCount);
210 
211 #ifndef _CRT_DIRECTORY_DEFINED
212 #define _CRT_DIRECTORY_DEFINED
213   int __cdecl remove(const char *_Filename);
214   int __cdecl rename(const char *_OldFilename,const char *_NewFilename);
215   _CRTIMP int __cdecl _unlink(const char *_Filename);
216 #ifndef	NO_OLDNAMES
217   int __cdecl unlink(const char *_Filename) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
218 #endif
219 #endif
220 
221   _CRTIMP int __cdecl _setmode(int _FileHandle,int _Mode);
222   _CRTIMP long __cdecl _tell(int _FileHandle);
223   _CRTIMP int __cdecl _umask(int _Mode) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
224   _SECIMP errno_t __cdecl _umask_s (int _NewMode,int *_OldMode);
225   _CRTIMP int __cdecl _write(int _FileHandle,const void *_Buf,unsigned int _MaxCharCount);
226 
227   __MINGW_EXTENSION _CRTIMP __int64 __cdecl _filelengthi64(int _FileHandle);
228   _CRTIMP intptr_t __cdecl _findfirst32i64(const char *_Filename,struct _finddata32i64_t *_FindData);
229   _CRTIMP intptr_t __cdecl _findfirst64(const char *_Filename,struct __finddata64_t *_FindData);
230 #ifdef __cplusplus
231 #include <string.h>
232 #endif
233   intptr_t __cdecl _findfirst64i32(const char *_Filename,struct _finddata64i32_t *_FindData);
234 #ifndef __CRT__NO_INLINE
_findfirst64i32(const char * _Filename,struct _finddata64i32_t * _FindData)235   __CRT_INLINE intptr_t __cdecl _findfirst64i32(const char *_Filename,struct _finddata64i32_t *_FindData)
236   {
237     struct __finddata64_t fd;
238     intptr_t ret = _findfirst64(_Filename,&fd);
239     if (ret == -1) {
240       memset(_FindData,0,sizeof(struct _finddata64i32_t));
241       return -1;
242     }
243     _FindData->attrib=fd.attrib;
244     _FindData->time_create=fd.time_create;
245     _FindData->time_access=fd.time_access;
246     _FindData->time_write=fd.time_write;
247     _FindData->size=(_fsize_t) fd.size;
248     strncpy(_FindData->name,fd.name,260);
249     return ret;
250   }
251 #endif /* __CRT__NO_INLINE */
252   _CRTIMP int __cdecl _findnext32i64(intptr_t _FindHandle,struct _finddata32i64_t *_FindData);
253   _CRTIMP int __cdecl _findnext64(intptr_t _FindHandle,struct __finddata64_t *_FindData);
254   int __cdecl _findnext64i32(intptr_t _FindHandle,struct _finddata64i32_t *_FindData);
255 #ifndef __CRT__NO_INLINE
_findnext64i32(intptr_t _FindHandle,struct _finddata64i32_t * _FindData)256   __CRT_INLINE int __cdecl _findnext64i32(intptr_t _FindHandle,struct _finddata64i32_t *_FindData)
257   {
258     struct __finddata64_t fd;
259     int ret = _findnext64(_FindHandle,&fd);
260     if (ret == -1) {
261       memset(_FindData,0,sizeof(struct _finddata64i32_t));
262       return -1;
263     }
264     _FindData->attrib=fd.attrib;
265     _FindData->time_create=fd.time_create;
266     _FindData->time_access=fd.time_access;
267     _FindData->time_write=fd.time_write;
268     _FindData->size=(_fsize_t) fd.size;
269     strncpy(_FindData->name,fd.name,260);
270     return ret;
271   }
272 #endif /* __CRT__NO_INLINE */
273   __MINGW_EXTENSION __int64 __cdecl _lseeki64(int _FileHandle,__int64 _Offset,int _Origin);
274   __MINGW_EXTENSION __int64 __cdecl _telli64(int _FileHandle);
275 
276 #ifndef NO_OLDNAMES
277 #ifndef _UWIN
278   int __cdecl chdir (const char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
279   char *__cdecl getcwd (char *, int) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
280   int __cdecl mkdir (const char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
281   char *__cdecl mktemp(char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
282   int __cdecl rmdir (const char*) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
283   int __cdecl chmod (const char *, int) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
284 #endif /* _UWIN */
285 #endif /* Not NO_OLDNAMES */
286 
287   _SECIMP errno_t __cdecl _sopen_s(int *_FileHandle,const char *_Filename,int _OpenFlag,int _ShareFlag,int _PermissionMode);
288 
289   _CRTIMP int __cdecl _open(const char *_Filename,int _OpenFlag,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
290   _CRTIMP int __cdecl _sopen(const char *_Filename,int _OpenFlag,int _ShareFlag,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
291 
292 #ifndef _WIO_DEFINED
293 #define _WIO_DEFINED
294   _CRTIMP int __cdecl _waccess(const wchar_t *_Filename,int _AccessMode);
295   _SECIMP errno_t __cdecl _waccess_s (const wchar_t *_Filename,int _AccessMode);
296   _CRTIMP int __cdecl _wchmod(const wchar_t *_Filename,int _Mode);
297   _CRTIMP int __cdecl _wcreat(const wchar_t *_Filename,int _PermissionMode) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
298   _CRTIMP intptr_t __cdecl _wfindfirst32(const wchar_t *_Filename,struct _wfinddata32_t *_FindData);
299   _CRTIMP int __cdecl _wfindnext32(intptr_t _FindHandle,struct _wfinddata32_t *_FindData);
300   _CRTIMP int __cdecl _wunlink(const wchar_t *_Filename);
301   _CRTIMP int __cdecl _wrename(const wchar_t *_OldFilename,const wchar_t *_NewFilename);
302   _CRTIMP wchar_t *__cdecl _wmktemp(wchar_t *_TemplateName) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
303   _SECIMP errno_t __cdecl _wmktemp_s (wchar_t *_TemplateName, size_t _SizeInWords);
304 
305   _CRTIMP intptr_t __cdecl _wfindfirst32i64(const wchar_t *_Filename,struct _wfinddata32i64_t *_FindData);
306   intptr_t __cdecl _wfindfirst64i32(const wchar_t *_Filename,struct _wfinddata64i32_t *_FindData);
307   _CRTIMP intptr_t __cdecl _wfindfirst64(const wchar_t *_Filename,struct _wfinddata64_t *_FindData);
308   _CRTIMP int __cdecl _wfindnext32i64(intptr_t _FindHandle,struct _wfinddata32i64_t *_FindData);
309   int __cdecl _wfindnext64i32(intptr_t _FindHandle,struct _wfinddata64i32_t *_FindData);
310   _CRTIMP int __cdecl _wfindnext64(intptr_t _FindHandle,struct _wfinddata64_t *_FindData);
311 
312   _CRTIMP errno_t __cdecl _wsopen_s(int *_FileHandle,const wchar_t *_Filename,int _OpenFlag,int _ShareFlag,int _PermissionFlag);
313 
314   _CRTIMP int __cdecl _wopen(const wchar_t *_Filename,int _OpenFlag,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
315   _CRTIMP int __cdecl _wsopen(const wchar_t *_Filename,int _OpenFlag,int _ShareFlag,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
316 
317 #endif
318 
319   int __cdecl __lock_fhandle(int _Filehandle);
320   void __cdecl _unlock_fhandle(int _Filehandle);
321   _CRTIMP intptr_t __cdecl _get_osfhandle(int _FileHandle);
322   _CRTIMP int __cdecl _open_osfhandle(intptr_t _OSFileHandle,int _Flags);
323 
324 #ifndef NO_OLDNAMES
325   int __cdecl access(const char *_Filename,int _AccessMode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
326   int __cdecl chmod(const char *_Filename,int _AccessMode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
327   int __cdecl chsize(int _FileHandle,long _Size) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
328   int __cdecl close(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
329   int __cdecl creat(const char *_Filename,int _PermissionMode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
330   int __cdecl dup(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
331   int __cdecl dup2(int _FileHandleSrc,int _FileHandleDst) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
332   int __cdecl eof(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
333   long __cdecl filelength(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
334   int __cdecl isatty(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
335   int __cdecl locking(int _FileHandle,int _LockMode,long _NumOfBytes) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
336   long __cdecl lseek(int _FileHandle,long _Offset,int _Origin) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
337   char *__cdecl mktemp(char *_TemplateName)  __MINGW_ATTRIB_DEPRECATED_MSVC2005;
338   int __cdecl open(const char *_Filename,int _OpenFlag,...)  __MINGW_ATTRIB_DEPRECATED_MSVC2005;
339   int __cdecl read(int _FileHandle,void *_DstBuf,unsigned int _MaxCharCount)  __MINGW_ATTRIB_DEPRECATED_MSVC2005;
340   int __cdecl setmode(int _FileHandle,int _Mode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
341   int __cdecl sopen(const char *_Filename,int _OpenFlag,int _ShareFlag,...) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
342   long __cdecl tell(int _FileHandle) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
343   int __cdecl umask(int _Mode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
344   int __cdecl write(int _Filehandle,const void *_Buf,unsigned int _MaxCharCount) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
345 #endif
346 
347 #ifndef _FILE_OFFSET_BITS_SET_LSEEK
348 #define _FILE_OFFSET_BITS_SET_LSEEK
349 #if (defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64))
350 #define lseek lseek64
351 #endif /* (defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)) */
352 #endif /* _FILE_OFFSET_BITS_SET_LSEEK */
353 
354 #ifdef _POSIX
355 
356 /* Misc stuff */
357 char *getlogin(void);
358 #ifdef __USE_MINGW_ALARM
359 unsigned int alarm(unsigned int seconds);
360 #endif
361 
362 #endif
363 
364 #ifdef __USE_MINGW_ACCESS
365 /*  Old versions of MSVCRT access() just ignored X_OK, while the version
366     shipped with Vista, returns an error code.  This will restore the
367     old behaviour  */
__mingw_access(const char * __fname,int __mode)368 static inline int __mingw_access (const char *__fname, int __mode) {
369   return  _access (__fname, __mode & ~X_OK);
370 }
371 
372 #define access(__f,__m)  __mingw_access (__f, __m)
373 #endif
374 
375 
376 #ifdef __cplusplus
377 }
378 #endif
379 
380 
381 #pragma pack(pop)
382 
383 #endif /* End _IO_H_ */
384 
385