fs_ops.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. // Filesystem operational functions -*- 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_ops.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_OPS_H
  25. #define _GLIBCXX_FS_OPS_H 1
  26. #if __cplusplus >= 201703L
  27. #include <cstdint>
  28. namespace std _GLIBCXX_VISIBILITY(default)
  29. {
  30. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  31. namespace filesystem
  32. {
  33. /** @addtogroup filesystem
  34. * @{
  35. */
  36. [[nodiscard]]
  37. path absolute(const path& __p);
  38. [[nodiscard]]
  39. path absolute(const path& __p, error_code& __ec);
  40. [[nodiscard]]
  41. path canonical(const path& __p);
  42. [[nodiscard]]
  43. path canonical(const path& __p, error_code& __ec);
  44. inline void
  45. copy(const path& __from, const path& __to)
  46. { copy(__from, __to, copy_options::none); }
  47. inline void
  48. copy(const path& __from, const path& __to, error_code& __ec)
  49. { copy(__from, __to, copy_options::none, __ec); }
  50. void copy(const path& __from, const path& __to, copy_options __options);
  51. void copy(const path& __from, const path& __to, copy_options __options,
  52. error_code& __ec);
  53. inline bool
  54. copy_file(const path& __from, const path& __to)
  55. { return copy_file(__from, __to, copy_options::none); }
  56. inline bool
  57. copy_file(const path& __from, const path& __to, error_code& __ec)
  58. { return copy_file(__from, __to, copy_options::none, __ec); }
  59. bool copy_file(const path& __from, const path& __to, copy_options __option);
  60. bool copy_file(const path& __from, const path& __to, copy_options __option,
  61. error_code& __ec);
  62. void copy_symlink(const path& __existing_symlink, const path& __new_symlink);
  63. void copy_symlink(const path& __existing_symlink, const path& __new_symlink,
  64. error_code& __ec) noexcept;
  65. bool create_directories(const path& __p);
  66. bool create_directories(const path& __p, error_code& __ec);
  67. bool create_directory(const path& __p);
  68. bool create_directory(const path& __p, error_code& __ec) noexcept;
  69. bool create_directory(const path& __p, const path& attributes);
  70. bool create_directory(const path& __p, const path& attributes,
  71. error_code& __ec) noexcept;
  72. void create_directory_symlink(const path& __to, const path& __new_symlink);
  73. void create_directory_symlink(const path& __to, const path& __new_symlink,
  74. error_code& __ec) noexcept;
  75. void create_hard_link(const path& __to, const path& __new_hard_link);
  76. void create_hard_link(const path& __to, const path& __new_hard_link,
  77. error_code& __ec) noexcept;
  78. void create_symlink(const path& __to, const path& __new_symlink);
  79. void create_symlink(const path& __to, const path& __new_symlink,
  80. error_code& __ec) noexcept;
  81. [[nodiscard]]
  82. path current_path();
  83. [[nodiscard]]
  84. path current_path(error_code& __ec);
  85. void current_path(const path& __p);
  86. void current_path(const path& __p, error_code& __ec) noexcept;
  87. [[nodiscard]]
  88. bool
  89. equivalent(const path& __p1, const path& __p2);
  90. [[nodiscard]]
  91. bool
  92. equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept;
  93. [[nodiscard]]
  94. inline bool
  95. exists(file_status __s) noexcept
  96. { return status_known(__s) && __s.type() != file_type::not_found; }
  97. [[nodiscard]]
  98. inline bool
  99. exists(const path& __p)
  100. { return exists(status(__p)); }
  101. [[nodiscard]]
  102. inline bool
  103. exists(const path& __p, error_code& __ec) noexcept
  104. {
  105. auto __s = status(__p, __ec);
  106. if (status_known(__s))
  107. {
  108. __ec.clear();
  109. return __s.type() != file_type::not_found;
  110. }
  111. return false;
  112. }
  113. [[nodiscard]]
  114. uintmax_t file_size(const path& __p);
  115. [[nodiscard]]
  116. uintmax_t file_size(const path& __p, error_code& __ec) noexcept;
  117. [[nodiscard]]
  118. uintmax_t hard_link_count(const path& __p);
  119. [[nodiscard]]
  120. uintmax_t hard_link_count(const path& __p, error_code& __ec) noexcept;
  121. [[nodiscard]]
  122. inline bool
  123. is_block_file(file_status __s) noexcept
  124. { return __s.type() == file_type::block; }
  125. [[nodiscard]]
  126. inline bool
  127. is_block_file(const path& __p)
  128. { return is_block_file(status(__p)); }
  129. [[nodiscard]]
  130. inline bool
  131. is_block_file(const path& __p, error_code& __ec) noexcept
  132. { return is_block_file(status(__p, __ec)); }
  133. [[nodiscard]]
  134. inline bool
  135. is_character_file(file_status __s) noexcept
  136. { return __s.type() == file_type::character; }
  137. [[nodiscard]]
  138. inline bool
  139. is_character_file(const path& __p)
  140. { return is_character_file(status(__p)); }
  141. [[nodiscard]]
  142. inline bool
  143. is_character_file(const path& __p, error_code& __ec) noexcept
  144. { return is_character_file(status(__p, __ec)); }
  145. [[nodiscard]]
  146. inline bool
  147. is_directory(file_status __s) noexcept
  148. { return __s.type() == file_type::directory; }
  149. [[nodiscard]]
  150. inline bool
  151. is_directory(const path& __p)
  152. { return is_directory(status(__p)); }
  153. [[nodiscard]]
  154. inline bool
  155. is_directory(const path& __p, error_code& __ec) noexcept
  156. { return is_directory(status(__p, __ec)); }
  157. [[nodiscard]]
  158. bool is_empty(const path& __p);
  159. [[nodiscard]]
  160. bool is_empty(const path& __p, error_code& __ec);
  161. [[nodiscard]]
  162. inline bool
  163. is_fifo(file_status __s) noexcept
  164. { return __s.type() == file_type::fifo; }
  165. [[nodiscard]]
  166. inline bool
  167. is_fifo(const path& __p)
  168. { return is_fifo(status(__p)); }
  169. [[nodiscard]]
  170. inline bool
  171. is_fifo(const path& __p, error_code& __ec) noexcept
  172. { return is_fifo(status(__p, __ec)); }
  173. [[nodiscard]]
  174. inline bool
  175. is_other(file_status __s) noexcept
  176. {
  177. return exists(__s) && !is_regular_file(__s) && !is_directory(__s)
  178. && !is_symlink(__s);
  179. }
  180. [[nodiscard]]
  181. inline bool
  182. is_other(const path& __p)
  183. { return is_other(status(__p)); }
  184. [[nodiscard]]
  185. inline bool
  186. is_other(const path& __p, error_code& __ec) noexcept
  187. { return is_other(status(__p, __ec)); }
  188. [[nodiscard]]
  189. inline bool
  190. is_regular_file(file_status __s) noexcept
  191. { return __s.type() == file_type::regular; }
  192. [[nodiscard]]
  193. inline bool
  194. is_regular_file(const path& __p)
  195. { return is_regular_file(status(__p)); }
  196. [[nodiscard]]
  197. inline bool
  198. is_regular_file(const path& __p, error_code& __ec) noexcept
  199. { return is_regular_file(status(__p, __ec)); }
  200. [[nodiscard]]
  201. inline bool
  202. is_socket(file_status __s) noexcept
  203. { return __s.type() == file_type::socket; }
  204. [[nodiscard]]
  205. inline bool
  206. is_socket(const path& __p)
  207. { return is_socket(status(__p)); }
  208. [[nodiscard]]
  209. inline bool
  210. is_socket(const path& __p, error_code& __ec) noexcept
  211. { return is_socket(status(__p, __ec)); }
  212. [[nodiscard]]
  213. inline bool
  214. is_symlink(file_status __s) noexcept
  215. { return __s.type() == file_type::symlink; }
  216. [[nodiscard]]
  217. inline bool
  218. is_symlink(const path& __p)
  219. { return is_symlink(symlink_status(__p)); }
  220. [[nodiscard]]
  221. inline bool
  222. is_symlink(const path& __p, error_code& __ec) noexcept
  223. { return is_symlink(symlink_status(__p, __ec)); }
  224. [[nodiscard]]
  225. file_time_type last_write_time(const path& __p);
  226. [[nodiscard]]
  227. file_time_type last_write_time(const path& __p, error_code& __ec) noexcept;
  228. void last_write_time(const path& __p, file_time_type __new_time);
  229. void last_write_time(const path& __p, file_time_type __new_time,
  230. error_code& __ec) noexcept;
  231. void
  232. permissions(const path& __p, perms __prms,
  233. perm_options __opts = perm_options::replace);
  234. inline void
  235. permissions(const path& __p, perms __prms, error_code& __ec) noexcept
  236. { permissions(__p, __prms, perm_options::replace, __ec); }
  237. void
  238. permissions(const path& __p, perms __prms, perm_options __opts,
  239. error_code& __ec) noexcept;
  240. [[nodiscard]]
  241. inline path proximate(const path& __p, error_code& __ec)
  242. { return proximate(__p, current_path(), __ec); }
  243. [[nodiscard]]
  244. path proximate(const path& __p, const path& __base = current_path());
  245. [[nodiscard]]
  246. path proximate(const path& __p, const path& __base, error_code& __ec);
  247. [[nodiscard]]
  248. path read_symlink(const path& __p);
  249. [[nodiscard]]
  250. path read_symlink(const path& __p, error_code& __ec);
  251. [[nodiscard]]
  252. inline path relative(const path& __p, error_code& __ec)
  253. { return relative(__p, current_path(), __ec); }
  254. [[nodiscard]]
  255. path relative(const path& __p, const path& __base = current_path());
  256. [[nodiscard]]
  257. path relative(const path& __p, const path& __base, error_code& __ec);
  258. bool remove(const path& __p);
  259. bool remove(const path& __p, error_code& __ec) noexcept;
  260. uintmax_t remove_all(const path& __p);
  261. uintmax_t remove_all(const path& __p, error_code& __ec);
  262. void rename(const path& __from, const path& __to);
  263. void rename(const path& __from, const path& __to, error_code& __ec) noexcept;
  264. void resize_file(const path& __p, uintmax_t __size);
  265. void resize_file(const path& __p, uintmax_t __size, error_code& __ec) noexcept;
  266. [[nodiscard]]
  267. space_info space(const path& __p);
  268. [[nodiscard]]
  269. space_info space(const path& __p, error_code& __ec) noexcept;
  270. [[nodiscard]]
  271. file_status status(const path& __p);
  272. [[nodiscard]]
  273. file_status status(const path& __p, error_code& __ec) noexcept;
  274. [[nodiscard]]
  275. inline bool status_known(file_status __s) noexcept
  276. { return __s.type() != file_type::none; }
  277. [[nodiscard]]
  278. file_status symlink_status(const path& __p);
  279. [[nodiscard]]
  280. file_status symlink_status(const path& __p, error_code& __ec) noexcept;
  281. [[nodiscard]]
  282. path temp_directory_path();
  283. [[nodiscard]]
  284. path temp_directory_path(error_code& __ec);
  285. [[nodiscard]]
  286. path weakly_canonical(const path& __p);
  287. [[nodiscard]]
  288. path weakly_canonical(const path& __p, error_code& __ec);
  289. /// @} group filesystem
  290. } // namespace filesystem
  291. _GLIBCXX_END_NAMESPACE_VERSION
  292. } // namespace std
  293. #endif // C++17
  294. #endif // _GLIBCXX_FS_OPS_H