blob: aa0cd562e2afbef1807f2fa8d666d8a80d2a89c6 [file] [log] [blame]
Eric Fiselier02cea5e2018-07-27 03:07:09 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Eric Fiselier02cea5e2018-07-27 03:07:09 +00003//
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 Fiselier02cea5e2018-07-27 03:07:09 +00007//
8//===----------------------------------------------------------------------===//
9#ifndef _LIBCPP_FILESYSTEM
10#define _LIBCPP_FILESYSTEM
Louis Dionneb4fce352022-03-25 12:55:36 -040011
Eric Fiselier02cea5e2018-07-27 03:07:09 +000012/*
13 filesystem synopsis
14
Joe Loser9d1c0d42021-10-14 11:53:43 -040015 namespace std::filesystem {
Eric Fiselier02cea5e2018-07-27 03:07:09 +000016
17 class path;
18
19 void swap(path& lhs, path& rhs) noexcept;
20 size_t hash_value(const path& p) noexcept;
21
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;
27 bool operator>=(const path& lhs, const path& rhs) noexcept;
28
29 path operator/ (const path& lhs, const path& rhs);
30
31 // fs.path.io operators are friends of path.
32 template <class charT, class traits>
33 friend basic_ostream<charT, traits>&
34 operator<<(basic_ostream<charT, traits>& os, const path& p);
35
36 template <class charT, class traits>
37 friend basic_istream<charT, traits>&
38 operator>>(basic_istream<charT, traits>& is, path& p);
39
40 template <class Source>
41 path u8path(const Source& source);
42 template <class InputIterator>
43 path u8path(InputIterator first, InputIterator last);
44
45 class filesystem_error;
46 class directory_entry;
47
48 class directory_iterator;
49
50 // enable directory_iterator range-based for statements
51 directory_iterator begin(directory_iterator iter) noexcept;
Joe Loser9d1c0d42021-10-14 11:53:43 -040052 directory_iterator end(directory_iterator) noexcept;
Eric Fiselier02cea5e2018-07-27 03:07:09 +000053
54 class recursive_directory_iterator;
55
56 // enable recursive_directory_iterator range-based for statements
57 recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
Joe Loser9d1c0d42021-10-14 11:53:43 -040058 recursive_directory_iterator end(recursive_directory_iterator) noexcept;
Eric Fiselier02cea5e2018-07-27 03:07:09 +000059
60 class file_status;
61
62 struct space_info
63 {
64 uintmax_t capacity;
65 uintmax_t free;
66 uintmax_t available;
Adrian Vogelsgesangfe1bc752022-07-31 16:12:42 -070067
68 friend bool operator==(const space_info&, const space_info&) = default; // C++20
Eric Fiselier02cea5e2018-07-27 03:07:09 +000069 };
70
71 enum class file_type;
72 enum class perms;
73 enum class perm_options;
74 enum class copy_options;
75 enum class directory_options;
76
77 typedef chrono::time_point<trivial-clock> file_time_type;
78
79 // operational functions
80
81 path absolute(const path& p);
82 path absolute(const path& p, error_code &ec);
83
84 path canonical(const path& p);
85 path canonical(const path& p, error_code& ec);
86
87 void copy(const path& from, const path& to);
88 void copy(const path& from, const path& to, error_code& ec);
89 void copy(const path& from, const path& to, copy_options options);
90 void copy(const path& from, const path& to, copy_options options,
91 error_code& ec);
92
93 bool copy_file(const path& from, const path& to);
94 bool copy_file(const path& from, const path& to, error_code& ec);
95 bool copy_file(const path& from, const path& to, copy_options option);
96 bool copy_file(const path& from, const path& to, copy_options option,
97 error_code& ec);
98
99 void copy_symlink(const path& existing_symlink, const path& new_symlink);
100 void copy_symlink(const path& existing_symlink, const path& new_symlink,
101 error_code& ec) noexcept;
102
103 bool create_directories(const path& p);
104 bool create_directories(const path& p, error_code& ec);
105
106 bool create_directory(const path& p);
107 bool create_directory(const path& p, error_code& ec) noexcept;
108
109 bool create_directory(const path& p, const path& attributes);
110 bool create_directory(const path& p, const path& attributes,
111 error_code& ec) noexcept;
112
113 void create_directory_symlink(const path& to, const path& new_symlink);
114 void create_directory_symlink(const path& to, const path& new_symlink,
115 error_code& ec) noexcept;
116
117 void create_hard_link(const path& to, const path& new_hard_link);
118 void create_hard_link(const path& to, const path& new_hard_link,
119 error_code& ec) noexcept;
120
121 void create_symlink(const path& to, const path& new_symlink);
122 void create_symlink(const path& to, const path& new_symlink,
123 error_code& ec) noexcept;
124
125 path current_path();
126 path current_path(error_code& ec);
127 void current_path(const path& p);
128 void current_path(const path& p, error_code& ec) noexcept;
129
130 bool exists(file_status s) noexcept;
131 bool exists(const path& p);
132 bool exists(const path& p, error_code& ec) noexcept;
133
134 bool equivalent(const path& p1, const path& p2);
135 bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
136
137 uintmax_t file_size(const path& p);
138 uintmax_t file_size(const path& p, error_code& ec) noexcept;
139
140 uintmax_t hard_link_count(const path& p);
141 uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
142
143 bool is_block_file(file_status s) noexcept;
144 bool is_block_file(const path& p);
145 bool is_block_file(const path& p, error_code& ec) noexcept;
146
147 bool is_character_file(file_status s) noexcept;
148 bool is_character_file(const path& p);
149 bool is_character_file(const path& p, error_code& ec) noexcept;
150
151 bool is_directory(file_status s) noexcept;
152 bool is_directory(const path& p);
153 bool is_directory(const path& p, error_code& ec) noexcept;
154
155 bool is_empty(const path& p);
156 bool is_empty(const path& p, error_code& ec) noexcept;
157
158 bool is_fifo(file_status s) noexcept;
159 bool is_fifo(const path& p);
160 bool is_fifo(const path& p, error_code& ec) noexcept;
161
162 bool is_other(file_status s) noexcept;
163 bool is_other(const path& p);
164 bool is_other(const path& p, error_code& ec) noexcept;
165
166 bool is_regular_file(file_status s) noexcept;
167 bool is_regular_file(const path& p);
168 bool is_regular_file(const path& p, error_code& ec) noexcept;
169
170 bool is_socket(file_status s) noexcept;
171 bool is_socket(const path& p);
172 bool is_socket(const path& p, error_code& ec) noexcept;
173
174 bool is_symlink(file_status s) noexcept;
175 bool is_symlink(const path& p);
176 bool is_symlink(const path& p, error_code& ec) noexcept;
177
178 file_time_type last_write_time(const path& p);
179 file_time_type last_write_time(const path& p, error_code& ec) noexcept;
180 void last_write_time(const path& p, file_time_type new_time);
181 void last_write_time(const path& p, file_time_type new_time,
182 error_code& ec) noexcept;
183
184 void permissions(const path& p, perms prms,
185 perm_options opts=perm_options::replace);
186 void permissions(const path& p, perms prms, error_code& ec) noexcept;
187 void permissions(const path& p, perms prms, perm_options opts,
188 error_code& ec);
189
190 path proximate(const path& p, error_code& ec);
191 path proximate(const path& p, const path& base = current_path());
192 path proximate(const path& p, const path& base, error_code &ec);
193
194 path read_symlink(const path& p);
195 path read_symlink(const path& p, error_code& ec);
196
197 path relative(const path& p, error_code& ec);
198 path relative(const path& p, const path& base=current_path());
199 path relative(const path& p, const path& base, error_code& ec);
200
201 bool remove(const path& p);
202 bool remove(const path& p, error_code& ec) noexcept;
203
204 uintmax_t remove_all(const path& p);
205 uintmax_t remove_all(const path& p, error_code& ec);
206
207 void rename(const path& from, const path& to);
208 void rename(const path& from, const path& to, error_code& ec) noexcept;
209
210 void resize_file(const path& p, uintmax_t size);
211 void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept;
212
213 space_info space(const path& p);
214 space_info space(const path& p, error_code& ec) noexcept;
215
216 file_status status(const path& p);
217 file_status status(const path& p, error_code& ec) noexcept;
218
219 bool status_known(file_status s) noexcept;
220
221 file_status symlink_status(const path& p);
222 file_status symlink_status(const path& p, error_code& ec) noexcept;
223
224 path temp_directory_path();
225 path temp_directory_path(error_code& ec);
226
227 path weakly_canonical(path const& p);
228 path weakly_canonical(path const& p, error_code& ec);
229
Joe Loser9d1c0d42021-10-14 11:53:43 -0400230} // namespace std::filesystem
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000231
Joe Loser9d1c0d42021-10-14 11:53:43 -0400232template <>
233inline constexpr bool std::ranges::enable_borrowed_range<std::filesystem::directory_iterator> = true;
234template <>
235inline constexpr bool std::ranges::enable_borrowed_range<std::filesystem::recursive_directory_iterator> = true;
236
237template <>
238inline constexpr bool std::ranges::enable_view<std::filesystem::directory_iterator> = true;
239template <>
240inline constexpr bool std::ranges::enable_view<std::filesystem::recursive_directory_iterator> = true;
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000241
242*/
243
Louis Dionneb4fce352022-03-25 12:55:36 -0400244#include <__assert> // all public C++ headers provide the assertion handler
Nikolas Klauser0d7bb8b2021-12-23 11:55:38 +0100245#include <__config>
Nikolas Klauserd2ef1062021-12-23 12:21:00 +0100246#include <__filesystem/copy_options.h>
247#include <__filesystem/directory_entry.h>
248#include <__filesystem/directory_iterator.h>
249#include <__filesystem/directory_options.h>
250#include <__filesystem/file_status.h>
251#include <__filesystem/file_time_type.h>
252#include <__filesystem/file_type.h>
253#include <__filesystem/filesystem_error.h>
254#include <__filesystem/operations.h>
Nikolas Klauserd2ef1062021-12-23 12:21:00 +0100255#include <__filesystem/path.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500256#include <__filesystem/path_iterator.h>
Nikolas Klauserd2ef1062021-12-23 12:21:00 +0100257#include <__filesystem/perm_options.h>
258#include <__filesystem/perms.h>
259#include <__filesystem/recursive_directory_iterator.h>
260#include <__filesystem/space_info.h>
261#include <__filesystem/u8path.h>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000262#include <version>
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000263
Nikolas Klausera0e0edb2022-06-16 22:43:46 +0200264// standard-mandated includes
265#include <compare>
266
Louis Dionnedb84e122021-01-18 12:18:18 -0500267#if defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
Louis Dionne685c4702022-05-18 13:17:14 -0400268# error "The <filesystem> library is not supported since libc++ has been configured without support for a filesystem."
Louis Dionnedb84e122021-01-18 12:18:18 -0500269#endif
270
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000271#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500272# pragma GCC system_header
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000273#endif
274
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000275#endif // _LIBCPP_FILESYSTEM