You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

347 lines
10KB

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