24 #include <winpr/winpr.h>
25 #include <winpr/wtypes.h>
29 #include <winpr/error.h>
30 #include <winpr/handle.h>
40 #define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)
41 #define INVALID_FILE_SIZE ((DWORD)0xFFFFFFFF)
42 #define INVALID_SET_FILE_POINTER ((DWORD)-1)
43 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
45 #define FILE_ATTRIBUTE_READONLY 0x00000001u
46 #define FILE_ATTRIBUTE_HIDDEN 0x00000002u
47 #define FILE_ATTRIBUTE_SYSTEM 0x00000004u
48 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010u
49 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020u
50 #define FILE_ATTRIBUTE_DEVICE 0x00000040u
51 #define FILE_ATTRIBUTE_NORMAL 0x00000080u
52 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100u
53 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200u
54 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400u
55 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800u
56 #define FILE_ATTRIBUTE_OFFLINE 0x00001000u
57 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000u
58 #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000u
59 #define FILE_ATTRIBUTE_VIRTUAL 0x00010000u
61 #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
62 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
63 #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
64 #define FILE_NOTIFY_CHANGE_SIZE 0x00000008
65 #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
66 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
67 #define FILE_NOTIFY_CHANGE_CREATION 0x00000040
68 #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
70 #define FILE_ACTION_ADDED 0x00000001
71 #define FILE_ACTION_REMOVED 0x00000002
72 #define FILE_ACTION_MODIFIED 0x00000003
73 #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
74 #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
76 #define FILE_CASE_SENSITIVE_SEARCH 0x00000001
77 #define FILE_CASE_PRESERVED_NAMES 0x00000002
78 #define FILE_UNICODE_ON_DISK 0x00000004
79 #define FILE_PERSISTENT_ACLS 0x00000008
80 #define FILE_FILE_COMPRESSION 0x00000010
81 #define FILE_VOLUME_QUOTAS 0x00000020
82 #define FILE_SUPPORTS_SPARSE_FILES 0x00000040
83 #define FILE_SUPPORTS_REPARSE_POINTS 0x00000080
84 #define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100
85 #define FILE_VOLUME_IS_COMPRESSED 0x00008000
86 #define FILE_SUPPORTS_OBJECT_IDS 0x00010000
87 #define FILE_SUPPORTS_ENCRYPTION 0x00020000
88 #define FILE_NAMED_STREAMS 0x00040000
89 #define FILE_READ_ONLY_VOLUME 0x00080000
90 #define FILE_SEQUENTIAL_WRITE_ONCE 0x00100000
91 #define FILE_SUPPORTS_TRANSACTIONS 0x00200000
92 #define FILE_SUPPORTS_HARD_LINKS 0x00400000
93 #define FILE_SUPPORTS_EXTENDED_ATTRIBUTES 0x00800000
94 #define FILE_SUPPORTS_OPEN_BY_FILE_ID 0x01000000
95 #define FILE_SUPPORTS_USN_JOURNAL 0x02000000
97 #define FILE_FLAG_WRITE_THROUGH 0x80000000
98 #define FILE_FLAG_OVERLAPPED 0x40000000
99 #define FILE_FLAG_NO_BUFFERING 0x20000000
100 #define FILE_FLAG_RANDOM_ACCESS 0x10000000
101 #define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000
102 #define FILE_FLAG_DELETE_ON_CLOSE 0x04000000
103 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000
104 #define FILE_FLAG_POSIX_SEMANTICS 0x01000000
105 #define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000
106 #define FILE_FLAG_OPEN_NO_RECALL 0x00100000
107 #define FILE_FLAG_FIRST_PIPE_INSTANCE 0x00080000
109 #define PAGE_NOACCESS 0x00000001
110 #define PAGE_READONLY 0x00000002
111 #define PAGE_READWRITE 0x00000004
112 #define PAGE_WRITECOPY 0x00000008
113 #define PAGE_EXECUTE 0x00000010
114 #define PAGE_EXECUTE_READ 0x00000020
115 #define PAGE_EXECUTE_READWRITE 0x00000040
116 #define PAGE_EXECUTE_WRITECOPY 0x00000080
117 #define PAGE_GUARD 0x00000100
118 #define PAGE_NOCACHE 0x00000200
119 #define PAGE_WRITECOMBINE 0x00000400
121 #define MEM_COMMIT 0x00001000
122 #define MEM_RESERVE 0x00002000
123 #define MEM_DECOMMIT 0x00004000
124 #define MEM_RELEASE 0x00008000
125 #define MEM_FREE 0x00010000
126 #define MEM_PRIVATE 0x00020000
127 #define MEM_MAPPED 0x00040000
128 #define MEM_RESET 0x00080000
129 #define MEM_TOP_DOWN 0x00100000
130 #define MEM_WRITE_WATCH 0x00200000
131 #define MEM_PHYSICAL 0x00400000
132 #define MEM_4MB_PAGES 0x80000000
133 #define MEM_IMAGE SEC_IMAGE
135 #define SEC_NO_CHANGE 0x00400000
136 #define SEC_FILE 0x00800000
137 #define SEC_IMAGE 0x01000000
138 #define SEC_VLM 0x02000000
139 #define SEC_RESERVE 0x04000000
140 #define SEC_COMMIT 0x08000000
141 #define SEC_NOCACHE 0x10000000
142 #define SEC_WRITECOMBINE 0x40000000
143 #define SEC_LARGE_PAGES 0x80000000
145 #define SECTION_MAP_EXECUTE_EXPLICIT 0x00020
146 #define SECTION_EXTEND_SIZE 0x00010
147 #define SECTION_MAP_READ 0x00004
148 #define SECTION_MAP_WRITE 0x00002
149 #define SECTION_QUERY 0x00001
150 #define SECTION_MAP_EXECUTE 0x00008
151 #define SECTION_ALL_ACCESS 0xF001F
153 #define FILE_MAP_COPY SECTION_QUERY
154 #define FILE_MAP_WRITE SECTION_MAP_WRITE
155 #define FILE_MAP_READ SECTION_MAP_READ
156 #define FILE_MAP_ALL_ACCESS SECTION_ALL_ACCESS
157 #define FILE_MAP_EXECUTE SECTION_MAP_EXECUTE_EXPLICIT
160 #define CREATE_ALWAYS 2
161 #define OPEN_EXISTING 3
162 #define OPEN_ALWAYS 4
163 #define TRUNCATE_EXISTING 5
165 #define FIND_FIRST_EX_CASE_SENSITIVE 0x1
166 #define FIND_FIRST_EX_LARGE_FETCH 0x2
168 #define STD_INPUT_HANDLE (DWORD) - 10
169 #define STD_OUTPUT_HANDLE (DWORD) - 11
170 #define STD_ERROR_HANDLE (DWORD) - 12
173 #define FILE_CURRENT 1
176 #define LOCKFILE_FAIL_IMMEDIATELY 1
177 #define LOCKFILE_EXCLUSIVE_LOCK 2
179 #define MOVEFILE_REPLACE_EXISTING 0x1
180 #define MOVEFILE_COPY_ALLOWED 0x2
181 #define MOVEFILE_DELAY_UNTIL_REBOOT 0x4
182 #define MOVEFILE_WRITE_THROUGH 0x8
183 #define MOVEFILE_CREATE_HARDLINK 0x10
184 #define MOVEFILE_FAIL_IF_NOT_TRACKABLE 0x20
194 DWORD dwFileAttributes;
202 CHAR cFileName[MAX_PATH];
203 CHAR cAlternateFileName[14];
208 DWORD dwFileAttributes;
216 WCHAR cFileName[MAX_PATH];
217 WCHAR cAlternateFileName[14];
222 DWORD dwFileAttributes;
226 DWORD dwVolumeSerialNumber;
229 DWORD nNumberOfLinks;
230 DWORD nFileIndexHigh;
237 FindExInfoMaxInfoLevel
238 } FINDEX_INFO_LEVELS;
242 FindExSearchNameMatch,
243 FindExSearchLimitToDirectories,
244 FindExSearchLimitToDevices,
245 FindExSearchMaxSearchOp
248 typedef VOID (*LPOVERLAPPED_COMPLETION_ROUTINE)(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered,
252 #define WIN32_FIND_DATA WIN32_FIND_DATAW
253 #define PWIN32_FIND_DATA PWIN32_FIND_DATAW
254 #define LPWIN32_FIND_DATA LPWIN32_FIND_DATAW
256 #define WIN32_FIND_DATA WIN32_FIND_DATAA
257 #define PWIN32_FIND_DATA PWIN32_FIND_DATAA
258 #define LPWIN32_FIND_DATA LPWIN32_FIND_DATAA
266 WINPR_ATTR_MALLOC(CloseHandle, 1)
267 WINPR_API HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
268 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
269 DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
270 HANDLE hTemplateFile);
272 WINPR_ATTR_MALLOC(CloseHandle, 1)
273 WINPR_API HANDLE CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
274 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
275 DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
276 HANDLE hTemplateFile);
278 WINPR_API BOOL DeleteFileA(LPCSTR lpFileName);
280 WINPR_API BOOL DeleteFileW(LPCWSTR lpFileName);
282 WINPR_API BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
283 LPDWORD lpNumberOfBytesRead,
LPOVERLAPPED lpOverlapped);
285 WINPR_API BOOL ReadFileEx(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
287 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
290 DWORD nNumberOfBytesToRead, LPDWORD lpReserved,
293 WINPR_API BOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
294 LPDWORD lpNumberOfBytesWritten,
LPOVERLAPPED lpOverlapped);
296 WINPR_API BOOL WriteFileEx(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
298 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
301 DWORD nNumberOfBytesToWrite, LPDWORD lpReserved,
304 WINPR_API BOOL FlushFileBuffers(HANDLE hFile);
308 DWORD dwFileAttributes;
318 GetFileExInfoStandard,
319 GetFileExMaxInfoLevel
320 } GET_FILEEX_INFO_LEVELS;
322 WINPR_API BOOL GetFileAttributesExA(LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId,
323 LPVOID lpFileInformation);
325 WINPR_API DWORD GetFileAttributesA(LPCSTR lpFileName);
327 WINPR_API BOOL GetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId,
328 LPVOID lpFileInformation);
330 WINPR_API DWORD GetFileAttributesW(LPCWSTR lpFileName);
332 WINPR_API BOOL GetFileInformationByHandle(HANDLE hFile,
335 WINPR_API BOOL SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes);
337 WINPR_API BOOL SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes);
339 WINPR_API BOOL SetEndOfFile(HANDLE hFile);
341 WINPR_API DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh);
343 WINPR_API DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh,
346 WINPR_API BOOL SetFilePointerEx(HANDLE hFile,
LARGE_INTEGER liDistanceToMove,
347 PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod);
349 WINPR_API BOOL LockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh,
350 DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh);
352 WINPR_API BOOL LockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved,
353 DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh,
356 WINPR_API BOOL UnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh,
357 DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh);
359 WINPR_API BOOL UnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow,
360 DWORD nNumberOfBytesToUnlockHigh,
LPOVERLAPPED lpOverlapped);
362 WINPR_API BOOL SetFileTime(HANDLE hFile,
const FILETIME* lpCreationTime,
365 WINPR_API BOOL FindClose(HANDLE hFindFile);
367 WINPR_ATTR_MALLOC(FindClose, 1)
368 WINPR_API HANDLE FindFirstFileA(LPCSTR lpFileName,
LPWIN32_FIND_DATAA lpFindFileData);
370 WINPR_ATTR_MALLOC(FindClose, 1)
371 WINPR_API HANDLE FindFirstFileW(LPCWSTR lpFileName,
LPWIN32_FIND_DATAW lpFindFileData);
373 WINPR_ATTR_MALLOC(FindClose, 1)
374 WINPR_API HANDLE FindFirstFileExA(LPCSTR lpFileName, FINDEX_INFO_LEVELS fInfoLevelId,
375 LPVOID lpFindFileData, FINDEX_SEARCH_OPS fSearchOp,
376 LPVOID lpSearchFilter, DWORD dwAdditionalFlags);
378 WINPR_ATTR_MALLOC(FindClose, 1)
379 WINPR_API HANDLE FindFirstFileExW(LPCWSTR lpFileName, FINDEX_INFO_LEVELS fInfoLevelId,
380 LPVOID lpFindFileData, FINDEX_SEARCH_OPS fSearchOp,
381 LPVOID lpSearchFilter, DWORD dwAdditionalFlags);
386 WINPR_API BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
387 WINPR_API BOOL CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
389 WINPR_API BOOL RemoveDirectoryA(LPCSTR lpPathName);
390 WINPR_API BOOL RemoveDirectoryW(LPCWSTR lpPathName);
392 WINPR_API HANDLE GetStdHandle(DWORD nStdHandle);
393 WINPR_API BOOL SetStdHandle(DWORD nStdHandle, HANDLE hHandle);
394 WINPR_API BOOL SetStdHandleEx(DWORD dwStdHandle, HANDLE hNewHandle, HANDLE* phOldHandle);
396 WINPR_API BOOL GetDiskFreeSpaceA(LPCSTR lpRootPathName, LPDWORD lpSectorsPerCluster,
397 LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters,
398 LPDWORD lpTotalNumberOfClusters);
400 WINPR_API BOOL GetDiskFreeSpaceW(LPCWSTR lpRootPathName, LPDWORD lpSectorsPerCluster,
401 LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters,
402 LPDWORD lpTotalNumberOfClusters);
404 WINPR_API BOOL MoveFileExA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, DWORD dwFlags);
406 WINPR_API BOOL MoveFileExW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, DWORD dwFlags);
408 WINPR_API BOOL MoveFileA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName);
410 WINPR_API BOOL MoveFileW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName);
417 #define CreateFile CreateFileW
418 #define DeleteFile DeleteFileW
419 #define FindFirstFile FindFirstFileW
420 #define FindFirstFileEx FindFirstFileExW
421 #define FindNextFile FindNextFileW
422 #define CreateDirectory CreateDirectoryW
423 #define RemoveDirectory RemoveDirectoryW
424 #define GetFileAttributesEx GetFileAttributesExW
425 #define GetFileAttributes GetFileAttributesW
426 #define SetFileAttributes SetFileAttributesW
427 #define GetDiskFreeSpace GetDiskFreeSpaceW
428 #define MoveFileEx MoveFileExW
429 #define MoveFile MoveFileW
431 #define CreateFile CreateFileA
432 #define DeleteFile DeleteFileA
433 #define FindFirstFile FindFirstFileA
434 #define FindFirstFileEx FindFirstFileExA
435 #define FindNextFile FindNextFileA
436 #define CreateDirectory CreateDirectoryA
437 #define RemoveDirectory RemoveDirectoryA
438 #define GetFileAttributesEx GetFileAttributesExA
439 #define GetFileAttributes GetFileAttributesA
440 #define SetFileAttributes SetFileAttributesA
441 #define GetDiskFreeSpace GetDiskFreeSpaceA
442 #define MoveFileEx MoveFileExA
443 #define MoveFile MoveFileA
448 typedef BOOL (*pcIsFileHandled)(LPCSTR lpFileName);
449 typedef HANDLE (*pcCreateFileA)(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
450 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
451 DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
452 HANDLE hTemplateFile);
456 pcIsFileHandled IsHandled;
457 pcCreateFileA CreateFileA;
462 WINPR_API BOOL ValidFileNameComponent(LPCWSTR lpFileName);
471 WINPR_API HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
472 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
473 DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
474 HANDLE hTemplateFile);
476 WINPR_API HANDLE CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
477 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
478 DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
479 HANDLE hTemplateFile);
481 WINPR_API DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh);
483 WINPR_API DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh,
486 WINPR_API HANDLE FindFirstFileA(LPCSTR lpFileName,
LPWIN32_FIND_DATAA lpFindFileData);
487 WINPR_API HANDLE FindFirstFileW(LPCWSTR lpFileName,
LPWIN32_FIND_DATAW lpFindFileData);
489 WINPR_API DWORD GetFullPathNameA(LPCSTR lpFileName, DWORD nBufferLength, LPSTR lpBuffer,
492 WINPR_API BOOL GetDiskFreeSpaceA(LPCSTR lpRootPathName, LPDWORD lpSectorsPerCluster,
493 LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters,
494 LPDWORD lpTotalNumberOfClusters);
496 WINPR_API BOOL GetDiskFreeSpaceW(LPCWSTR lpRootPathName, LPDWORD lpSectorsPerCluster,
497 LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters,
498 LPDWORD lpTotalNumberOfClusters);
500 WINPR_API DWORD GetLogicalDriveStringsA(DWORD nBufferLength, LPSTR lpBuffer);
502 WINPR_API DWORD GetLogicalDriveStringsW(DWORD nBufferLength, LPWSTR lpBuffer);
504 WINPR_API BOOL PathIsDirectoryEmptyA(LPCSTR pszPath);
506 WINPR_API UINT GetACP(
void);
509 #define CreateFile CreateFileW
510 #define FindFirstFile FindFirstFileW
512 #define CreateFile CreateFileA
513 #define FindFirstFile FindFirstFileA
521 #define FindFirstFile FindFirstFileW
523 #define FindFirstFile FindFirstFileA
528 #define WILDCARD_STAR 0x00000001
529 #define WILDCARD_QM 0x00000002
530 #define WILDCARD_DOS 0x00000100
531 #define WILDCARD_DOS_STAR 0x00000110
532 #define WILDCARD_DOS_QM 0x00000120
533 #define WILDCARD_DOS_DOT 0x00000140
540 WINPR_API BOOL FilePatternMatchA(LPCSTR lpFileName, LPCSTR lpPattern);
541 WINPR_API LPSTR FilePatternFindNextWildcardA(LPCSTR lpPattern, DWORD* pFlags);
543 WINPR_API
int UnixChangeFileMode(
const char* filename,
int flags);
545 WINPR_API BOOL IsNamedPipeFileNameA(LPCSTR lpName);
546 WINPR_API
char* GetNamedPipeNameWithoutPrefixA(LPCSTR lpName);
547 WINPR_API
char* GetNamedPipeUnixDomainSocketBaseFilePathA(
void);
548 WINPR_API
char* GetNamedPipeUnixDomainSocketFilePathA(LPCSTR lpName);
550 WINPR_API
int GetNamePipeFileDescriptor(HANDLE hNamedPipe);
551 WINPR_API HANDLE GetFileHandleForFileDescriptor(
int fd);
553 WINPR_ATTR_MALLOC(fclose, 1)
554 WINPR_API FILE* winpr_fopen(const
char* path, const
char* mode);