filesystem 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_FILESYSTEM
  10. #define _LIBCPP_FILESYSTEM
  11. /*
  12. filesystem synopsis
  13. namespace std::filesystem {
  14. class path;
  15. void swap(path& lhs, path& rhs) noexcept;
  16. size_t hash_value(const path& p) noexcept;
  17. bool operator==(const path& lhs, const path& rhs) noexcept;
  18. bool operator!=(const path& lhs, const path& rhs) noexcept;
  19. bool operator< (const path& lhs, const path& rhs) noexcept;
  20. bool operator<=(const path& lhs, const path& rhs) noexcept;
  21. bool operator> (const path& lhs, const path& rhs) noexcept;
  22. bool operator>=(const path& lhs, const path& rhs) noexcept;
  23. path operator/ (const path& lhs, const path& rhs);
  24. // fs.path.io operators are friends of path.
  25. template <class charT, class traits>
  26. friend basic_ostream<charT, traits>&
  27. operator<<(basic_ostream<charT, traits>& os, const path& p);
  28. template <class charT, class traits>
  29. friend basic_istream<charT, traits>&
  30. operator>>(basic_istream<charT, traits>& is, path& p);
  31. template <class Source>
  32. path u8path(const Source& source);
  33. template <class InputIterator>
  34. path u8path(InputIterator first, InputIterator last);
  35. class filesystem_error;
  36. class directory_entry;
  37. class directory_iterator;
  38. // enable directory_iterator range-based for statements
  39. directory_iterator begin(directory_iterator iter) noexcept;
  40. directory_iterator end(directory_iterator) noexcept;
  41. class recursive_directory_iterator;
  42. // enable recursive_directory_iterator range-based for statements
  43. recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
  44. recursive_directory_iterator end(recursive_directory_iterator) noexcept;
  45. class file_status;
  46. struct space_info
  47. {
  48. uintmax_t capacity;
  49. uintmax_t free;
  50. uintmax_t available;
  51. };
  52. enum class file_type;
  53. enum class perms;
  54. enum class perm_options;
  55. enum class copy_options;
  56. enum class directory_options;
  57. typedef chrono::time_point<trivial-clock> file_time_type;
  58. // operational functions
  59. path absolute(const path& p);
  60. path absolute(const path& p, error_code &ec);
  61. path canonical(const path& p);
  62. path canonical(const path& p, error_code& ec);
  63. void copy(const path& from, const path& to);
  64. void copy(const path& from, const path& to, error_code& ec);
  65. void copy(const path& from, const path& to, copy_options options);
  66. void copy(const path& from, const path& to, copy_options options,
  67. error_code& ec);
  68. bool copy_file(const path& from, const path& to);
  69. bool copy_file(const path& from, const path& to, error_code& ec);
  70. bool copy_file(const path& from, const path& to, copy_options option);
  71. bool copy_file(const path& from, const path& to, copy_options option,
  72. error_code& ec);
  73. void copy_symlink(const path& existing_symlink, const path& new_symlink);
  74. void copy_symlink(const path& existing_symlink, const path& new_symlink,
  75. error_code& ec) noexcept;
  76. bool create_directories(const path& p);
  77. bool create_directories(const path& p, error_code& ec);
  78. bool create_directory(const path& p);
  79. bool create_directory(const path& p, error_code& ec) noexcept;
  80. bool create_directory(const path& p, const path& attributes);
  81. bool create_directory(const path& p, const path& attributes,
  82. error_code& ec) noexcept;
  83. void create_directory_symlink(const path& to, const path& new_symlink);
  84. void create_directory_symlink(const path& to, const path& new_symlink,
  85. error_code& ec) noexcept;
  86. void create_hard_link(const path& to, const path& new_hard_link);
  87. void create_hard_link(const path& to, const path& new_hard_link,
  88. error_code& ec) noexcept;
  89. void create_symlink(const path& to, const path& new_symlink);
  90. void create_symlink(const path& to, const path& new_symlink,
  91. error_code& ec) noexcept;
  92. path current_path();
  93. path current_path(error_code& ec);
  94. void current_path(const path& p);
  95. void current_path(const path& p, error_code& ec) noexcept;
  96. bool exists(file_status s) noexcept;
  97. bool exists(const path& p);
  98. bool exists(const path& p, error_code& ec) noexcept;
  99. bool equivalent(const path& p1, const path& p2);
  100. bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
  101. uintmax_t file_size(const path& p);
  102. uintmax_t file_size(const path& p, error_code& ec) noexcept;
  103. uintmax_t hard_link_count(const path& p);
  104. uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
  105. bool is_block_file(file_status s) noexcept;
  106. bool is_block_file(const path& p);
  107. bool is_block_file(const path& p, error_code& ec) noexcept;
  108. bool is_character_file(file_status s) noexcept;
  109. bool is_character_file(const path& p);
  110. bool is_character_file(const path& p, error_code& ec) noexcept;
  111. bool is_directory(file_status s) noexcept;
  112. bool is_directory(const path& p);
  113. bool is_directory(const path& p, error_code& ec) noexcept;
  114. bool is_empty(const path& p);
  115. bool is_empty(const path& p, error_code& ec) noexcept;
  116. bool is_fifo(file_status s) noexcept;
  117. bool is_fifo(const path& p);
  118. bool is_fifo(const path& p, error_code& ec) noexcept;
  119. bool is_other(file_status s) noexcept;
  120. bool is_other(const path& p);
  121. bool is_other(const path& p, error_code& ec) noexcept;
  122. bool is_regular_file(file_status s) noexcept;
  123. bool is_regular_file(const path& p);
  124. bool is_regular_file(const path& p, error_code& ec) noexcept;
  125. bool is_socket(file_status s) noexcept;
  126. bool is_socket(const path& p);
  127. bool is_socket(const path& p, error_code& ec) noexcept;
  128. bool is_symlink(file_status s) noexcept;
  129. bool is_symlink(const path& p);
  130. bool is_symlink(const path& p, error_code& ec) noexcept;
  131. file_time_type last_write_time(const path& p);
  132. file_time_type last_write_time(const path& p, error_code& ec) noexcept;
  133. void last_write_time(const path& p, file_time_type new_time);
  134. void last_write_time(const path& p, file_time_type new_time,
  135. error_code& ec) noexcept;
  136. void permissions(const path& p, perms prms,
  137. perm_options opts=perm_options::replace);
  138. void permissions(const path& p, perms prms, error_code& ec) noexcept;
  139. void permissions(const path& p, perms prms, perm_options opts,
  140. error_code& ec);
  141. path proximate(const path& p, error_code& ec);
  142. path proximate(const path& p, const path& base = current_path());
  143. path proximate(const path& p, const path& base, error_code &ec);
  144. path read_symlink(const path& p);
  145. path read_symlink(const path& p, error_code& ec);
  146. path relative(const path& p, error_code& ec);
  147. path relative(const path& p, const path& base=current_path());
  148. path relative(const path& p, const path& base, error_code& ec);
  149. bool remove(const path& p);
  150. bool remove(const path& p, error_code& ec) noexcept;
  151. uintmax_t remove_all(const path& p);
  152. uintmax_t remove_all(const path& p, error_code& ec);
  153. void rename(const path& from, const path& to);
  154. void rename(const path& from, const path& to, error_code& ec) noexcept;
  155. void resize_file(const path& p, uintmax_t size);
  156. void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept;
  157. space_info space(const path& p);
  158. space_info space(const path& p, error_code& ec) noexcept;
  159. file_status status(const path& p);
  160. file_status status(const path& p, error_code& ec) noexcept;
  161. bool status_known(file_status s) noexcept;
  162. file_status symlink_status(const path& p);
  163. file_status symlink_status(const path& p, error_code& ec) noexcept;
  164. path temp_directory_path();
  165. path temp_directory_path(error_code& ec);
  166. path weakly_canonical(path const& p);
  167. path weakly_canonical(path const& p, error_code& ec);
  168. } // namespace std::filesystem
  169. template <>
  170. inline constexpr bool std::ranges::enable_borrowed_range<std::filesystem::directory_iterator> = true;
  171. template <>
  172. inline constexpr bool std::ranges::enable_borrowed_range<std::filesystem::recursive_directory_iterator> = true;
  173. template <>
  174. inline constexpr bool std::ranges::enable_view<std::filesystem::directory_iterator> = true;
  175. template <>
  176. inline constexpr bool std::ranges::enable_view<std::filesystem::recursive_directory_iterator> = true;
  177. */
  178. #include <__config>
  179. #include <__filesystem/copy_options.h>
  180. #include <__filesystem/directory_entry.h>
  181. #include <__filesystem/directory_iterator.h>
  182. #include <__filesystem/directory_options.h>
  183. #include <__filesystem/file_status.h>
  184. #include <__filesystem/file_time_type.h>
  185. #include <__filesystem/file_type.h>
  186. #include <__filesystem/filesystem_error.h>
  187. #include <__filesystem/operations.h>
  188. #include <__filesystem/path.h>
  189. #include <__filesystem/path_iterator.h>
  190. #include <__filesystem/perm_options.h>
  191. #include <__filesystem/perms.h>
  192. #include <__filesystem/recursive_directory_iterator.h>
  193. #include <__filesystem/space_info.h>
  194. #include <__filesystem/u8path.h>
  195. #include <compare>
  196. #include <version>
  197. #if defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
  198. # error "The Filesystem library is not supported since libc++ has been configured with LIBCXX_ENABLE_FILESYSTEM disabled"
  199. #endif
  200. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  201. # pragma GCC system_header
  202. #endif
  203. #endif // _LIBCPP_FILESYSTEM