file_management.hpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /*
  2. * Copyright 2010 Vicente J. Botet Escriba
  3. * Copyright 2015 Andrey Semashev
  4. * Copyright 2016 Jorge Lodos
  5. * Copyright 2017 James E. King, III
  6. *
  7. * Distributed under the Boost Software License, Version 1.0.
  8. * See http://www.boost.org/LICENSE_1_0.txt
  9. */
  10. #ifndef BOOST_WINAPI_FILE_MANAGEMENT_HPP_INCLUDED_
  11. #define BOOST_WINAPI_FILE_MANAGEMENT_HPP_INCLUDED_
  12. #include <boost/winapi/basic_types.hpp>
  13. #include <boost/winapi/limits.hpp>
  14. #include <boost/winapi/time.hpp>
  15. #include <boost/winapi/overlapped.hpp>
  16. #include <boost/winapi/detail/header.hpp>
  17. #ifdef BOOST_HAS_PRAGMA_ONCE
  18. #pragma once
  19. #endif
  20. /*
  21. * UWP:
  22. * API SDK 8 SDK 10 _WIN32_WINNT
  23. * AreFileApisANSI DESKTOP - DESKTOP | SYSTEM
  24. * CreateFile DESKTOP - DESKTOP | SYSTEM
  25. * DeleteFile APP - APP | SYSTEM
  26. * FindClose APP - APP | SYSTEM
  27. * FindFirstFile DESKTOP > APP | SYSTEM
  28. * FindNextFile DESKTOP > APP | SYSTEM
  29. * GetFileAttributes DESKTOP > APP | SYSTEM
  30. * GetFileInformationByHandle DESKTOP - DESKTOP | SYSTEM
  31. * GetFileSizeEx DESKTOP > APP | SYSTEM
  32. * LockFile DESKTOP - DESKTOP | SYSTEM
  33. * MoveFileEx APP - APP | SYSTEM
  34. * ReadFile APP - APP | SYSTEM
  35. * SetEndOfFile APP - APP | SYSTEM
  36. * SetFilePointer DESKTOP > APP | SYSTEM
  37. * SetFileValidData DESKTOP - DESKTOP | SYSTEM >= 0x0501
  38. * UnlockFile DESKTOP - DESKTOP | SYSTEM
  39. * WriteFile APP - APP | SYSTEM
  40. */
  41. #if !defined( BOOST_USE_WINDOWS_H )
  42. extern "C" {
  43. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  44. #if !defined( BOOST_NO_ANSI_APIS )
  45. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  46. AreFileApisANSI(BOOST_WINAPI_DETAIL_VOID);
  47. BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  48. CreateFileA(
  49. boost::winapi::LPCSTR_ lpFileName,
  50. boost::winapi::DWORD_ dwDesiredAccess,
  51. boost::winapi::DWORD_ dwShareMode,
  52. ::_SECURITY_ATTRIBUTES* lpSecurityAttributes,
  53. boost::winapi::DWORD_ dwCreationDisposition,
  54. boost::winapi::DWORD_ dwFlagsAndAttributes,
  55. boost::winapi::HANDLE_ hTemplateFile);
  56. struct _WIN32_FIND_DATAA;
  57. BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  58. FindFirstFileA(boost::winapi::LPCSTR_ lpFileName, ::_WIN32_FIND_DATAA* lpFindFileData);
  59. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  60. FindNextFileA(boost::winapi::HANDLE_ hFindFile, ::_WIN32_FIND_DATAA* lpFindFileData);
  61. #endif
  62. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  63. CreateFileW(
  64. boost::winapi::LPCWSTR_ lpFileName,
  65. boost::winapi::DWORD_ dwDesiredAccess,
  66. boost::winapi::DWORD_ dwShareMode,
  67. ::_SECURITY_ATTRIBUTES* lpSecurityAttributes,
  68. boost::winapi::DWORD_ dwCreationDisposition,
  69. boost::winapi::DWORD_ dwFlagsAndAttributes,
  70. boost::winapi::HANDLE_ hTemplateFile);
  71. struct _WIN32_FIND_DATAW;
  72. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  73. FindFirstFileW(boost::winapi::LPCWSTR_ lpFileName, ::_WIN32_FIND_DATAW* lpFindFileData);
  74. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  75. FindNextFileW(boost::winapi::HANDLE_ hFindFile, ::_WIN32_FIND_DATAW* lpFindFileData);
  76. struct _BY_HANDLE_FILE_INFORMATION;
  77. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  78. GetFileInformationByHandle(
  79. boost::winapi::HANDLE_ hFile,
  80. ::_BY_HANDLE_FILE_INFORMATION* lpFileInformation);
  81. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  82. LockFile(
  83. boost::winapi::HANDLE_ hFile,
  84. boost::winapi::DWORD_ dwFileOffsetLow,
  85. boost::winapi::DWORD_ dwFileOffsetHigh,
  86. boost::winapi::DWORD_ nNumberOfBytesToLockLow,
  87. boost::winapi::DWORD_ nNumberOfBytesToLockHigh);
  88. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  89. LockFileEx(
  90. boost::winapi::HANDLE_ hFile,
  91. boost::winapi::DWORD_ dwFlags,
  92. boost::winapi::DWORD_ dwReserved,
  93. boost::winapi::DWORD_ nNumberOfBytesToLockLow,
  94. boost::winapi::DWORD_ nNumberOfBytesToLockHigh,
  95. ::_OVERLAPPED* lpOverlapped);
  96. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WINXP
  97. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  98. SetFileValidData(
  99. boost::winapi::HANDLE_ hFile,
  100. boost::winapi::LONGLONG_ ValidDataLength);
  101. #endif
  102. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  103. UnlockFile(
  104. boost::winapi::HANDLE_ hFile,
  105. boost::winapi::DWORD_ dwFileOffsetLow,
  106. boost::winapi::DWORD_ dwFileOffsetHigh,
  107. boost::winapi::DWORD_ nNumberOfBytesToUnlockLow,
  108. boost::winapi::DWORD_ nNumberOfBytesToUnlockHigh);
  109. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  110. UnlockFileEx(
  111. boost::winapi::HANDLE_ hFile,
  112. boost::winapi::DWORD_ dwReserved,
  113. boost::winapi::DWORD_ nNumberOfBytesToUnlockLow,
  114. boost::winapi::DWORD_ nNumberOfBytesToUnlockHigh,
  115. ::_OVERLAPPED* lpOverlapped);
  116. #endif
  117. #if BOOST_WINAPI_PARTITION_APP || BOOST_WINAPI_PARTITION_SYSTEM
  118. #if !defined( BOOST_NO_ANSI_APIS )
  119. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  120. DeleteFileA(boost::winapi::LPCSTR_ lpFileName);
  121. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  122. MoveFileExA(
  123. boost::winapi::LPCSTR_ lpExistingFileName,
  124. boost::winapi::LPCSTR_ lpNewFileName,
  125. boost::winapi::DWORD_ dwFlags);
  126. #endif
  127. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  128. DeleteFileW(boost::winapi::LPCWSTR_ lpFileName);
  129. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  130. FindClose(boost::winapi::HANDLE_ hFindFile);
  131. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  132. MoveFileExW(
  133. boost::winapi::LPCWSTR_ lpExistingFileName,
  134. boost::winapi::LPCWSTR_ lpNewFileName,
  135. boost::winapi::DWORD_ dwFlags);
  136. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  137. ReadFile(
  138. boost::winapi::HANDLE_ hFile,
  139. boost::winapi::LPVOID_ lpBuffer,
  140. boost::winapi::DWORD_ nNumberOfBytesToRead,
  141. boost::winapi::LPDWORD_ lpNumberOfBytesRead,
  142. ::_OVERLAPPED* lpOverlapped);
  143. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  144. SetEndOfFile(boost::winapi::HANDLE_ hFile);
  145. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  146. WriteFile(
  147. boost::winapi::HANDLE_ hFile,
  148. boost::winapi::LPCVOID_ lpBuffer,
  149. boost::winapi::DWORD_ nNumberOfBytesToWrite,
  150. boost::winapi::LPDWORD_ lpNumberOfBytesWritten,
  151. ::_OVERLAPPED* lpOverlapped);
  152. #endif // BOOST_WINAPI_PARTITION_APP || BOOST_WINAPI_PARTITION_SYSTEM
  153. #if BOOST_WINAPI_PARTITION_APP_SYSTEM
  154. #if !defined( BOOST_NO_ANSI_APIS )
  155. BOOST_WINAPI_IMPORT boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
  156. GetFileAttributesA(boost::winapi::LPCSTR_ lpFileName);
  157. #endif
  158. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
  159. GetFileAttributesW(boost::winapi::LPCWSTR_ lpFileName);
  160. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  161. GetFileSizeEx(boost::winapi::HANDLE_ hFile, ::_LARGE_INTEGER* lpFileSize);
  162. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
  163. SetFilePointer(
  164. boost::winapi::HANDLE_ hFile,
  165. boost::winapi::LONG_ lpDistanceToMove,
  166. boost::winapi::PLONG_ lpDistanceToMoveHigh,
  167. boost::winapi::DWORD_ dwMoveMethod);
  168. #endif // BOOST_WINAPI_PARTITION_APP_SYSTEM
  169. } // extern "C"
  170. #endif // !defined(BOOST_USE_WINDOWS_H)
  171. namespace boost {
  172. namespace winapi {
  173. #if defined( BOOST_USE_WINDOWS_H )
  174. BOOST_CONSTEXPR_OR_CONST DWORD_ INVALID_FILE_SIZE_ = INVALID_FILE_SIZE;
  175. BOOST_CONSTEXPR_OR_CONST DWORD_ INVALID_SET_FILE_POINTER_ = INVALID_SET_FILE_POINTER;
  176. BOOST_CONSTEXPR_OR_CONST DWORD_ INVALID_FILE_ATTRIBUTES_ = INVALID_FILE_ATTRIBUTES;
  177. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_READONLY_ = FILE_ATTRIBUTE_READONLY;
  178. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_HIDDEN_ = FILE_ATTRIBUTE_HIDDEN;
  179. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_SYSTEM_ = FILE_ATTRIBUTE_SYSTEM;
  180. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_DIRECTORY_ = FILE_ATTRIBUTE_DIRECTORY;
  181. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_ARCHIVE_ = FILE_ATTRIBUTE_ARCHIVE;
  182. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_DEVICE_ = FILE_ATTRIBUTE_DEVICE;
  183. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_NORMAL_ = FILE_ATTRIBUTE_NORMAL;
  184. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_TEMPORARY_ = FILE_ATTRIBUTE_TEMPORARY;
  185. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_SPARSE_FILE_ = FILE_ATTRIBUTE_SPARSE_FILE;
  186. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_REPARSE_POINT_ = FILE_ATTRIBUTE_REPARSE_POINT;
  187. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_COMPRESSED_ = FILE_ATTRIBUTE_COMPRESSED;
  188. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_OFFLINE_ = FILE_ATTRIBUTE_OFFLINE;
  189. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED_ = FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
  190. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_ENCRYPTED_ = FILE_ATTRIBUTE_ENCRYPTED;
  191. BOOST_CONSTEXPR_OR_CONST DWORD_ CREATE_NEW_ = CREATE_NEW;
  192. BOOST_CONSTEXPR_OR_CONST DWORD_ CREATE_ALWAYS_ = CREATE_ALWAYS;
  193. BOOST_CONSTEXPR_OR_CONST DWORD_ OPEN_EXISTING_ = OPEN_EXISTING;
  194. BOOST_CONSTEXPR_OR_CONST DWORD_ OPEN_ALWAYS_ = OPEN_ALWAYS;
  195. BOOST_CONSTEXPR_OR_CONST DWORD_ TRUNCATE_EXISTING_ = TRUNCATE_EXISTING;
  196. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_SHARE_READ_ = FILE_SHARE_READ;
  197. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_SHARE_WRITE_ = FILE_SHARE_WRITE;
  198. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_SHARE_DELETE_ = FILE_SHARE_DELETE;
  199. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_BEGIN_ = FILE_BEGIN;
  200. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_CURRENT_ = FILE_CURRENT;
  201. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_END_ = FILE_END;
  202. #else // defined( BOOST_USE_WINDOWS_H )
  203. BOOST_CONSTEXPR_OR_CONST DWORD_ INVALID_FILE_SIZE_ = ((DWORD_)0xFFFFFFFF);
  204. BOOST_CONSTEXPR_OR_CONST DWORD_ INVALID_SET_FILE_POINTER_ = ((DWORD_)-1);
  205. BOOST_CONSTEXPR_OR_CONST DWORD_ INVALID_FILE_ATTRIBUTES_ = ((DWORD_)-1);
  206. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_READONLY_ = 0x00000001;
  207. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_HIDDEN_ = 0x00000002;
  208. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_SYSTEM_ = 0x00000004;
  209. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_DIRECTORY_ = 0x00000010;
  210. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_ARCHIVE_ = 0x00000020;
  211. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_DEVICE_ = 0x00000040;
  212. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_NORMAL_ = 0x00000080;
  213. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_TEMPORARY_ = 0x00000100;
  214. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_SPARSE_FILE_ = 0x00000200;
  215. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_REPARSE_POINT_ = 0x00000400;
  216. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_COMPRESSED_ = 0x00000800;
  217. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_OFFLINE_ = 0x00001000;
  218. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED_ = 0x00002000;
  219. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_ENCRYPTED_ = 0x00004000;
  220. BOOST_CONSTEXPR_OR_CONST DWORD_ CREATE_NEW_ = 1;
  221. BOOST_CONSTEXPR_OR_CONST DWORD_ CREATE_ALWAYS_ = 2;
  222. BOOST_CONSTEXPR_OR_CONST DWORD_ OPEN_EXISTING_ = 3;
  223. BOOST_CONSTEXPR_OR_CONST DWORD_ OPEN_ALWAYS_ = 4;
  224. BOOST_CONSTEXPR_OR_CONST DWORD_ TRUNCATE_EXISTING_ = 5;
  225. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_SHARE_READ_ = 0x00000001;
  226. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_SHARE_WRITE_ = 0x00000002;
  227. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_SHARE_DELETE_ = 0x00000004;
  228. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_BEGIN_ = 0;
  229. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_CURRENT_ = 1;
  230. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_END_ = 2;
  231. #endif // defined( BOOST_USE_WINDOWS_H )
  232. // Some of these constants are not defined by Windows SDK in MinGW or older MSVC
  233. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_WRITE_THROUGH_ = 0x80000000;
  234. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_OVERLAPPED_ = 0x40000000;
  235. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_NO_BUFFERING_ = 0x20000000;
  236. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_RANDOM_ACCESS_ = 0x10000000;
  237. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_SEQUENTIAL_SCAN_ = 0x08000000;
  238. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_DELETE_ON_CLOSE_ = 0x04000000;
  239. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_BACKUP_SEMANTICS_ = 0x02000000;
  240. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_POSIX_SEMANTICS_ = 0x01000000;
  241. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_SESSION_AWARE_ = 0x00800000;
  242. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_OPEN_REPARSE_POINT_ = 0x00200000;
  243. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_OPEN_NO_RECALL_ = 0x00100000;
  244. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_FIRST_PIPE_INSTANCE_ = 0x00080000;
  245. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN8
  246. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_FLAG_OPEN_REQUIRING_OPLOCK_ = 0x00040000;
  247. #endif
  248. // This constant is not defined in Windows SDK up until 6.0A
  249. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_VIRTUAL_ = 0x00010000;
  250. // These constants are not defined in Windows SDK up until 8.0 and MinGW/MinGW-w64 (as of 2016-02-14).
  251. // They are documented to be supported only since Windows 8/Windows Server 2012
  252. // but defined unconditionally.
  253. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_INTEGRITY_STREAM_ = 0x00008000;
  254. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_NO_SCRUB_DATA_ = 0x00020000;
  255. // Undocumented
  256. BOOST_CONSTEXPR_OR_CONST DWORD_ FILE_ATTRIBUTE_EA_ = 0x00040000;
  257. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  258. #if !defined( BOOST_NO_ANSI_APIS )
  259. using ::AreFileApisANSI;
  260. BOOST_FORCEINLINE HANDLE_ CreateFileA(
  261. LPCSTR_ lpFileName,
  262. DWORD_ dwDesiredAccess,
  263. DWORD_ dwShareMode,
  264. SECURITY_ATTRIBUTES_* lpSecurityAttributes,
  265. DWORD_ dwCreationDisposition,
  266. DWORD_ dwFlagsAndAttributes,
  267. HANDLE_ hTemplateFile)
  268. {
  269. return ::CreateFileA(
  270. lpFileName,
  271. dwDesiredAccess,
  272. dwShareMode,
  273. reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes),
  274. dwCreationDisposition,
  275. dwFlagsAndAttributes,
  276. hTemplateFile);
  277. }
  278. BOOST_FORCEINLINE HANDLE_ create_file(
  279. LPCSTR_ lpFileName,
  280. DWORD_ dwDesiredAccess,
  281. DWORD_ dwShareMode,
  282. SECURITY_ATTRIBUTES_* lpSecurityAttributes,
  283. DWORD_ dwCreationDisposition,
  284. DWORD_ dwFlagsAndAttributes,
  285. HANDLE_ hTemplateFile)
  286. {
  287. return ::CreateFileA(
  288. lpFileName,
  289. dwDesiredAccess,
  290. dwShareMode,
  291. reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes),
  292. dwCreationDisposition,
  293. dwFlagsAndAttributes,
  294. hTemplateFile);
  295. }
  296. typedef struct BOOST_MAY_ALIAS _WIN32_FIND_DATAA {
  297. DWORD_ dwFileAttributes;
  298. FILETIME_ ftCreationTime;
  299. FILETIME_ ftLastAccessTime;
  300. FILETIME_ ftLastWriteTime;
  301. DWORD_ nFileSizeHigh;
  302. DWORD_ nFileSizeLow;
  303. DWORD_ dwReserved0;
  304. DWORD_ dwReserved1;
  305. CHAR_ cFileName[MAX_PATH_];
  306. CHAR_ cAlternateFileName[14];
  307. #ifdef _MAC
  308. DWORD_ dwFileType;
  309. DWORD_ dwCreatorType;
  310. WORD_ wFinderFlags;
  311. #endif
  312. } WIN32_FIND_DATAA_, *PWIN32_FIND_DATAA_, *LPWIN32_FIND_DATAA_;
  313. BOOST_FORCEINLINE HANDLE_ FindFirstFileA(LPCSTR_ lpFileName, WIN32_FIND_DATAA_* lpFindFileData)
  314. {
  315. return ::FindFirstFileA(lpFileName, reinterpret_cast< ::_WIN32_FIND_DATAA* >(lpFindFileData));
  316. }
  317. BOOST_FORCEINLINE HANDLE_ find_first_file(LPCSTR_ lpFileName, WIN32_FIND_DATAA_* lpFindFileData)
  318. {
  319. return ::FindFirstFileA(lpFileName, reinterpret_cast< ::_WIN32_FIND_DATAA* >(lpFindFileData));
  320. }
  321. BOOST_FORCEINLINE BOOL_ FindNextFileA(HANDLE_ hFindFile, WIN32_FIND_DATAA_* lpFindFileData)
  322. {
  323. return ::FindNextFileA(hFindFile, reinterpret_cast< ::_WIN32_FIND_DATAA* >(lpFindFileData));
  324. }
  325. BOOST_FORCEINLINE BOOL_ find_next_file(HANDLE_ hFindFile, WIN32_FIND_DATAA_* lpFindFileData)
  326. {
  327. return ::FindNextFileA(hFindFile, reinterpret_cast< ::_WIN32_FIND_DATAA* >(lpFindFileData));
  328. }
  329. #endif // !defined( BOOST_NO_ANSI_APIS )
  330. BOOST_FORCEINLINE HANDLE_ CreateFileW(
  331. LPCWSTR_ lpFileName,
  332. DWORD_ dwDesiredAccess,
  333. DWORD_ dwShareMode,
  334. SECURITY_ATTRIBUTES_* lpSecurityAttributes,
  335. DWORD_ dwCreationDisposition,
  336. DWORD_ dwFlagsAndAttributes,
  337. HANDLE_ hTemplateFile)
  338. {
  339. return ::CreateFileW(
  340. lpFileName,
  341. dwDesiredAccess,
  342. dwShareMode,
  343. reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes),
  344. dwCreationDisposition,
  345. dwFlagsAndAttributes,
  346. hTemplateFile);
  347. }
  348. BOOST_FORCEINLINE HANDLE_ create_file(
  349. LPCWSTR_ lpFileName,
  350. DWORD_ dwDesiredAccess,
  351. DWORD_ dwShareMode,
  352. SECURITY_ATTRIBUTES_* lpSecurityAttributes,
  353. DWORD_ dwCreationDisposition,
  354. DWORD_ dwFlagsAndAttributes,
  355. HANDLE_ hTemplateFile)
  356. {
  357. return ::CreateFileW(
  358. lpFileName,
  359. dwDesiredAccess,
  360. dwShareMode,
  361. reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes),
  362. dwCreationDisposition,
  363. dwFlagsAndAttributes,
  364. hTemplateFile);
  365. }
  366. typedef struct BOOST_MAY_ALIAS _WIN32_FIND_DATAW {
  367. DWORD_ dwFileAttributes;
  368. FILETIME_ ftCreationTime;
  369. FILETIME_ ftLastAccessTime;
  370. FILETIME_ ftLastWriteTime;
  371. DWORD_ nFileSizeHigh;
  372. DWORD_ nFileSizeLow;
  373. DWORD_ dwReserved0;
  374. DWORD_ dwReserved1;
  375. WCHAR_ cFileName[MAX_PATH_];
  376. WCHAR_ cAlternateFileName[14];
  377. #ifdef _MAC
  378. DWORD_ dwFileType;
  379. DWORD_ dwCreatorType;
  380. WORD_ wFinderFlags;
  381. #endif
  382. } WIN32_FIND_DATAW_, *PWIN32_FIND_DATAW_, *LPWIN32_FIND_DATAW_;
  383. typedef struct BOOST_MAY_ALIAS _BY_HANDLE_FILE_INFORMATION {
  384. DWORD_ dwFileAttributes;
  385. FILETIME_ ftCreationTime;
  386. FILETIME_ ftLastAccessTime;
  387. FILETIME_ ftLastWriteTime;
  388. DWORD_ dwVolumeSerialNumber;
  389. DWORD_ nFileSizeHigh;
  390. DWORD_ nFileSizeLow;
  391. DWORD_ nNumberOfLinks;
  392. DWORD_ nFileIndexHigh;
  393. DWORD_ nFileIndexLow;
  394. } BY_HANDLE_FILE_INFORMATION_, *PBY_HANDLE_FILE_INFORMATION_, *LPBY_HANDLE_FILE_INFORMATION_;
  395. BOOST_FORCEINLINE HANDLE_ FindFirstFileW(LPCWSTR_ lpFileName, WIN32_FIND_DATAW_* lpFindFileData)
  396. {
  397. return ::FindFirstFileW(lpFileName, reinterpret_cast< ::_WIN32_FIND_DATAW* >(lpFindFileData));
  398. }
  399. BOOST_FORCEINLINE HANDLE_ find_first_file(LPCWSTR_ lpFileName, WIN32_FIND_DATAW_* lpFindFileData)
  400. {
  401. return ::FindFirstFileW(lpFileName, reinterpret_cast< ::_WIN32_FIND_DATAW* >(lpFindFileData));
  402. }
  403. BOOST_FORCEINLINE BOOL_ FindNextFileW(HANDLE_ hFindFile, WIN32_FIND_DATAW_* lpFindFileData)
  404. {
  405. return ::FindNextFileW(hFindFile, reinterpret_cast< ::_WIN32_FIND_DATAW* >(lpFindFileData));
  406. }
  407. BOOST_FORCEINLINE BOOL_ find_next_file(HANDLE_ hFindFile, WIN32_FIND_DATAW_* lpFindFileData)
  408. {
  409. return ::FindNextFileW(hFindFile, reinterpret_cast< ::_WIN32_FIND_DATAW* >(lpFindFileData));
  410. }
  411. BOOST_FORCEINLINE BOOL_ GetFileInformationByHandle(HANDLE_ h, BY_HANDLE_FILE_INFORMATION_* info)
  412. {
  413. return ::GetFileInformationByHandle(h, reinterpret_cast< ::_BY_HANDLE_FILE_INFORMATION* >(info));
  414. }
  415. using ::LockFile;
  416. BOOST_FORCEINLINE BOOL_ LockFileEx(
  417. HANDLE_ hFile,
  418. DWORD_ dwFlags,
  419. DWORD_ dwReserved,
  420. DWORD_ nNumberOfBytesToLockLow,
  421. DWORD_ nNumberOfBytesToLockHigh,
  422. OVERLAPPED_* lpOverlapped)
  423. {
  424. return ::LockFileEx(hFile, dwFlags, dwReserved, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh, reinterpret_cast< ::_OVERLAPPED* >(lpOverlapped));
  425. }
  426. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WINXP
  427. using ::SetFileValidData;
  428. #endif
  429. using ::UnlockFile;
  430. BOOST_FORCEINLINE BOOL_ UnlockFileEx(
  431. HANDLE_ hFile,
  432. DWORD_ dwReserved,
  433. DWORD_ nNumberOfBytesToUnlockLow,
  434. DWORD_ nNumberOfBytesToUnlockHigh,
  435. OVERLAPPED_* lpOverlapped)
  436. {
  437. return ::UnlockFileEx(hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, reinterpret_cast< ::_OVERLAPPED* >(lpOverlapped));
  438. }
  439. #endif // BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  440. #if BOOST_WINAPI_PARTITION_APP || BOOST_WINAPI_PARTITION_SYSTEM
  441. #if !defined( BOOST_NO_ANSI_APIS )
  442. using ::DeleteFileA;
  443. BOOST_FORCEINLINE BOOL_ delete_file(LPCSTR_ lpFileName)
  444. {
  445. return ::DeleteFileA(lpFileName);
  446. }
  447. using ::MoveFileExA;
  448. BOOST_FORCEINLINE BOOL_ move_file(LPCSTR_ lpExistingFileName, LPCSTR_ lpNewFileName, DWORD_ dwFlags)
  449. {
  450. return ::MoveFileExA(lpExistingFileName, lpNewFileName, dwFlags);
  451. }
  452. #endif
  453. using ::DeleteFileW;
  454. BOOST_FORCEINLINE BOOL_ delete_file(LPCWSTR_ lpFileName)
  455. {
  456. return ::DeleteFileW(lpFileName);
  457. }
  458. using ::FindClose;
  459. using ::MoveFileExW;
  460. BOOST_FORCEINLINE BOOL_ move_file(LPCWSTR_ lpExistingFileName, LPCWSTR_ lpNewFileName, DWORD_ dwFlags)
  461. {
  462. return ::MoveFileExW(lpExistingFileName, lpNewFileName, dwFlags);
  463. }
  464. BOOST_FORCEINLINE BOOL_ ReadFile(
  465. HANDLE_ hFile,
  466. LPVOID_ lpBuffer,
  467. DWORD_ nNumberOfBytesToWrite,
  468. LPDWORD_ lpNumberOfBytesWritten,
  469. OVERLAPPED_* lpOverlapped)
  470. {
  471. return ::ReadFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, reinterpret_cast< ::_OVERLAPPED* >(lpOverlapped));
  472. }
  473. using ::SetEndOfFile;
  474. BOOST_FORCEINLINE BOOL_ WriteFile(
  475. HANDLE_ hFile,
  476. LPCVOID_ lpBuffer,
  477. DWORD_ nNumberOfBytesToWrite,
  478. LPDWORD_ lpNumberOfBytesWritten,
  479. OVERLAPPED_* lpOverlapped)
  480. {
  481. return ::WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, reinterpret_cast< ::_OVERLAPPED* >(lpOverlapped));
  482. }
  483. #endif // BOOST_WINAPI_PARTITION_APP || BOOST_WINAPI_PARTITION_SYSTEM
  484. #if BOOST_WINAPI_PARTITION_APP_SYSTEM
  485. #if !defined( BOOST_NO_ANSI_APIS )
  486. using ::GetFileAttributesA;
  487. BOOST_FORCEINLINE DWORD_ get_file_attributes(LPCSTR_ lpFileName)
  488. {
  489. return ::GetFileAttributesA(lpFileName);
  490. }
  491. #endif
  492. using ::GetFileAttributesW;
  493. BOOST_FORCEINLINE DWORD_ get_file_attributes(LPCWSTR_ lpFileName)
  494. {
  495. return ::GetFileAttributesW(lpFileName);
  496. }
  497. BOOST_FORCEINLINE BOOL_ GetFileSizeEx(HANDLE_ hFile, LARGE_INTEGER_* lpFileSize)
  498. {
  499. return ::GetFileSizeEx(hFile, reinterpret_cast< ::_LARGE_INTEGER* >(lpFileSize));
  500. }
  501. using ::SetFilePointer;
  502. #endif // BOOST_WINAPI_PARTITION_APP_SYSTEM
  503. }
  504. }
  505. #include <boost/winapi/detail/footer.hpp>
  506. #endif // BOOST_WINAPI_FILE_MANAGEMENT_HPP_INCLUDED_