fs_fwd.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. // Filesystem declarations -*- C++ -*-
  2. // Copyright (C) 2014-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file include/bits/fs_fwd.h
  21. * This is an internal header file, included by other library headers.
  22. * Do not attempt to use it directly. @headername{filesystem}
  23. */
  24. #ifndef _GLIBCXX_FS_FWD_H
  25. #define _GLIBCXX_FS_FWD_H 1
  26. #if __cplusplus >= 201703L
  27. #include <system_error>
  28. #include <cstdint>
  29. #include <bits/chrono.h>
  30. namespace std _GLIBCXX_VISIBILITY(default)
  31. {
  32. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  33. /// ISO C++ 2017 namespace for File System library
  34. namespace filesystem
  35. {
  36. #if _GLIBCXX_USE_CXX11_ABI
  37. /// @cond undocumented
  38. inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
  39. /// @endcond
  40. #endif
  41. /** @addtogroup filesystem
  42. * @{
  43. */
  44. class file_status;
  45. _GLIBCXX_BEGIN_NAMESPACE_CXX11
  46. class path;
  47. class filesystem_error;
  48. class directory_entry;
  49. class directory_iterator;
  50. class recursive_directory_iterator;
  51. _GLIBCXX_END_NAMESPACE_CXX11
  52. /// Information about free space on a disk
  53. struct space_info
  54. {
  55. uintmax_t capacity;
  56. uintmax_t free;
  57. uintmax_t available;
  58. #if __cpp_impl_three_way_comparison >= 201907L
  59. friend bool operator==(const space_info&, const space_info&) = default;
  60. #endif
  61. };
  62. /// Enumerated type representing the type of a file
  63. enum class file_type : signed char {
  64. none = 0, not_found = -1, regular = 1, directory = 2, symlink = 3,
  65. block = 4, character = 5, fifo = 6, socket = 7, unknown = 8
  66. };
  67. /// Bitmask type controlling effects of `filesystem::copy`
  68. enum class copy_options : unsigned short {
  69. none = 0,
  70. skip_existing = 1, overwrite_existing = 2, update_existing = 4,
  71. recursive = 8,
  72. copy_symlinks = 16, skip_symlinks = 32,
  73. directories_only = 64, create_symlinks = 128, create_hard_links = 256
  74. };
  75. /// @{
  76. /// @relates copy_options
  77. constexpr copy_options
  78. operator&(copy_options __x, copy_options __y) noexcept
  79. {
  80. using __utype = typename std::underlying_type<copy_options>::type;
  81. return static_cast<copy_options>(
  82. static_cast<__utype>(__x) & static_cast<__utype>(__y));
  83. }
  84. constexpr copy_options
  85. operator|(copy_options __x, copy_options __y) noexcept
  86. {
  87. using __utype = typename std::underlying_type<copy_options>::type;
  88. return static_cast<copy_options>(
  89. static_cast<__utype>(__x) | static_cast<__utype>(__y));
  90. }
  91. constexpr copy_options
  92. operator^(copy_options __x, copy_options __y) noexcept
  93. {
  94. using __utype = typename std::underlying_type<copy_options>::type;
  95. return static_cast<copy_options>(
  96. static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
  97. }
  98. constexpr copy_options
  99. operator~(copy_options __x) noexcept
  100. {
  101. using __utype = typename std::underlying_type<copy_options>::type;
  102. return static_cast<copy_options>(~static_cast<__utype>(__x));
  103. }
  104. inline copy_options&
  105. operator&=(copy_options& __x, copy_options __y) noexcept
  106. { return __x = __x & __y; }
  107. inline copy_options&
  108. operator|=(copy_options& __x, copy_options __y) noexcept
  109. { return __x = __x | __y; }
  110. inline copy_options&
  111. operator^=(copy_options& __x, copy_options __y) noexcept
  112. { return __x = __x ^ __y; }
  113. /// @}
  114. /// Bitmask type representing file access permissions
  115. enum class perms : unsigned {
  116. none = 0,
  117. owner_read = 0400,
  118. owner_write = 0200,
  119. owner_exec = 0100,
  120. owner_all = 0700,
  121. group_read = 040,
  122. group_write = 020,
  123. group_exec = 010,
  124. group_all = 070,
  125. others_read = 04,
  126. others_write = 02,
  127. others_exec = 01,
  128. others_all = 07,
  129. all = 0777,
  130. set_uid = 04000,
  131. set_gid = 02000,
  132. sticky_bit = 01000,
  133. mask = 07777,
  134. unknown = 0xFFFF,
  135. };
  136. /// @{
  137. /// @relates perms
  138. constexpr perms
  139. operator&(perms __x, perms __y) noexcept
  140. {
  141. using __utype = typename std::underlying_type<perms>::type;
  142. return static_cast<perms>(
  143. static_cast<__utype>(__x) & static_cast<__utype>(__y));
  144. }
  145. constexpr perms
  146. operator|(perms __x, perms __y) noexcept
  147. {
  148. using __utype = typename std::underlying_type<perms>::type;
  149. return static_cast<perms>(
  150. static_cast<__utype>(__x) | static_cast<__utype>(__y));
  151. }
  152. constexpr perms
  153. operator^(perms __x, perms __y) noexcept
  154. {
  155. using __utype = typename std::underlying_type<perms>::type;
  156. return static_cast<perms>(
  157. static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
  158. }
  159. constexpr perms
  160. operator~(perms __x) noexcept
  161. {
  162. using __utype = typename std::underlying_type<perms>::type;
  163. return static_cast<perms>(~static_cast<__utype>(__x));
  164. }
  165. inline perms&
  166. operator&=(perms& __x, perms __y) noexcept
  167. { return __x = __x & __y; }
  168. inline perms&
  169. operator|=(perms& __x, perms __y) noexcept
  170. { return __x = __x | __y; }
  171. inline perms&
  172. operator^=(perms& __x, perms __y) noexcept
  173. { return __x = __x ^ __y; }
  174. /// @}
  175. /// Bitmask type controlling changes to permissions
  176. enum class perm_options : unsigned {
  177. replace = 0x1,
  178. add = 0x2,
  179. remove = 0x4,
  180. nofollow = 0x8
  181. };
  182. /// @{
  183. /// @relates perm_options
  184. constexpr perm_options
  185. operator&(perm_options __x, perm_options __y) noexcept
  186. {
  187. using __utype = typename std::underlying_type<perm_options>::type;
  188. return static_cast<perm_options>(
  189. static_cast<__utype>(__x) & static_cast<__utype>(__y));
  190. }
  191. constexpr perm_options
  192. operator|(perm_options __x, perm_options __y) noexcept
  193. {
  194. using __utype = typename std::underlying_type<perm_options>::type;
  195. return static_cast<perm_options>(
  196. static_cast<__utype>(__x) | static_cast<__utype>(__y));
  197. }
  198. constexpr perm_options
  199. operator^(perm_options __x, perm_options __y) noexcept
  200. {
  201. using __utype = typename std::underlying_type<perm_options>::type;
  202. return static_cast<perm_options>(
  203. static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
  204. }
  205. constexpr perm_options
  206. operator~(perm_options __x) noexcept
  207. {
  208. using __utype = typename std::underlying_type<perm_options>::type;
  209. return static_cast<perm_options>(~static_cast<__utype>(__x));
  210. }
  211. inline perm_options&
  212. operator&=(perm_options& __x, perm_options __y) noexcept
  213. { return __x = __x & __y; }
  214. inline perm_options&
  215. operator|=(perm_options& __x, perm_options __y) noexcept
  216. { return __x = __x | __y; }
  217. inline perm_options&
  218. operator^=(perm_options& __x, perm_options __y) noexcept
  219. { return __x = __x ^ __y; }
  220. /// @}
  221. /// Bitmask type controlling directory iteration
  222. enum class directory_options : unsigned char {
  223. none = 0, follow_directory_symlink = 1, skip_permission_denied = 2
  224. };
  225. /// @{
  226. /// @relates directory_options
  227. constexpr directory_options
  228. operator&(directory_options __x, directory_options __y) noexcept
  229. {
  230. using __utype = typename std::underlying_type<directory_options>::type;
  231. return static_cast<directory_options>(
  232. static_cast<__utype>(__x) & static_cast<__utype>(__y));
  233. }
  234. constexpr directory_options
  235. operator|(directory_options __x, directory_options __y) noexcept
  236. {
  237. using __utype = typename std::underlying_type<directory_options>::type;
  238. return static_cast<directory_options>(
  239. static_cast<__utype>(__x) | static_cast<__utype>(__y));
  240. }
  241. constexpr directory_options
  242. operator^(directory_options __x, directory_options __y) noexcept
  243. {
  244. using __utype = typename std::underlying_type<directory_options>::type;
  245. return static_cast<directory_options>(
  246. static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
  247. }
  248. constexpr directory_options
  249. operator~(directory_options __x) noexcept
  250. {
  251. using __utype = typename std::underlying_type<directory_options>::type;
  252. return static_cast<directory_options>(~static_cast<__utype>(__x));
  253. }
  254. inline directory_options&
  255. operator&=(directory_options& __x, directory_options __y) noexcept
  256. { return __x = __x & __y; }
  257. inline directory_options&
  258. operator|=(directory_options& __x, directory_options __y) noexcept
  259. { return __x = __x | __y; }
  260. inline directory_options&
  261. operator^=(directory_options& __x, directory_options __y) noexcept
  262. { return __x = __x ^ __y; }
  263. /// @}
  264. /// The type used for file timestamps
  265. using file_time_type = __file_clock::time_point;
  266. // operational functions
  267. void copy(const path& __from, const path& __to, copy_options __options);
  268. void copy(const path& __from, const path& __to, copy_options __options,
  269. error_code&);
  270. bool copy_file(const path& __from, const path& __to, copy_options __option);
  271. bool copy_file(const path& __from, const path& __to, copy_options __option,
  272. error_code&);
  273. path current_path();
  274. bool exists(file_status) noexcept;
  275. bool is_other(file_status) noexcept;
  276. uintmax_t file_size(const path&);
  277. uintmax_t file_size(const path&, error_code&) noexcept;
  278. uintmax_t hard_link_count(const path&);
  279. uintmax_t hard_link_count(const path&, error_code&) noexcept;
  280. file_time_type last_write_time(const path&);
  281. file_time_type last_write_time(const path&, error_code&) noexcept;
  282. void permissions(const path&, perms, perm_options, error_code&) noexcept;
  283. path proximate(const path& __p, const path& __base, error_code& __ec);
  284. path proximate(const path& __p, const path& __base, error_code& __ec);
  285. path relative(const path& __p, const path& __base, error_code& __ec);
  286. file_status status(const path&);
  287. file_status status(const path&, error_code&) noexcept;
  288. bool status_known(file_status) noexcept;
  289. file_status symlink_status(const path&);
  290. file_status symlink_status(const path&, error_code&) noexcept;
  291. bool is_regular_file(file_status) noexcept;
  292. bool is_symlink(file_status) noexcept;
  293. bool remove(const path&, error_code&) noexcept;
  294. uintmax_t remove_all(const path&);
  295. uintmax_t remove_all(const path&, error_code&);
  296. /// @}
  297. } // namespace filesystem
  298. _GLIBCXX_END_NAMESPACE_VERSION
  299. } // namespace std
  300. #endif // C++17
  301. #endif // _GLIBCXX_FS_FWD_H