blob: d2e6237df3484f4f0f9741487ddb8143d0719c9f [file] [log] [blame]
Eric Fiselier435db152016-06-17 19:46:40 +00001// -*- C++ -*-
2//===--------------------------- filesystem -------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// 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
Eric Fiselier435db152016-06-17 19:46:40 +00007//
8//===----------------------------------------------------------------------===//
9#ifndef _LIBCPP_EXPERIMENTAL_FILESYSTEM
10#define _LIBCPP_EXPERIMENTAL_FILESYSTEM
11/*
12 filesystem synopsis
13
14 namespace std { namespace experimental { namespace filesystem { inline namespace v1 {
15
16 class path;
17
Eric Fiselierd7c4ec82018-07-25 03:41:31 +000018 void swap(path& lhs, path& rhs) noexcept;
19 size_t hash_value(const path& p) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +000020
Eric Fiselierd7c4ec82018-07-25 03:41:31 +000021 bool operator==(const path& lhs, const path& rhs) noexcept;
22 bool operator!=(const path& lhs, const path& rhs) noexcept;
23 bool operator< (const path& lhs, const path& rhs) noexcept;
24 bool operator<=(const path& lhs, const path& rhs) noexcept;
25 bool operator> (const path& lhs, const path& rhs) noexcept;
26 bool operator>=(const path& lhs, const path& rhs) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +000027
28 path operator/ (const path& lhs, const path& rhs);
29
Eric Fiselier2cd75272018-02-04 03:10:53 +000030 // fs.path.io operators are friends of path.
Eric Fiselier435db152016-06-17 19:46:40 +000031 template <class charT, class traits>
Eric Fiselier2cd75272018-02-04 03:10:53 +000032 friend basic_ostream<charT, traits>&
Eric Fiselier435db152016-06-17 19:46:40 +000033 operator<<(basic_ostream<charT, traits>& os, const path& p);
34
35 template <class charT, class traits>
Eric Fiselier2cd75272018-02-04 03:10:53 +000036 friend basic_istream<charT, traits>&
Eric Fiselier435db152016-06-17 19:46:40 +000037 operator>>(basic_istream<charT, traits>& is, path& p);
38
39 template <class Source>
40 path u8path(const Source& source);
41 template <class InputIterator>
42 path u8path(InputIterator first, InputIterator last);
43
44 class filesystem_error;
45 class directory_entry;
46
47 class directory_iterator;
48
49 // enable directory_iterator range-based for statements
50 directory_iterator begin(directory_iterator iter) noexcept;
51 directory_iterator end(const directory_iterator&) noexcept;
52
53 class recursive_directory_iterator;
54
55 // enable recursive_directory_iterator range-based for statements
56 recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
57 recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
58
59 class file_status;
60
61 struct space_info
62 {
63 uintmax_t capacity;
64 uintmax_t free;
65 uintmax_t available;
66 };
67
68 enum class file_type;
69 enum class perms;
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +000070 enum class perm_options;
Eric Fiselier435db152016-06-17 19:46:40 +000071 enum class copy_options;
72 enum class directory_options;
73
74 typedef chrono::time_point<trivial-clock> file_time_type;
75
76 // operational functions
77
Eric Fiselier91a182b2018-04-02 23:03:41 +000078 path absolute(const path& p);
79 path absolute(const path& p, error_code &ec);
Eric Fiselier435db152016-06-17 19:46:40 +000080
Eric Fiselier91a182b2018-04-02 23:03:41 +000081 path canonical(const path& p);
Eric Fiselier435db152016-06-17 19:46:40 +000082 path canonical(const path& p, error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +000083
84 void copy(const path& from, const path& to);
Eric Fiselierd56d5322017-10-30 18:59:59 +000085 void copy(const path& from, const path& to, error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +000086 void copy(const path& from, const path& to, copy_options options);
87 void copy(const path& from, const path& to, copy_options options,
Eric Fiselierd56d5322017-10-30 18:59:59 +000088 error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +000089
90 bool copy_file(const path& from, const path& to);
Eric Fiseliere1164812018-02-04 07:35:36 +000091 bool copy_file(const path& from, const path& to, error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +000092 bool copy_file(const path& from, const path& to, copy_options option);
93 bool copy_file(const path& from, const path& to, copy_options option,
Eric Fiseliere1164812018-02-04 07:35:36 +000094 error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +000095
96 void copy_symlink(const path& existing_symlink, const path& new_symlink);
97 void copy_symlink(const path& existing_symlink, const path& new_symlink,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +000098 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +000099
100 bool create_directories(const path& p);
Eric Fiseliere1164812018-02-04 07:35:36 +0000101 bool create_directories(const path& p, error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +0000102
103 bool create_directory(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000104 bool create_directory(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000105
106 bool create_directory(const path& p, const path& attributes);
107 bool create_directory(const path& p, const path& attributes,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000108 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000109
110 void create_directory_symlink(const path& to, const path& new_symlink);
111 void create_directory_symlink(const path& to, const path& new_symlink,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000112 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000113
114 void create_hard_link(const path& to, const path& new_hard_link);
115 void create_hard_link(const path& to, const path& new_hard_link,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000116 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000117
118 void create_symlink(const path& to, const path& new_symlink);
119 void create_symlink(const path& to, const path& new_symlink,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000120 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000121
122 path current_path();
123 path current_path(error_code& ec);
124 void current_path(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000125 void current_path(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000126
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000127 bool exists(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000128 bool exists(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000129 bool exists(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000130
131 bool equivalent(const path& p1, const path& p2);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000132 bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000133
134 uintmax_t file_size(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000135 uintmax_t file_size(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000136
137 uintmax_t hard_link_count(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000138 uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000139
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000140 bool is_block_file(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000141 bool is_block_file(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000142 bool is_block_file(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000143
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000144 bool is_character_file(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000145 bool is_character_file(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000146 bool is_character_file(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000147
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000148 bool is_directory(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000149 bool is_directory(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000150 bool is_directory(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000151
152 bool is_empty(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000153 bool is_empty(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000154
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000155 bool is_fifo(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000156 bool is_fifo(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000157 bool is_fifo(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000158
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000159 bool is_other(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000160 bool is_other(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000161 bool is_other(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000162
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000163 bool is_regular_file(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000164 bool is_regular_file(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000165 bool is_regular_file(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000166
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000167 bool is_socket(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000168 bool is_socket(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000169 bool is_socket(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000170
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000171 bool is_symlink(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000172 bool is_symlink(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000173 bool is_symlink(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000174
175 file_time_type last_write_time(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000176 file_time_type last_write_time(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000177 void last_write_time(const path& p, file_time_type new_time);
178 void last_write_time(const path& p, file_time_type new_time,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000179 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000180
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000181 void permissions(const path& p, perms prms,
182 perm_options opts=perm_options::replace);
183 void permissions(const path& p, perms prms, error_code& ec) noexcept;
184 void permissions(const path& p, perms prms, perm_options opts,
185 error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +0000186
Eric Fiselier91a182b2018-04-02 23:03:41 +0000187 path proximate(const path& p, error_code& ec);
188 path proximate(const path& p, const path& base = current_path());
189 path proximate(const path& p, const path& base, error_code &ec);
190
Eric Fiselier435db152016-06-17 19:46:40 +0000191 path read_symlink(const path& p);
192 path read_symlink(const path& p, error_code& ec);
193
Eric Fiselier91a182b2018-04-02 23:03:41 +0000194 path relative(const path& p, error_code& ec);
195 path relative(const path& p, const path& base=current_path());
196 path relative(const path& p, const path& base, error_code& ec);
197
Eric Fiselier435db152016-06-17 19:46:40 +0000198 bool remove(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000199 bool remove(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000200
201 uintmax_t remove_all(const path& p);
Eric Fiseliere1164812018-02-04 07:35:36 +0000202 uintmax_t remove_all(const path& p, error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +0000203
204 void rename(const path& from, const path& to);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000205 void rename(const path& from, const path& to, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000206
207 void resize_file(const path& p, uintmax_t size);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000208 void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000209
210 space_info space(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000211 space_info space(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000212
213 file_status status(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000214 file_status status(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000215
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000216 bool status_known(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000217
218 file_status symlink_status(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000219 file_status symlink_status(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000220
Eric Fiselier435db152016-06-17 19:46:40 +0000221 path temp_directory_path();
222 path temp_directory_path(error_code& ec);
223
Eric Fiselier91a182b2018-04-02 23:03:41 +0000224 path weakly_canonical(path const& p);
225 path weakly_canonical(path const& p, error_code& ec);
226
227
Eric Fiselier435db152016-06-17 19:46:40 +0000228} } } } // namespaces std::experimental::filesystem::v1
229
230*/
231
232#include <experimental/__config>
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000233#include <filesystem>
Eric Fiselier435db152016-06-17 19:46:40 +0000234
235#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
236#pragma GCC system_header
237#endif
238
Eric Fiselier3ad58be2018-07-20 01:51:48 +0000239_LIBCPP_PUSH_MACROS
240#include <__undef_macros>
241
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000242#ifndef _LIBCPP_CXX03_LANG
243
Eric Fiselier435db152016-06-17 19:46:40 +0000244#define __cpp_lib_experimental_filesystem 201406
245
246_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM
247
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000248using namespace _VSTD_FS;
Eric Fiselier435db152016-06-17 19:46:40 +0000249
250_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM
251
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000252#endif // !_LIBCPP_CXX03_LANG
253
Eric Fiselier3ad58be2018-07-20 01:51:48 +0000254_LIBCPP_POP_MACROS
255
Eric Fiselier435db152016-06-17 19:46:40 +0000256#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM