fs_fwd.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. // Filesystem declarations -*- C++ -*-
  2. // Copyright (C) 2014-2018 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 <chrono>
  30. namespace std _GLIBCXX_VISIBILITY(default)
  31. {
  32. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  33. namespace filesystem
  34. {
  35. #if _GLIBCXX_USE_CXX11_ABI
  36. inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
  37. #endif
  38. /**
  39. * @defgroup filesystem Filesystem
  40. *
  41. * Utilities for performing operations on file systems and their components,
  42. * such as paths, regular files, and directories.
  43. *
  44. * @{
  45. */
  46. class file_status;
  47. _GLIBCXX_BEGIN_NAMESPACE_CXX11
  48. class path;
  49. class filesystem_error;
  50. class directory_entry;
  51. class directory_iterator;
  52. class recursive_directory_iterator;
  53. _GLIBCXX_END_NAMESPACE_CXX11
  54. struct space_info
  55. {
  56. uintmax_t capacity;
  57. uintmax_t free;
  58. uintmax_t available;
  59. };
  60. enum class file_type : signed char {
  61. none = 0, not_found = -1, regular = 1, directory = 2, symlink = 3,
  62. block = 4, character = 5, fifo = 6, socket = 7, unknown = 8
  63. };
  64. /// Bitmask type
  65. enum class copy_options : unsigned short {
  66. none = 0,
  67. skip_existing = 1, overwrite_existing = 2, update_existing = 4,
  68. recursive = 8,
  69. copy_symlinks = 16, skip_symlinks = 32,
  70. directories_only = 64, create_symlinks = 128, create_hard_links = 256
  71. };
  72. constexpr copy_options
  73. operator&(copy_options __x, copy_options __y) noexcept
  74. {
  75. using __utype = typename std::underlying_type<copy_options>::type;
  76. return static_cast<copy_options>(
  77. static_cast<__utype>(__x) & static_cast<__utype>(__y));
  78. }
  79. constexpr copy_options
  80. operator|(copy_options __x, copy_options __y) noexcept
  81. {
  82. using __utype = typename std::underlying_type<copy_options>::type;
  83. return static_cast<copy_options>(
  84. static_cast<__utype>(__x) | static_cast<__utype>(__y));
  85. }
  86. constexpr copy_options
  87. operator^(copy_options __x, copy_options __y) noexcept
  88. {
  89. using __utype = typename std::underlying_type<copy_options>::type;
  90. return static_cast<copy_options>(
  91. static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
  92. }
  93. constexpr copy_options
  94. operator~(copy_options __x) noexcept
  95. {
  96. using __utype = typename std::underlying_type<copy_options>::type;
  97. return static_cast<copy_options>(~static_cast<__utype>(__x));
  98. }
  99. inline copy_options&
  100. operator&=(copy_options& __x, copy_options __y) noexcept
  101. { return __x = __x & __y; }
  102. inline copy_options&
  103. operator|=(copy_options& __x, copy_options __y) noexcept
  104. { return __x = __x | __y; }
  105. inline copy_options&
  106. operator^=(copy_options& __x, copy_options __y) noexcept
  107. { return __x = __x ^ __y; }
  108. /// Bitmask type
  109. enum class perms : unsigned {
  110. none = 0,
  111. owner_read = 0400,
  112. owner_write = 0200,
  113. owner_exec = 0100,
  114. owner_all = 0700,
  115. group_read = 040,
  116. group_write = 020,
  117. group_exec = 010,
  118. group_all = 070,
  119. others_read = 04,
  120. others_write = 02,
  121. others_exec = 01,
  122. others_all = 07,
  123. all = 0777,
  124. set_uid = 04000,
  125. set_gid = 02000,
  126. sticky_bit = 01000,
  127. mask = 07777,
  128. unknown = 0xFFFF,
  129. };
  130. constexpr perms
  131. operator&(perms __x, perms __y) noexcept
  132. {
  133. using __utype = typename std::underlying_type<perms>::type;
  134. return static_cast<perms>(
  135. static_cast<__utype>(__x) & static_cast<__utype>(__y));
  136. }
  137. constexpr perms
  138. operator|(perms __x, perms __y) noexcept
  139. {
  140. using __utype = typename std::underlying_type<perms>::type;
  141. return static_cast<perms>(
  142. static_cast<__utype>(__x) | static_cast<__utype>(__y));
  143. }
  144. constexpr perms
  145. operator^(perms __x, perms __y) noexcept
  146. {
  147. using __utype = typename std::underlying_type<perms>::type;
  148. return static_cast<perms>(
  149. static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
  150. }
  151. constexpr perms
  152. operator~(perms __x) noexcept
  153. {
  154. using __utype = typename std::underlying_type<perms>::type;
  155. return static_cast<perms>(~static_cast<__utype>(__x));
  156. }
  157. inline perms&
  158. operator&=(perms& __x, perms __y) noexcept
  159. { return __x = __x & __y; }
  160. inline perms&
  161. operator|=(perms& __x, perms __y) noexcept
  162. { return __x = __x | __y; }
  163. inline perms&
  164. operator^=(perms& __x, perms __y) noexcept
  165. { return __x = __x ^ __y; }
  166. /// Bitmask type
  167. enum class perm_options : unsigned {
  168. replace = 0x1,
  169. add = 0x2,
  170. remove = 0x4,
  171. nofollow = 0x8
  172. };
  173. constexpr perm_options
  174. operator&(perm_options __x, perm_options __y) noexcept
  175. {
  176. using __utype = typename std::underlying_type<perm_options>::type;
  177. return static_cast<perm_options>(
  178. static_cast<__utype>(__x) & static_cast<__utype>(__y));
  179. }
  180. constexpr perm_options
  181. operator|(perm_options __x, perm_options __y) noexcept
  182. {
  183. using __utype = typename std::underlying_type<perm_options>::type;
  184. return static_cast<perm_options>(
  185. static_cast<__utype>(__x) | static_cast<__utype>(__y));
  186. }
  187. constexpr perm_options
  188. operator^(perm_options __x, perm_options __y) noexcept
  189. {
  190. using __utype = typename std::underlying_type<perm_options>::type;
  191. return static_cast<perm_options>(
  192. static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
  193. }
  194. constexpr perm_options
  195. operator~(perm_options __x) noexcept
  196. {
  197. using __utype = typename std::underlying_type<perm_options>::type;
  198. return static_cast<perm_options>(~static_cast<__utype>(__x));
  199. }
  200. inline perm_options&
  201. operator&=(perm_options& __x, perm_options __y) noexcept
  202. { return __x = __x & __y; }
  203. inline perm_options&
  204. operator|=(perm_options& __x, perm_options __y) noexcept
  205. { return __x = __x | __y; }
  206. inline perm_options&
  207. operator^=(perm_options& __x, perm_options __y) noexcept
  208. { return __x = __x ^ __y; }
  209. // Bitmask type
  210. enum class directory_options : unsigned char {
  211. none = 0, follow_directory_symlink = 1, skip_permission_denied = 2
  212. };
  213. constexpr directory_options
  214. operator&(directory_options __x, directory_options __y) noexcept
  215. {
  216. using __utype = typename std::underlying_type<directory_options>::type;
  217. return static_cast<directory_options>(
  218. static_cast<__utype>(__x) & static_cast<__utype>(__y));
  219. }
  220. constexpr directory_options
  221. operator|(directory_options __x, directory_options __y) noexcept
  222. {
  223. using __utype = typename std::underlying_type<directory_options>::type;
  224. return static_cast<directory_options>(
  225. static_cast<__utype>(__x) | static_cast<__utype>(__y));
  226. }
  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) noexcept
  236. {
  237. using __utype = typename std::underlying_type<directory_options>::type;
  238. return static_cast<directory_options>(~static_cast<__utype>(__x));
  239. }
  240. inline directory_options&
  241. operator&=(directory_options& __x, directory_options __y) noexcept
  242. { return __x = __x & __y; }
  243. inline directory_options&
  244. operator|=(directory_options& __x, directory_options __y) noexcept
  245. { return __x = __x | __y; }
  246. inline directory_options&
  247. operator^=(directory_options& __x, directory_options __y) noexcept
  248. { return __x = __x ^ __y; }
  249. using file_time_type = std::chrono::system_clock::time_point;
  250. // operational functions
  251. void copy(const path& __from, const path& __to, copy_options __options);
  252. void copy(const path& __from, const path& __to, copy_options __options,
  253. error_code&);
  254. bool copy_file(const path& __from, const path& __to, copy_options __option);
  255. bool copy_file(const path& __from, const path& __to, copy_options __option,
  256. error_code&);
  257. path current_path();
  258. bool exists(file_status) noexcept;
  259. bool is_other(file_status) noexcept;
  260. uintmax_t file_size(const path&);
  261. uintmax_t file_size(const path&, error_code&) noexcept;
  262. uintmax_t hard_link_count(const path&);
  263. uintmax_t hard_link_count(const path&, error_code&) noexcept;
  264. file_time_type last_write_time(const path&);
  265. file_time_type last_write_time(const path&, error_code&) noexcept;
  266. void permissions(const path&, perms, perm_options, error_code&) noexcept;
  267. path proximate(const path& __p, const path& __base, error_code& __ec);
  268. path proximate(const path& __p, const path& __base, error_code& __ec);
  269. path relative(const path& __p, const path& __base, error_code& __ec);
  270. file_status status(const path&);
  271. file_status status(const path&, error_code&) noexcept;
  272. bool status_known(file_status) noexcept;
  273. file_status symlink_status(const path&);
  274. file_status symlink_status(const path&, error_code&) noexcept;
  275. bool is_regular_file(file_status) noexcept;
  276. bool is_symlink(file_status) noexcept;
  277. // @} group filesystem
  278. } // namespace filesystem
  279. _GLIBCXX_END_NAMESPACE_VERSION
  280. } // namespace std
  281. #endif // C++17
  282. #endif // _GLIBCXX_FS_FWD_H