1 /***
2 *io.h - declarations for low-level file handling and I/O functions
3 *
4 *           Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 *Purpose:
7 *           This file contains the function declarations for the low-level
8 *           file handling and I/O functions.
9 *
10 *           [Public]
11 *
12 ****/
13
14 #if        _MSC_VER > 1000
15 #pragma once
16 #endif
17
18 #ifndef _INC_IO
19 #define _INC_IO
20
21 #include <crtdefs.h>
22
23 #ifdef  _MSC_VER
24 /*
25  * Currently, all MS C compilers for Win32 platforms default to 8 byte
26  * alignment.
27  */
28 #pragma pack(push,_CRT_PACKING)
29 #endif  /* _MSC_VER */
30
31 #ifndef _POSIX_
32
33 #ifdef  __cplusplus
34 extern "C" {
35 #endif
36
37 #ifndef _FSIZE_T_DEFINED
38 typedef unsigned long _fsize_t; /* Could be 64 bits for Win32 */
39 #define _FSIZE_T_DEFINED
40 #endif
41
42 #ifndef _FINDDATA_T_DEFINED
43
44 struct _finddata32_t {
45              unsigned      attrib;
46              __time32_t  time_create;      /* -1 for FAT file systems */
47              __time32_t  time_access;      /* -1 for FAT file systems */
48              __time32_t  time_write;
49              _fsize_t      size;
50              char             name[260];
51 };
52
53 struct _finddata32i64_t {
54              unsigned      attrib;
55              __time32_t  time_create;      /* -1 for FAT file systems */
Lines 56 ... 65 are skipped.
66              __time64_t  time_write;
67              _fsize_t      size;
68              char             name[260];
69 };
70
71 struct __finddata64_t {
72              unsigned      attrib;
73              __time64_t  time_create;      /* -1 for FAT file systems */
74              __time64_t  time_access;      /* -1 for FAT file systems */
75              __time64_t  time_write;
76              __int64        size;
77              char             name[260];
78 };
79
80 #ifdef _USE_32BIT_TIME_T
81 #define _finddata_t        _finddata32_t
82 #define _finddatai64_t  _finddata32i64_t
83
84 #define _findfirst          _findfirst32
85 #define _findnext           _findnext32
86 #define _findfirsti64     _findfirst32i64
87 #define _findnexti64        _findnext32i64
88
89 #else
90 #define _finddata_t        _finddata64i32_t
91 #define _finddatai64_t  __finddata64_t
92
93 #define _findfirst          _findfirst64i32
94 #define _findnext           _findnext64i32
95 #define _findfirsti64     _findfirst64
96 #define _findnexti64      _findnext64
97
98 #endif
99
100
101 #define _FINDDATA_T_DEFINED
102 #endif
103
104 #ifndef _WFINDDATA_T_DEFINED
105
106 struct _wfinddata32_t {
107              unsigned      attrib;
108              __time32_t  time_create;      /* -1 for FAT file systems */
109              __time32_t  time_access;      /* -1 for FAT file systems */
110              __time32_t  time_write;
111              _fsize_t      size;
112              wchar_t        name[260];
113 };
114
115 struct _wfinddata32i64_t {
116              unsigned      attrib;
117              __time32_t  time_create;      /* -1 for FAT file systems */
118              __time32_t  time_access;      /* -1 for FAT file systems */
119              __time32_t  time_write;
120              __int64        size;
121              wchar_t        name[260];
122 };
123
124 struct _wfinddata64i32_t {
125              unsigned      attrib;
126              __time64_t  time_create;      /* -1 for FAT file systems */
127              __time64_t  time_access;      /* -1 for FAT file systems */
128              __time64_t  time_write;
129              _fsize_t      size;
130              wchar_t        name[260];
131 };
132
133 struct _wfinddata64_t {
134              unsigned      attrib;
135              __time64_t  time_create;      /* -1 for FAT file systems */
136              __time64_t  time_access;      /* -1 for FAT file systems */
137              __time64_t  time_write;
138              __int64        size;
139              wchar_t        name[260];
140 };
141
142 #ifdef _USE_32BIT_TIME_T
143 #define _wfinddata_t      _wfinddata32_t
144 #define _wfinddatai64_t _wfinddata32i64_t
145
146 #define _wfindfirst        _wfindfirst32
147 #define _wfindnext          _wfindnext32
148 #define _wfindfirsti64  _wfindfirst32i64
149 #define _wfindnexti64     _wfindnext32i64
150
151 #else                              
152 #define _wfinddata_t      _wfinddata64i32_t
153 #define _wfinddatai64_t _wfinddata64_t
154
155 #define _wfindfirst        _wfindfirst64i32
156 #define _wfindnext          _wfindnext64i32
157 #define _wfindfirsti64  _wfindfirst64
158 #define _wfindnexti64     _wfindnext64
159
160 #endif
161
162 #define _WFINDDATA_T_DEFINED
163 #endif
164
165 /* File attribute constants for _findfirst() */
166
167 #define _A_NORMAL           0x00      /* Normal file - No read/write restrictions */
168 #define _A_RDONLY           0x01      /* Read only file */
169 #define _A_HIDDEN           0x02      /* Hidden file */
170 #define _A_SYSTEM           0x04      /* System file */
171 #define _A_SUBDIR           0x10      /* Subdirectory */
172 #define _A_ARCH               0x20      /* Archive file */
173
174 /* function prototypes */
175
176 #ifndef _SIZE_T_DEFINED
177 #ifdef  _WIN64
178 typedef unsigned __int64      size_t;
179 #else
180 typedef _W64 unsigned int     size_t;
181 #endif
182 #define _SIZE_T_DEFINED
183 #endif
184
185 _Check_return_ _CRTIMP int __cdecl _access(_In_z_ const char * _Filename, _In_ int _AccessMode);
186 _Check_return_wat_ _CRTIMP errno_t __cdecl _access_s(_In_z_ const char * _Filename, _In_ int _AccessMode);
187 _Check_return_ _CRTIMP int __cdecl _chmod(_In_z_ const char * _Filename, _In_ int _Mode);
188 /* note that the newly added _chsize_s takes a 64 bit value */
189 _Check_return_ _CRTIMP int __cdecl _chsize(_In_ int _FileHandle, _In_ long _Size);
190 _Check_return_wat_ _CRTIMP errno_t __cdecl _chsize_s(_In_ int _FileHandle,_In_ __int64 _Size);
191 _Check_return_opt_ _CRTIMP int __cdecl _close(_In_ int _FileHandle);
192 _Check_return_opt_ _CRTIMP int __cdecl _commit(_In_ int _FileHandle);
193 _Check_return_ _CRT_INSECURE_DEPRECATE(_sopen_s) _CRTIMP int __cdecl _creat(_In_z_ const char * _Filename, _In_ int _PermissionMode);
194 _Check_return_ _CRTIMP int __cdecl _dup(_In_ int _FileHandle);
195 _Check_return_ _CRTIMP int __cdecl _dup2(_In_ int _FileHandleSrc, _In_ int _FileHandleDst);
196 _Check_return_ _CRTIMP int __cdecl _eof(_In_ int _FileHandle);
197 _Check_return_ _CRTIMP long __cdecl _filelength(_In_ int _FileHandle);
198 _Check_return_ _CRTIMP intptr_t __cdecl _findfirst32(_In_z_ const char * _Filename, _Out_ struct _finddata32_t * _FindData);
199 _Check_return_ _CRTIMP int __cdecl _findnext32(_In_ intptr_t _FindHandle, _Out_ struct _finddata32_t * _FindData);
200 _Check_return_opt_ _CRTIMP int __cdecl _findclose(_In_ intptr_t _FindHandle);
201 _Check_return_ _CRTIMP int __cdecl _isatty(_In_ int _FileHandle);
202 _CRTIMP int __cdecl _locking(_In_ int _FileHandle, _In_ int _LockMode, _In_ long _NumOfBytes);
203 _Check_return_opt_ _CRTIMP long __cdecl _lseek(_In_ int _FileHandle, _In_ long _Offset, _In_ int _Origin);
204 _Check_return_wat_ _CRTIMP errno_t __cdecl _mktemp_s(_Inout_z_cap_(_Size) char * _TemplateName, _In_ size_t _Size);
205 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _mktemp_s, _Deref_prepost_z_ char, _TemplateName)
206 _Check_return_ __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(char *, __RETURN_POLICY_DST, _CRTIMP, _mktemp, _Inout_z_, char, _TemplateName)
207 _Check_return_ _CRTIMP int __cdecl _pipe(_Inout_cap_c_(2) int * _PtHandles, _In_ unsigned int _PipeSize, _In_ int _TextMode);
208 _Check_return_ _CRTIMP int __cdecl _read(_In_ int _FileHandle, _Out_bytecap_(_MaxCharCount) void * _DstBuf, _In_ unsigned int _MaxCharCount);
209
210 #ifndef _CRT_DIRECTORY_DEFINED
211 #define _CRT_DIRECTORY_DEFINED
212 _Check_return_ _CRTIMP int __cdecl remove(_In_z_ const char * _Filename);
213 _Check_return_ _CRTIMP int __cdecl rename(_In_z_ const char * _OldFilename, _In_z_ const char * _NewFilename);
214 _Check_return_ _CRTIMP int __cdecl _unlink(_In_z_ const char * _Filename);
215 #if !__STDC__
216 _Check_return_ _CRT_NONSTDC_DEPRECATE(_unlink) _CRTIMP int __cdecl unlink(_In_z_ const char * _Filename);
217 #endif
218 #endif
219
220 _Check_return_ _CRTIMP int __cdecl _setmode(_In_ int _FileHandle, _In_ int _Mode);
221 _Check_return_ _CRTIMP long __cdecl _tell(_In_ int _FileHandle);
222 _CRT_INSECURE_DEPRECATE(_umask_s) _CRTIMP int __cdecl _umask(_In_ int _Mode);
223 _Check_return_wat_ _CRTIMP errno_t __cdecl _umask_s(_In_ int _NewMode, _Out_ int * _OldMode);
224 _CRTIMP int __cdecl _write(_In_ int _FileHandle, _In_bytecount_(_MaxCharCount) const void * _Buf, _In_ unsigned int _MaxCharCount);
225
226 _Check_return_ _CRTIMP __int64 __cdecl _filelengthi64(_In_ int _FileHandle);
227 _Check_return_ _CRTIMP intptr_t __cdecl _findfirst32i64(_In_z_ const char * _Filename, _Out_ struct _finddata32i64_t * _FindData);
228 _Check_return_ _CRTIMP intptr_t __cdecl _findfirst64i32(_In_z_ const char * _Filename, _Out_ struct _finddata64i32_t * _FindData);
229 _Check_return_ _CRTIMP intptr_t __cdecl _findfirst64(_In_z_ const char * _Filename, _Out_ struct __finddata64_t * _FindData);
230 _Check_return_ _CRTIMP int __cdecl _findnext32i64(_In_ intptr_t _FindHandle, _Out_ struct _finddata32i64_t * _FindData);
231 _Check_return_ _CRTIMP int __cdecl _findnext64i32(_In_ intptr_t _FindHandle, _Out_ struct _finddata64i32_t * _FindData);
232 _Check_return_ _CRTIMP int __cdecl _findnext64(_In_ intptr_t _FindHandle, _Out_ struct __finddata64_t * _FindData);
233 _Check_return_opt_ _CRTIMP __int64 __cdecl _lseeki64(_In_ int _FileHandle, _In_ __int64 _Offset, _In_ int _Origin);
234 _Check_return_ _CRTIMP __int64 __cdecl _telli64(_In_ int _FileHandle);
235
236 _Check_return_wat_ _CRTIMP errno_t __cdecl _sopen_s(_Out_ int * _FileHandle, _In_z_ const char * _Filename,_In_ int _OpenFlag, _In_ int _ShareFlag, _In_ int _PermissionMode);
237
238 #if !defined(__cplusplus)
239 _Check_return_ _CRT_INSECURE_DEPRECATE(_sopen_s) _CRTIMP int __cdecl _open(_In_z_ const char * _Filename, _In_ int _OpenFlag, ...);
240 _Check_return_ _CRT_INSECURE_DEPRECATE(_sopen_s) _CRTIMP int __cdecl _sopen(_In_z_ const char * _Filename, _In_ int _OpenFlag, int _ShareFlag, ...);
241 #else
242
243 /* these function do not validate pmode; use _sopen_s */
244 extern "C++" _Check_return_ _CRT_INSECURE_DEPRECATE(_sopen_s) _CRTIMP int __cdecl _open(_In_z_ const char * _Filename, _In_ int _Openflag, _In_ int _PermissionMode = 0);
245 extern "C++" _Check_return_ _CRT_INSECURE_DEPRECATE(_sopen_s) _CRTIMP int __cdecl _sopen(_In_z_ const char * _Filename, _In_ int _Openflag, _In_ int _ShareFlag, _In_ int _PermissionMode = 0);
246
247 #endif
248
249 #ifndef _WIO_DEFINED
250
251 /* wide function prototypes, also declared in wchar.h  */
252
253 _Check_return_ _CRTIMP int __cdecl _waccess(_In_z_ const wchar_t * _Filename, _In_ int _AccessMode);
254 _Check_return_wat_ _CRTIMP errno_t __cdecl _waccess_s(_In_z_ const wchar_t * _Filename, _In_ int _AccessMode);
255 _Check_return_ _CRTIMP int __cdecl _wchmod(_In_z_ const wchar_t * _Filename, _In_ int _Mode);
256 _Check_return_ _CRT_INSECURE_DEPRECATE(_wsopen_s) _CRTIMP int __cdecl _wcreat(_In_z_ const wchar_t * _Filename, _In_ int _PermissionMode);
257 _Check_return_ _CRTIMP intptr_t __cdecl _wfindfirst32(_In_z_ const wchar_t * _Filename, _Out_ struct _wfinddata32_t * _FindData);
258 _Check_return_ _CRTIMP int __cdecl _wfindnext32(_In_ intptr_t _FindHandle, _Out_ struct _wfinddata32_t * _FindData);
259 _Check_return_ _CRTIMP int __cdecl _wunlink(_In_z_ const wchar_t * _Filename);
260 _Check_return_ _CRTIMP int __cdecl _wrename(_In_z_ const wchar_t * _OldFilename, _In_z_ const wchar_t * _NewFilename);
261 _CRTIMP errno_t __cdecl _wmktemp_s(_Inout_z_cap_(_SizeInWords) wchar_t * _TemplateName, _In_ size_t _SizeInWords);
262 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _wmktemp_s, _Deref_prepost_z_ wchar_t, _TemplateName)
263 __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, _wmktemp, _Inout_z_, wchar_t, _TemplateName)
264
265 _Check_return_ _CRTIMP intptr_t __cdecl _wfindfirst32i64(_In_z_ const wchar_t * _Filename, _Out_ struct _wfinddata32i64_t * _FindData);
266 _Check_return_ _CRTIMP intptr_t __cdecl _wfindfirst64i32(_In_z_ const wchar_t * _Filename, _Out_ struct _wfinddata64i32_t * _FindData);
267 _Check_return_ _CRTIMP intptr_t __cdecl _wfindfirst64(_In_z_ const wchar_t * _Filename, _Out_ struct _wfinddata64_t * _FindData);
268 _Check_return_ _CRTIMP int __cdecl _wfindnext32i64(_In_ intptr_t _FindHandle, _Out_ struct _wfinddata32i64_t * _FindData);
269 _Check_return_ _CRTIMP int __cdecl _wfindnext64i32(_In_ intptr_t _FindHandle, _Out_ struct _wfinddata64i32_t * _FindData);
270 _Check_return_ _CRTIMP int __cdecl _wfindnext64(_In_ intptr_t _FindHandle, _Out_ struct _wfinddata64_t * _FindData);
271
272 _Check_return_wat_ _CRTIMP errno_t __cdecl _wsopen_s(_Out_ int * _FileHandle, _In_z_ const wchar_t * _Filename, _In_ int _OpenFlag, _In_ int _ShareFlag, _In_ int _PermissionFlag);
273
274 #if !defined(__cplusplus) || !defined(_M_IX86)
275
276 _Check_return_ _CRT_INSECURE_DEPRECATE(_wsopen_s) _CRTIMP int __cdecl _wopen(_In_z_ const wchar_t * _Filename, _In_ int _OpenFlag, ...);
277 _Check_return_ _CRT_INSECURE_DEPRECATE(_wsopen_s) _CRTIMP int __cdecl _wsopen(_In_z_ const wchar_t * _Filename, _In_ int _OpenFlag, int _ShareFlag, ...);
278
279 #else
280
281 /* these function do not validate pmode; use _sopen_s */
282 extern "C++" _CRT_INSECURE_DEPRECATE(_wsopen_s) _CRTIMP int __cdecl _wopen(_In_z_ const wchar_t * _Filename, _In_ int _OpenFlag, _In_ int _PermissionMode = 0);
283 extern "C++" _CRT_INSECURE_DEPRECATE(_wsopen_s) _CRTIMP int __cdecl _wsopen(_In_z_ const wchar_t * _Filename, _In_ int _OpenFlag, _In_ int _ShareFlag, int _PermissionMode = 0);
284
285 #endif
286
287 #define _WIO_DEFINED
288 #endif
289
290 int  __cdecl __lock_fhandle(_In_ int _Filehandle);
291 void __cdecl _unlock_fhandle(_In_ int _Filehandle);
292
293
294 _CRTIMP intptr_t __cdecl _get_osfhandle(_In_ int _FileHandle);
295 _CRTIMP int __cdecl _open_osfhandle(_In_ intptr_t _OSFileHandle, _In_ int _Flags);
296
297 #if        !__STDC__
298
299 /* Non-ANSI names for compatibility */
300
301 #pragma warning(push)
302 #pragma warning(disable: 4141) /* Using deprecated twice */ 
303 _Check_return_ _CRT_NONSTDC_DEPRECATE(_access) _CRTIMP int __cdecl access(_In_z_ const char * _Filename, _In_ int _AccessMode);
304 _Check_return_ _CRT_NONSTDC_DEPRECATE(_chmod) _CRTIMP int __cdecl chmod(_In_z_ const char * _Filename, int _AccessMode);
305 _Check_return_ _CRT_NONSTDC_DEPRECATE(_chsize) _CRTIMP int __cdecl chsize(_In_ int _FileHandle, _In_ long _Size);
306 _Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_close) _CRTIMP int __cdecl close(_In_ int _FileHandle);
307 _Check_return_ _CRT_NONSTDC_DEPRECATE(_creat) _CRT_INSECURE_DEPRECATE(_sopen_s) _CRTIMP int __cdecl creat(_In_z_ const char * _Filename, _In_ int _PermissionMode);
308 _Check_return_ _CRT_NONSTDC_DEPRECATE(_dup) _CRTIMP int __cdecl dup(_In_ int _FileHandle);
309 _Check_return_ _CRT_NONSTDC_DEPRECATE(_dup2) _CRTIMP int __cdecl dup2(_In_ int _FileHandleSrc, _In_ int _FileHandleDst);
310 _Check_return_ _CRT_NONSTDC_DEPRECATE(_eof) _CRTIMP int __cdecl eof(_In_ int _FileHandle);
311 _Check_return_ _CRT_NONSTDC_DEPRECATE(_filelength) _CRTIMP long __cdecl filelength(_In_ int _FileHandle);
312 _Check_return_ _CRT_NONSTDC_DEPRECATE(_isatty) _CRTIMP int __cdecl isatty(_In_ int _FileHandle);
313 _Check_return_ _CRT_NONSTDC_DEPRECATE(_locking) _CRTIMP int __cdecl locking(_In_ int _FileHandle, _In_ int _LockMode, _In_ long _NumOfBytes);
314 _Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_lseek) _CRTIMP long __cdecl lseek(_In_ int _FileHandle, _In_ long _Offset, _In_ int _Origin);
315 _CRT_NONSTDC_DEPRECATE(_mktemp) _CRT_INSECURE_DEPRECATE(_mktemp_s) _CRTIMP char * __cdecl mktemp(_Inout_z_ char * _TemplateName);
316 _Check_return_ _CRT_NONSTDC_DEPRECATE(_open) _CRT_INSECURE_DEPRECATE(_sopen_s) _CRTIMP int __cdecl open(_In_z_ const char * _Filename, _In_ int _OpenFlag, ...);
317 _CRT_NONSTDC_DEPRECATE(_read) _CRTIMP int __cdecl read(int _FileHandle, _Out_bytecap_(_MaxCharCount) void * _DstBuf, _In_ unsigned int _MaxCharCount);
318 _Check_return_ _CRT_NONSTDC_DEPRECATE(_setmode) _CRTIMP int __cdecl setmode(_In_ int _FileHandle, _In_ int _Mode);
319 _CRT_NONSTDC_DEPRECATE(_sopen) _CRT_INSECURE_DEPRECATE(_sopen_s) _CRTIMP int __cdecl sopen(const char * _Filename, _In_ int _OpenFlag, _In_ int _ShareFlag, ...);
320 _Check_return_ _CRT_NONSTDC_DEPRECATE(_tell) _CRTIMP long __cdecl tell(_In_ int _FileHandle);
321 _CRT_NONSTDC_DEPRECATE(_umask) _CRT_INSECURE_DEPRECATE(_umask_s) _CRTIMP int __cdecl umask(_In_ int _Mode);
322 _Check_return_ _CRT_NONSTDC_DEPRECATE(_write) _CRTIMP int __cdecl write(_In_ int _Filehandle, _In_bytecount_(_MaxCharCount) const void * _Buf, _In_ unsigned int _MaxCharCount);
323 #pragma warning(pop)
324
325 #endif  /* __STDC__ */
326
327 #ifdef  __cplusplus
328 }
329 #endif
330
331 #endif  /* _POSIX_ */
332
333 #ifdef  _MSC_VER
334 #pragma pack(pop)
335 #endif  /* _MSC_VER */
336
337 #endif  /* _INC_IO */
338