blob: dbc03595d42219ebf7deeb27212e46a85b78eba2 [file] [log] [blame]
Eric Fiselier435db152016-06-17 19:46:40 +00001// -*- C++ -*-
2//===--------------------------- filesystem -------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10#ifndef _LIBCPP_EXPERIMENTAL_FILESYSTEM
11#define _LIBCPP_EXPERIMENTAL_FILESYSTEM
12/*
13 filesystem synopsis
14
15 namespace std { namespace experimental { namespace filesystem { inline namespace v1 {
16
17 class path;
18
Eric Fiselierd7c4ec82018-07-25 03:41:31 +000019 void swap(path& lhs, path& rhs) noexcept;
20 size_t hash_value(const path& p) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +000021
Eric Fiselierd7c4ec82018-07-25 03:41:31 +000022 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;
Eric Fiselier435db152016-06-17 19:46:40 +000028
29 path operator/ (const path& lhs, const path& rhs);
30
Eric Fiselier2cd75272018-02-04 03:10:53 +000031 // fs.path.io operators are friends of path.
Eric Fiselier435db152016-06-17 19:46:40 +000032 template <class charT, class traits>
Eric Fiselier2cd75272018-02-04 03:10:53 +000033 friend basic_ostream<charT, traits>&
Eric Fiselier435db152016-06-17 19:46:40 +000034 operator<<(basic_ostream<charT, traits>& os, const path& p);
35
36 template <class charT, class traits>
Eric Fiselier2cd75272018-02-04 03:10:53 +000037 friend basic_istream<charT, traits>&
Eric Fiselier435db152016-06-17 19:46:40 +000038 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;
52 directory_iterator end(const directory_iterator&) noexcept;
53
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;
58 recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
59
60 class file_status;
61
62 struct space_info
63 {
64 uintmax_t capacity;
65 uintmax_t free;
66 uintmax_t available;
67 };
68
69 enum class file_type;
70 enum class perms;
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +000071 enum class perm_options;
Eric Fiselier435db152016-06-17 19:46:40 +000072 enum class copy_options;
73 enum class directory_options;
74
75 typedef chrono::time_point<trivial-clock> file_time_type;
76
77 // operational functions
78
Eric Fiselier91a182b2018-04-02 23:03:41 +000079 path absolute(const path& p);
80 path absolute(const path& p, error_code &ec);
Eric Fiselier435db152016-06-17 19:46:40 +000081
Eric Fiselier91a182b2018-04-02 23:03:41 +000082 path canonical(const path& p);
Eric Fiselier435db152016-06-17 19:46:40 +000083 path canonical(const path& p, error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +000084
85 void copy(const path& from, const path& to);
Eric Fiselierd56d5322017-10-30 18:59:59 +000086 void copy(const path& from, const path& to, error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +000087 void copy(const path& from, const path& to, copy_options options);
88 void copy(const path& from, const path& to, copy_options options,
Eric Fiselierd56d5322017-10-30 18:59:59 +000089 error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +000090
91 bool copy_file(const path& from, const path& to);
Eric Fiseliere1164812018-02-04 07:35:36 +000092 bool copy_file(const path& from, const path& to, error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +000093 bool copy_file(const path& from, const path& to, copy_options option);
94 bool copy_file(const path& from, const path& to, copy_options option,
Eric Fiseliere1164812018-02-04 07:35:36 +000095 error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +000096
97 void copy_symlink(const path& existing_symlink, const path& new_symlink);
98 void copy_symlink(const path& existing_symlink, const path& new_symlink,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +000099 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000100
101 bool create_directories(const path& p);
Eric Fiseliere1164812018-02-04 07:35:36 +0000102 bool create_directories(const path& p, error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +0000103
104 bool create_directory(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000105 bool create_directory(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000106
107 bool create_directory(const path& p, const path& attributes);
108 bool create_directory(const path& p, const path& attributes,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000109 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000110
111 void create_directory_symlink(const path& to, const path& new_symlink);
112 void create_directory_symlink(const path& to, const path& new_symlink,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000113 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000114
115 void create_hard_link(const path& to, const path& new_hard_link);
116 void create_hard_link(const path& to, const path& new_hard_link,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000117 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000118
119 void create_symlink(const path& to, const path& new_symlink);
120 void create_symlink(const path& to, const path& new_symlink,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000121 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000122
123 path current_path();
124 path current_path(error_code& ec);
125 void current_path(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000126 void current_path(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000127
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000128 bool exists(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000129 bool exists(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000130 bool exists(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000131
132 bool equivalent(const path& p1, const path& p2);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000133 bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000134
135 uintmax_t file_size(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000136 uintmax_t file_size(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000137
138 uintmax_t hard_link_count(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000139 uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000140
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000141 bool is_block_file(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000142 bool is_block_file(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000143 bool is_block_file(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000144
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000145 bool is_character_file(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000146 bool is_character_file(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000147 bool is_character_file(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000148
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000149 bool is_directory(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000150 bool is_directory(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000151 bool is_directory(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000152
153 bool is_empty(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000154 bool is_empty(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000155
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000156 bool is_fifo(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000157 bool is_fifo(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000158 bool is_fifo(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000159
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000160 bool is_other(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000161 bool is_other(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000162 bool is_other(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000163
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000164 bool is_regular_file(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000165 bool is_regular_file(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000166 bool is_regular_file(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000167
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000168 bool is_socket(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000169 bool is_socket(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000170 bool is_socket(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000171
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000172 bool is_symlink(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000173 bool is_symlink(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000174 bool is_symlink(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000175
176 file_time_type last_write_time(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000177 file_time_type last_write_time(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000178 void last_write_time(const path& p, file_time_type new_time);
179 void last_write_time(const path& p, file_time_type new_time,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000180 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000181
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000182 void permissions(const path& p, perms prms,
183 perm_options opts=perm_options::replace);
184 void permissions(const path& p, perms prms, error_code& ec) noexcept;
185 void permissions(const path& p, perms prms, perm_options opts,
186 error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +0000187
Eric Fiselier91a182b2018-04-02 23:03:41 +0000188 path proximate(const path& p, error_code& ec);
189 path proximate(const path& p, const path& base = current_path());
190 path proximate(const path& p, const path& base, error_code &ec);
191
Eric Fiselier435db152016-06-17 19:46:40 +0000192 path read_symlink(const path& p);
193 path read_symlink(const path& p, error_code& ec);
194
Eric Fiselier91a182b2018-04-02 23:03:41 +0000195 path relative(const path& p, error_code& ec);
196 path relative(const path& p, const path& base=current_path());
197 path relative(const path& p, const path& base, error_code& ec);
198
Eric Fiselier435db152016-06-17 19:46:40 +0000199 bool remove(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000200 bool remove(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000201
202 uintmax_t remove_all(const path& p);
Eric Fiseliere1164812018-02-04 07:35:36 +0000203 uintmax_t remove_all(const path& p, error_code& ec);
Eric Fiselier435db152016-06-17 19:46:40 +0000204
205 void rename(const path& from, const path& to);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000206 void rename(const path& from, const path& to, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000207
208 void resize_file(const path& p, uintmax_t size);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000209 void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000210
211 space_info space(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000212 space_info space(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000213
214 file_status status(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000215 file_status status(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000216
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000217 bool status_known(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000218
219 file_status symlink_status(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000220 file_status symlink_status(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000221
Eric Fiselier435db152016-06-17 19:46:40 +0000222 path temp_directory_path();
223 path temp_directory_path(error_code& ec);
224
Eric Fiselier91a182b2018-04-02 23:03:41 +0000225 path weakly_canonical(path const& p);
226 path weakly_canonical(path const& p, error_code& ec);
227
228
Eric Fiselier435db152016-06-17 19:46:40 +0000229} } } } // namespaces std::experimental::filesystem::v1
230
231*/
232
233#include <experimental/__config>
234#include <cstddef>
Eric Fiselierb3b129c2018-07-20 01:44:33 +0000235#include <cstdlib>
Eric Fiselier435db152016-06-17 19:46:40 +0000236#include <chrono>
237#include <iterator>
238#include <iosfwd>
239#include <locale>
240#include <memory>
241#include <stack>
242#include <string>
243#include <system_error>
244#include <utility>
245#include <iomanip> // for quoted
Eric Fiselierb05e1b02016-07-23 03:10:56 +0000246#include <string_view>
Eric Fiselier435db152016-06-17 19:46:40 +0000247
248#include <__debug>
249
250#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
251#pragma GCC system_header
252#endif
253
Eric Fiselier3ad58be2018-07-20 01:51:48 +0000254_LIBCPP_PUSH_MACROS
255#include <__undef_macros>
256
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000257#ifndef _LIBCPP_CXX03_LANG
258
Eric Fiselier435db152016-06-17 19:46:40 +0000259#define __cpp_lib_experimental_filesystem 201406
260
261_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM
262
Eric Fiselier7eba47e2018-07-25 20:51:49 +0000263struct _FilesystemClock {
264#if !defined(_LIBCPP_HAS_NO_INT128)
265 typedef __int128_t rep;
266 typedef nano period;
267#else
268 typedef long long rep;
269 typedef nano period;
270#endif
271
272 typedef chrono::duration<rep, period> duration;
273 typedef chrono::time_point<_FilesystemClock> time_point;
274
275 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
276
277 _LIBCPP_FUNC_VIS static time_point now() noexcept;
278
279 _LIBCPP_INLINE_VISIBILITY
280 static time_t to_time_t(const time_point& __t) noexcept {
281 typedef chrono::duration<rep> __secs;
282 return time_t(
283 chrono::duration_cast<__secs>(__t.time_since_epoch()).count());
284 }
285
286 _LIBCPP_INLINE_VISIBILITY
287 static time_point from_time_t(time_t __t) noexcept {
288 typedef chrono::duration<rep> __secs;
289 return time_point(__secs(__t));
290 }
291};
292
293typedef chrono::time_point<_FilesystemClock> file_time_type;
Eric Fiselier435db152016-06-17 19:46:40 +0000294
295struct _LIBCPP_TYPE_VIS space_info
296{
297 uintmax_t capacity;
298 uintmax_t free;
299 uintmax_t available;
300};
301
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000302enum class _LIBCPP_ENUM_VIS file_type : signed char
Eric Fiselier435db152016-06-17 19:46:40 +0000303{
304 none = 0,
305 not_found = -1,
306 regular = 1,
307 directory = 2,
308 symlink = 3,
309 block = 4,
310 character = 5,
311 fifo = 6,
312 socket = 7,
313 unknown = 8
314};
315
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000316enum class _LIBCPP_ENUM_VIS perms : unsigned
Eric Fiselier435db152016-06-17 19:46:40 +0000317{
318 none = 0,
319
320 owner_read = 0400,
321 owner_write = 0200,
322 owner_exec = 0100,
323 owner_all = 0700,
324
325 group_read = 040,
326 group_write = 020,
327 group_exec = 010,
328 group_all = 070,
329
330 others_read = 04,
331 others_write = 02,
332 others_exec = 01,
333 others_all = 07,
334
335 all = 0777,
336
337 set_uid = 04000,
338 set_gid = 02000,
339 sticky_bit = 01000,
340 mask = 07777,
341 unknown = 0xFFFF,
Eric Fiselier435db152016-06-17 19:46:40 +0000342};
343
344_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000345inline constexpr perms operator&(perms _LHS, perms _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000346{ return static_cast<perms>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); }
347
348_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000349inline constexpr perms operator|(perms _LHS, perms _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000350{ return static_cast<perms>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); }
351
352_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000353inline constexpr perms operator^(perms _LHS, perms _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000354{ return static_cast<perms>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); }
355
356_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000357inline constexpr perms operator~(perms _LHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000358{ return static_cast<perms>(~static_cast<unsigned>(_LHS)); }
359
360_LIBCPP_INLINE_VISIBILITY
361inline perms& operator&=(perms& _LHS, perms _RHS)
362{ return _LHS = _LHS & _RHS; }
363
364_LIBCPP_INLINE_VISIBILITY
365inline perms& operator|=(perms& _LHS, perms _RHS)
366{ return _LHS = _LHS | _RHS; }
367
368_LIBCPP_INLINE_VISIBILITY
369inline perms& operator^=(perms& _LHS, perms _RHS)
370{ return _LHS = _LHS ^ _RHS; }
371
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000372enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
373 replace = 1,
374 add = 2,
375 remove = 4,
376 nofollow = 8
377};
378
379_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000380inline constexpr perm_options operator&(perm_options _LHS, perm_options _RHS)
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000381{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); }
382
383_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000384inline constexpr perm_options operator|(perm_options _LHS, perm_options _RHS)
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000385{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); }
386
387_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000388inline constexpr perm_options operator^(perm_options _LHS, perm_options _RHS)
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000389{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); }
390
391_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000392inline constexpr perm_options operator~(perm_options _LHS)
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000393{ return static_cast<perm_options>(~static_cast<unsigned>(_LHS)); }
394
395_LIBCPP_INLINE_VISIBILITY
396inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS)
397{ return _LHS = _LHS & _RHS; }
398
399_LIBCPP_INLINE_VISIBILITY
400inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS)
401{ return _LHS = _LHS | _RHS; }
402
403_LIBCPP_INLINE_VISIBILITY
404inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS)
405{ return _LHS = _LHS ^ _RHS; }
406
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000407enum class _LIBCPP_ENUM_VIS copy_options : unsigned short
Eric Fiselier435db152016-06-17 19:46:40 +0000408{
409 none = 0,
410 skip_existing = 1,
411 overwrite_existing = 2,
412 update_existing = 4,
413 recursive = 8,
414 copy_symlinks = 16,
415 skip_symlinks = 32,
416 directories_only = 64,
417 create_symlinks = 128,
418 create_hard_links = 256,
419 __in_recursive_copy = 512,
420};
421
422_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000423inline constexpr copy_options operator&(copy_options _LHS, copy_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000424{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) & static_cast<unsigned short>(_RHS)); }
425
426_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000427inline constexpr copy_options operator|(copy_options _LHS, copy_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000428{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) | static_cast<unsigned short>(_RHS)); }
429
430_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000431inline constexpr copy_options operator^(copy_options _LHS, copy_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000432{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^ static_cast<unsigned short>(_RHS)); }
433
434_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000435inline constexpr copy_options operator~(copy_options _LHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000436{ return static_cast<copy_options>(~static_cast<unsigned short>(_LHS)); }
437
438_LIBCPP_INLINE_VISIBILITY
439inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS)
440{ return _LHS = _LHS & _RHS; }
441
442_LIBCPP_INLINE_VISIBILITY
443inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS)
444{ return _LHS = _LHS | _RHS; }
445
446_LIBCPP_INLINE_VISIBILITY
447inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS)
448{ return _LHS = _LHS ^ _RHS; }
449
450
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000451enum class _LIBCPP_ENUM_VIS directory_options : unsigned char
Eric Fiselier435db152016-06-17 19:46:40 +0000452{
453 none = 0,
454 follow_directory_symlink = 1,
455 skip_permission_denied = 2
456};
457
458_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000459inline constexpr directory_options operator&(directory_options _LHS, directory_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000460{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) & static_cast<unsigned char>(_RHS)); }
461
462_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000463inline constexpr directory_options operator|(directory_options _LHS, directory_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000464{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) | static_cast<unsigned char>(_RHS)); }
465
466_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000467inline constexpr directory_options operator^(directory_options _LHS, directory_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000468{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^ static_cast<unsigned char>(_RHS)); }
469
470_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000471inline constexpr directory_options operator~(directory_options _LHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000472{ return static_cast<directory_options>(~static_cast<unsigned char>(_LHS)); }
473
474_LIBCPP_INLINE_VISIBILITY
475inline directory_options& operator&=(directory_options& _LHS, directory_options _RHS)
476{ return _LHS = _LHS & _RHS; }
477
478_LIBCPP_INLINE_VISIBILITY
479inline directory_options& operator|=(directory_options& _LHS, directory_options _RHS)
480{ return _LHS = _LHS | _RHS; }
481
482_LIBCPP_INLINE_VISIBILITY
483inline directory_options& operator^=(directory_options& _LHS, directory_options _RHS)
484{ return _LHS = _LHS ^ _RHS; }
485
486
487class _LIBCPP_TYPE_VIS file_status
488{
489public:
490 // constructors
491 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000492 file_status() noexcept : file_status(file_type::none) {}
Eric Fiselier6afd7e82017-03-06 21:02:06 +0000493 _LIBCPP_INLINE_VISIBILITY
494 explicit file_status(file_type __ft,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000495 perms __prms = perms::unknown) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +0000496 : __ft_(__ft), __prms_(__prms)
497 {}
498
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000499 file_status(const file_status&) noexcept = default;
500 file_status(file_status&&) noexcept = default;
Eric Fiselier435db152016-06-17 19:46:40 +0000501
502 _LIBCPP_INLINE_VISIBILITY
503 ~file_status() {}
504
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000505 file_status& operator=(const file_status&) noexcept = default;
506 file_status& operator=(file_status&&) noexcept = default;
Eric Fiselier435db152016-06-17 19:46:40 +0000507
508 // observers
Louis Dionne16fe2952018-07-11 23:14:33 +0000509 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000510 file_type type() const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000511 return __ft_;
512 }
513
Louis Dionne16fe2952018-07-11 23:14:33 +0000514 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000515 perms permissions() const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000516 return __prms_;
517 }
518
519 // modifiers
Louis Dionne16fe2952018-07-11 23:14:33 +0000520 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000521 void type(file_type __ft) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000522 __ft_ = __ft;
523 }
524
Louis Dionne16fe2952018-07-11 23:14:33 +0000525 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000526 void permissions(perms __p) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000527 __prms_ = __p;
528 }
529private:
530 file_type __ft_;
531 perms __prms_;
532};
533
534class _LIBCPP_TYPE_VIS directory_entry;
535
536template <class _Tp> struct __can_convert_char {
537 static const bool value = false;
538};
Eric Fiselierc355aa32016-08-28 21:26:01 +0000539template <class _Tp> struct __can_convert_char<const _Tp>
540 : public __can_convert_char<_Tp> {
541};
Eric Fiselier435db152016-06-17 19:46:40 +0000542template <> struct __can_convert_char<char> {
543 static const bool value = true;
544 using __char_type = char;
545};
546template <> struct __can_convert_char<wchar_t> {
547 static const bool value = true;
548 using __char_type = wchar_t;
549};
550template <> struct __can_convert_char<char16_t> {
551 static const bool value = true;
552 using __char_type = char16_t;
553};
554template <> struct __can_convert_char<char32_t> {
555 static const bool value = true;
556 using __char_type = char32_t;
557};
558
559template <class _ECharT>
560typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
561__is_separator(_ECharT __e) {
562 return __e == _ECharT('/');
563};
564
565struct _NullSentinal {};
566
567template <class _Tp>
568using _Void = void;
569
570template <class _Tp, class = void>
571struct __is_pathable_string : public false_type {};
572
573template <class _ECharT, class _Traits, class _Alloc>
574struct __is_pathable_string<basic_string<_ECharT, _Traits, _Alloc>,
575 _Void<typename __can_convert_char<_ECharT>::__char_type>>
576: public __can_convert_char<_ECharT>
577{
578 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
579 using _Base = __can_convert_char<_ECharT>;
580 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
581 static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
582 static _ECharT __first_or_null(_Str const& __s) {
583 return __s.empty() ? _ECharT{} : __s[0];
584 }
585};
586
Eric Fiselierb05e1b02016-07-23 03:10:56 +0000587
588template <class _ECharT, class _Traits>
589struct __is_pathable_string<basic_string_view<_ECharT, _Traits>,
590 _Void<typename __can_convert_char<_ECharT>::__char_type>>
591: public __can_convert_char<_ECharT>
592{
593 using _Str = basic_string_view<_ECharT, _Traits>;
594 using _Base = __can_convert_char<_ECharT>;
595 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
596 static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
597 static _ECharT __first_or_null(_Str const& __s) {
598 return __s.empty() ? _ECharT{} : __s[0];
599 }
600};
601
Eric Fiselier435db152016-06-17 19:46:40 +0000602template <class _Source,
603 class _DS = typename decay<_Source>::type,
604 class _UnqualPtrType = typename remove_const<
605 typename remove_pointer<_DS>::type>::type,
606 bool _IsCharPtr = is_pointer<_DS>::value &&
607 __can_convert_char<_UnqualPtrType>::value
608 >
609struct __is_pathable_char_array : false_type {};
610
611template <class _Source, class _ECharT, class _UPtr>
612struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
613 : __can_convert_char<typename remove_const<_ECharT>::type>
614{
615 using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
616
617 static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
618 static _ECharT const* __range_end(const _ECharT* __b)
619 {
620 using _Iter = const _ECharT*;
621 const _ECharT __sentinal = _ECharT{};
622 _Iter __e = __b;
623 for (; *__e != __sentinal; ++__e)
624 ;
625 return __e;
626 }
627
628 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
629};
630
631template <class _Iter, bool _IsIt = __is_input_iterator<_Iter>::value, class = void>
632struct __is_pathable_iter : false_type {};
633
634template <class _Iter>
635struct __is_pathable_iter<_Iter, true,
636 _Void<typename __can_convert_char<typename iterator_traits<_Iter>::value_type>::__char_type>>
637 : __can_convert_char<typename iterator_traits<_Iter>::value_type>
638{
639 using _ECharT = typename iterator_traits<_Iter>::value_type;
640 using _Base = __can_convert_char<_ECharT>;
641
642 static _Iter __range_begin(_Iter __b) { return __b; }
643 static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; }
644
645 static _ECharT __first_or_null(_Iter __b) { return *__b; }
646};
647
648template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
649 bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
650 bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value
651 >
652struct __is_pathable : false_type {
653 static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
654};
655
656template <class _Tp>
657struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
658
659
660template <class _Tp>
661struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {};
662
663
664template <class _Tp>
665struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
666
667
668template <class _ECharT>
669struct _PathCVT {
670 static_assert(__can_convert_char<_ECharT>::value, "Char type not convertible");
671
672 typedef __narrow_to_utf8<sizeof(_ECharT)*__CHAR_BIT__> _Narrower;
673
674 static void __append_range(string& __dest, _ECharT const* __b, _ECharT const* __e) {
675 _Narrower()(back_inserter(__dest), __b, __e);
676 }
677
678 template <class _Iter>
679 static void __append_range(string& __dest, _Iter __b, _Iter __e) {
680 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
681 if (__b == __e) return;
682 basic_string<_ECharT> __tmp(__b, __e);
683 _Narrower()(back_inserter(__dest), __tmp.data(),
684 __tmp.data() + __tmp.length());
685 }
686
687 template <class _Iter>
688 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
689 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
690 const _ECharT __sentinal = _ECharT{};
691 if (*__b == __sentinal) return;
692 basic_string<_ECharT> __tmp;
693 for (; *__b != __sentinal; ++__b)
694 __tmp.push_back(*__b);
695 _Narrower()(back_inserter(__dest), __tmp.data(),
696 __tmp.data() + __tmp.length());
697 }
698
699 template <class _Source>
700 static void __append_source(string& __dest, _Source const& __s)
701 {
702 using _Traits = __is_pathable<_Source>;
703 __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s));
704 }
705};
706
707template <>
708struct _PathCVT<char> {
Eric Fiselier70027d62016-10-30 23:53:50 +0000709
Eric Fiselier435db152016-06-17 19:46:40 +0000710 template <class _Iter>
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +0000711 static typename enable_if<
712 __is_exactly_input_iterator<_Iter>::value
713 >::type __append_range(string& __dest, _Iter __b, _Iter __e) {
714 for (; __b != __e; ++__b)
715 __dest.push_back(*__b);
716 }
717
718 template <class _Iter>
719 static typename enable_if<
720 __is_forward_iterator<_Iter>::value
721 >::type __append_range(string& __dest, _Iter __b, _Iter __e) {
722 __dest.__append_forward_unsafe(__b, __e);
Eric Fiselier435db152016-06-17 19:46:40 +0000723 }
724
725 template <class _Iter>
726 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
727 const char __sentinal = char{};
728 for (; *__b != __sentinal; ++__b)
729 __dest.push_back(*__b);
730 }
731
732 template <class _Source>
733 static void __append_source(string& __dest, _Source const& __s)
734 {
735 using _Traits = __is_pathable<_Source>;
Eric Fiselier70027d62016-10-30 23:53:50 +0000736 __append_range(__dest, _Traits::__range_begin(__s),
737 _Traits::__range_end(__s));
Eric Fiselier435db152016-06-17 19:46:40 +0000738 }
739};
740
741
742class _LIBCPP_TYPE_VIS path
743{
744 template <class _SourceOrIter, class _Tp = path&>
745 using _EnableIfPathable = typename
746 enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
747
748 template <class _Tp>
749 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
750
751 template <class _Tp>
752 using _SourceCVT = _PathCVT<_SourceChar<_Tp>>;
753
754public:
755 typedef char value_type;
756 typedef basic_string<value_type> string_type;
Eric Fiselierb05e1b02016-07-23 03:10:56 +0000757 typedef _VSTD::string_view __string_view;
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000758 static constexpr value_type preferred_separator = '/';
Eric Fiselier435db152016-06-17 19:46:40 +0000759
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000760 enum class _LIBCPP_ENUM_VIS format : unsigned char {
761 auto_format,
762 native_format,
763 generic_format
764 };
765
Eric Fiselier435db152016-06-17 19:46:40 +0000766 // constructors and destructor
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000767 _LIBCPP_INLINE_VISIBILITY path() noexcept {}
Eric Fiselier435db152016-06-17 19:46:40 +0000768 _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000769 _LIBCPP_INLINE_VISIBILITY path(path&& __p) noexcept : __pn_(_VSTD::move(__p.__pn_)) {}
Eric Fiselier435db152016-06-17 19:46:40 +0000770
771 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000772 path(string_type&& __s, format = format::auto_format) noexcept
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000773 : __pn_(_VSTD::move(__s)) {}
Eric Fiselier435db152016-06-17 19:46:40 +0000774
775 template <
776 class _Source,
777 class = _EnableIfPathable<_Source, void>
778 >
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000779 path(const _Source& __src, format = format::auto_format) {
Eric Fiselier435db152016-06-17 19:46:40 +0000780 _SourceCVT<_Source>::__append_source(__pn_, __src);
781 }
782
783 template <class _InputIt>
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000784 path(_InputIt __first, _InputIt __last, format = format::auto_format) {
Eric Fiselier435db152016-06-17 19:46:40 +0000785 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
786 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
787 }
788
789 // TODO Implement locale conversions.
790 template <class _Source,
791 class = _EnableIfPathable<_Source, void>
792 >
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000793 path(const _Source& __src, const locale& __loc,
794 format = format::auto_format);
Eric Fiselier435db152016-06-17 19:46:40 +0000795 template <class _InputIt>
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000796 path(_InputIt __first, _InputIt _last, const locale& __loc,
797 format = format::auto_format);
Eric Fiselier435db152016-06-17 19:46:40 +0000798
799 _LIBCPP_INLINE_VISIBILITY
800 ~path() = default;
801
802 // assignments
803 _LIBCPP_INLINE_VISIBILITY
804 path& operator=(const path& __p) {
805 __pn_ = __p.__pn_;
806 return *this;
807 }
808
809 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000810 path& operator=(path&& __p) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000811 __pn_ = _VSTD::move(__p.__pn_);
812 return *this;
813 }
814
Eric Fiselier8beffc82017-01-18 05:48:55 +0000815 template <class = void>
Eric Fiselier435db152016-06-17 19:46:40 +0000816 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000817 path& operator=(string_type&& __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000818 __pn_ = _VSTD::move(__s);
819 return *this;
820 }
821
822 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000823 path& assign(string_type&& __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000824 __pn_ = _VSTD::move(__s);
825 return *this;
826 }
827
828 template <class _Source>
829 _LIBCPP_INLINE_VISIBILITY
830 _EnableIfPathable<_Source>
831 operator=(const _Source& __src)
832 { return this->assign(__src); }
833
834
835 template <class _Source>
836 _EnableIfPathable<_Source>
837 assign(const _Source& __src) {
838 __pn_.clear();
839 _SourceCVT<_Source>::__append_source(__pn_, __src);
840 return *this;
841 }
842
843 template <class _InputIt>
844 path& assign(_InputIt __first, _InputIt __last) {
845 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
846 __pn_.clear();
847 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
848 return *this;
849 }
850
851private:
852 template <class _ECharT>
Eric Fiselier91a182b2018-04-02 23:03:41 +0000853 static bool __source_is_absolute(_ECharT __first_or_null) {
854 return __is_separator(__first_or_null);
Eric Fiselier435db152016-06-17 19:46:40 +0000855 }
856
857public:
858 // appends
859 path& operator/=(const path& __p) {
Eric Fiselier91a182b2018-04-02 23:03:41 +0000860 if (__p.is_absolute()) {
861 __pn_ = __p.__pn_;
862 return *this;
863 }
864 if (has_filename())
865 __pn_ += preferred_separator;
Eric Fiselier435db152016-06-17 19:46:40 +0000866 __pn_ += __p.native();
867 return *this;
868 }
869
Eric Fiselier91a182b2018-04-02 23:03:41 +0000870 // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
871 // is known at compile time to be "/' since the user almost certainly intended
872 // to append a separator instead of overwriting the path with "/"
Eric Fiselier435db152016-06-17 19:46:40 +0000873 template <class _Source>
874 _LIBCPP_INLINE_VISIBILITY
875 _EnableIfPathable<_Source>
876 operator/=(const _Source& __src) {
877 return this->append(__src);
878 }
879
880 template <class _Source>
881 _EnableIfPathable<_Source>
882 append(const _Source& __src) {
883 using _Traits = __is_pathable<_Source>;
884 using _CVT = _PathCVT<_SourceChar<_Source>>;
Eric Fiselier91a182b2018-04-02 23:03:41 +0000885 if (__source_is_absolute(_Traits::__first_or_null(__src)))
886 __pn_.clear();
887 else if (has_filename())
888 __pn_ += preferred_separator;
Eric Fiselier435db152016-06-17 19:46:40 +0000889 _CVT::__append_source(__pn_, __src);
890 return *this;
891 }
892
893 template <class _InputIt>
894 path& append(_InputIt __first, _InputIt __last) {
895 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
896 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
897 using _CVT = _PathCVT<_ItVal>;
Eric Fiselier91a182b2018-04-02 23:03:41 +0000898 if (__first != __last && __source_is_absolute(*__first))
899 __pn_.clear();
900 else if (has_filename())
901 __pn_ += preferred_separator;
902 _CVT::__append_range(__pn_, __first, __last);
Eric Fiselier435db152016-06-17 19:46:40 +0000903 return *this;
904 }
905
906 // concatenation
907 _LIBCPP_INLINE_VISIBILITY
908 path& operator+=(const path& __x) {
909 __pn_ += __x.__pn_;
910 return *this;
911 }
912
913 _LIBCPP_INLINE_VISIBILITY
914 path& operator+=(const string_type& __x) {
915 __pn_ += __x;
916 return *this;
917 }
918
919 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb05e1b02016-07-23 03:10:56 +0000920 path& operator+=(__string_view __x) {
921 __pn_ += __x;
922 return *this;
923 }
924
925 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +0000926 path& operator+=(const value_type* __x) {
927 __pn_ += __x;
928 return *this;
929 }
930
931 _LIBCPP_INLINE_VISIBILITY
932 path& operator+=(value_type __x) {
933 __pn_ += __x;
934 return *this;
935 }
936
Eric Fiselier435db152016-06-17 19:46:40 +0000937 template <class _ECharT>
938 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
939 operator+=(_ECharT __x)
940 {
941 basic_string<_ECharT> __tmp;
942 __tmp += __x;
943 _PathCVT<_ECharT>::__append_source(__pn_, __tmp);
944 return *this;
945 }
946
947 template <class _Source>
948 _EnableIfPathable<_Source>
949 operator+=(const _Source& __x) {
950 return this->concat(__x);
951 }
952
953 template <class _Source>
954 _EnableIfPathable<_Source>
955 concat(const _Source& __x) {
956 _SourceCVT<_Source>::__append_source(__pn_, __x);
957 return *this;
958 }
959
960 template <class _InputIt>
961 path& concat(_InputIt __first, _InputIt __last) {
962 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
963 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
964 return *this;
965 }
966
967 // modifiers
968 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000969 void clear() noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000970 __pn_.clear();
971 }
972
973 path& make_preferred() { return *this; }
Eric Fiselierf08063a2016-10-15 22:37:42 +0000974
975 _LIBCPP_INLINE_VISIBILITY
976 path& remove_filename() {
Eric Fiselier91a182b2018-04-02 23:03:41 +0000977 auto __fname = __filename();
978 if (!__fname.empty())
979 __pn_.erase(__fname.data() - __pn_.data());
Eric Fiselierf08063a2016-10-15 22:37:42 +0000980 return *this;
981 }
Eric Fiselier435db152016-06-17 19:46:40 +0000982
983 path& replace_filename(const path& __replacement) {
984 remove_filename();
985 return (*this /= __replacement);
986 }
987
988 path& replace_extension(const path& __replacement = path());
989
990 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000991 void swap(path& __rhs) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000992 __pn_.swap(__rhs.__pn_);
993 }
994
Eric Fiselier91a182b2018-04-02 23:03:41 +0000995 // private helper to allow reserving memory in the path
996 _LIBCPP_INLINE_VISIBILITY
997 void __reserve(size_t __s) { __pn_.reserve(__s); }
998
Eric Fiselier435db152016-06-17 19:46:40 +0000999 // native format observers
1000 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001001 const string_type& native() const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001002 return __pn_;
1003 }
1004
1005 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001006 const value_type* c_str() const noexcept { return __pn_.c_str(); }
Eric Fiselier435db152016-06-17 19:46:40 +00001007
1008 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
1009
1010 template <class _ECharT, class _Traits = char_traits<_ECharT>,
1011 class _Allocator = allocator<_ECharT> >
1012 basic_string<_ECharT, _Traits, _Allocator>
1013 string(const _Allocator& __a = _Allocator()) const {
1014 using _CVT = __widen_from_utf8<sizeof(_ECharT)*__CHAR_BIT__>;
1015 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
1016 _Str __s(__a);
1017 __s.reserve(__pn_.size());
1018 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
1019 return __s;
1020 }
1021
1022 _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; }
1023 _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const { return string<wchar_t>(); }
1024 _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; }
1025 _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const { return string<char16_t>(); }
1026 _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const { return string<char32_t>(); }
1027
1028 // generic format observers
1029 template <class _ECharT, class _Traits = char_traits<_ECharT>,
1030 class _Allocator = allocator<_ECharT>
1031 >
1032 basic_string<_ECharT, _Traits, _Allocator>
1033 generic_string(const _Allocator& __a = _Allocator()) const {
1034 return string<_ECharT, _Traits, _Allocator>(__a);
1035 }
1036
1037 std::string generic_string() const { return __pn_; }
1038 std::wstring generic_wstring() const { return string<wchar_t>(); }
1039 std::string generic_u8string() const { return __pn_; }
1040 std::u16string generic_u16string() const { return string<char16_t>(); }
1041 std::u32string generic_u32string() const { return string<char32_t>(); }
1042
1043private:
Saleem Abdulrasool53a32382017-01-30 03:58:26 +00001044 int __compare(__string_view) const;
1045 __string_view __root_name() const;
1046 __string_view __root_directory() const;
1047 __string_view __root_path_raw() const;
1048 __string_view __relative_path() const;
1049 __string_view __parent_path() const;
1050 __string_view __filename() const;
1051 __string_view __stem() const;
1052 __string_view __extension() const;
Eric Fiselier435db152016-06-17 19:46:40 +00001053
1054public:
1055 // compare
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001056 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept { return __compare(__p.__pn_);}
Eric Fiselierb05e1b02016-07-23 03:10:56 +00001057 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s); }
1058 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { return __compare(__s); }
Eric Fiselier435db152016-06-17 19:46:40 +00001059 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { return __compare(__s); }
1060
1061 // decomposition
Eric Fiselierb05e1b02016-07-23 03:10:56 +00001062 _LIBCPP_INLINE_VISIBILITY path root_name() const { return string_type(__root_name()); }
1063 _LIBCPP_INLINE_VISIBILITY path root_directory() const { return string_type(__root_directory()); }
1064 _LIBCPP_INLINE_VISIBILITY path root_path() const { return root_name().append(string_type(__root_directory())); }
1065 _LIBCPP_INLINE_VISIBILITY path relative_path() const { return string_type(__relative_path()); }
1066 _LIBCPP_INLINE_VISIBILITY path parent_path() const { return string_type(__parent_path()); }
1067 _LIBCPP_INLINE_VISIBILITY path filename() const { return string_type(__filename()); }
1068 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem());}
1069 _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); }
Eric Fiselier435db152016-06-17 19:46:40 +00001070
1071 // query
Eric Fiselier23a120c2018-07-25 03:31:48 +00001072 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001073 bool empty() const noexcept { return __pn_.empty(); }
Eric Fiselier435db152016-06-17 19:46:40 +00001074
1075 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); }
1076 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); }
Eric Fiselierf08063a2016-10-15 22:37:42 +00001077 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { return !__root_path_raw().empty(); }
Eric Fiselier435db152016-06-17 19:46:40 +00001078 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { return !__relative_path().empty(); }
1079 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { return !__parent_path().empty(); }
1080 _LIBCPP_INLINE_VISIBILITY bool has_filename() const { return !__filename().empty(); }
1081 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
1082 _LIBCPP_INLINE_VISIBILITY bool has_extension() const { return !__extension().empty(); }
1083
1084 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const { return has_root_directory(); }
1085 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
1086
Eric Fiselier91a182b2018-04-02 23:03:41 +00001087 // relative paths
1088 path lexically_normal() const;
1089 path lexically_relative(const path& __base) const;
1090
1091 _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
1092 path __result = this->lexically_relative(__base);
1093 if (__result.native().empty())
1094 return *this;
1095 return __result;
1096 }
1097
Eric Fiselier435db152016-06-17 19:46:40 +00001098 // iterators
1099 class _LIBCPP_TYPE_VIS iterator;
1100 typedef iterator const_iterator;
1101
Saleem Abdulrasool53a32382017-01-30 03:58:26 +00001102 iterator begin() const;
1103 iterator end() const;
Eric Fiselier435db152016-06-17 19:46:40 +00001104
Eric Fiselier2cd75272018-02-04 03:10:53 +00001105
1106 template <class _CharT, class _Traits>
1107 _LIBCPP_INLINE_VISIBILITY
1108 friend typename enable_if<is_same<_CharT, char>::value &&
1109 is_same<_Traits, char_traits<char>>::value,
1110 basic_ostream<_CharT, _Traits>&
1111 >::type
1112 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1113 __os << std::__quoted(__p.native());
1114 return __os;
1115 }
1116
1117 template <class _CharT, class _Traits>
1118 _LIBCPP_INLINE_VISIBILITY
1119 friend typename enable_if<!is_same<_CharT, char>::value ||
1120 !is_same<_Traits, char_traits<char>>::value,
1121 basic_ostream<_CharT, _Traits>&
1122 >::type
1123 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1124 __os << std::__quoted(__p.string<_CharT, _Traits>());
1125 return __os;
1126 }
1127
1128 template <class _CharT, class _Traits>
1129 _LIBCPP_INLINE_VISIBILITY
1130 friend basic_istream<_CharT, _Traits>&
1131 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
1132 {
1133 basic_string<_CharT, _Traits> __tmp;
1134 __is >> __quoted(__tmp);
1135 __p = __tmp;
1136 return __is;
1137 }
1138
Eric Fiselier435db152016-06-17 19:46:40 +00001139private:
1140 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb05e1b02016-07-23 03:10:56 +00001141 path& __assign_view(__string_view const& __s) noexcept { __pn_ = string_type(__s); return *this; }
Eric Fiselier435db152016-06-17 19:46:40 +00001142 string_type __pn_;
1143};
1144
Louis Dionne16fe2952018-07-11 23:14:33 +00001145inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001146void swap(path& __lhs, path& __rhs) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001147 __lhs.swap(__rhs);
1148}
1149
1150_LIBCPP_FUNC_VIS
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001151size_t hash_value(const path& __p) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +00001152
1153inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001154bool operator==(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001155{ return __lhs.compare(__rhs) == 0; }
1156
1157inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001158bool operator!=(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001159{ return __lhs.compare(__rhs) != 0; }
1160
1161inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001162bool operator<(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001163{ return __lhs.compare(__rhs) < 0; }
1164
1165inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001166bool operator<=(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001167{ return __lhs.compare(__rhs) <= 0; }
1168
1169inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001170bool operator>(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001171{ return __lhs.compare(__rhs) > 0; }
1172
1173inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001174bool operator>=(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001175{ return __lhs.compare(__rhs) >= 0; }
1176
1177inline _LIBCPP_INLINE_VISIBILITY
1178path operator/(const path& __lhs, const path& __rhs) {
David Bolvansky38b37ef2018-05-09 18:57:17 +00001179 path __result(__lhs);
1180 __result /= __rhs;
1181 return __result;
Eric Fiselier435db152016-06-17 19:46:40 +00001182}
1183
Eric Fiselier435db152016-06-17 19:46:40 +00001184template <class _Source>
1185_LIBCPP_INLINE_VISIBILITY
1186typename enable_if<__is_pathable<_Source>::value, path>::type
1187u8path(const _Source& __s){
1188 static_assert(is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1189 "u8path(Source const&) requires Source have a character type of type 'char'");
1190 return path(__s);
1191}
1192
1193template <class _InputIt>
1194_LIBCPP_INLINE_VISIBILITY
1195typename enable_if<__is_pathable<_InputIt>::value, path>::type
1196u8path(_InputIt __f, _InputIt __l) {
1197 static_assert(is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1198 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
1199 return path(__f, __l);
1200}
1201
1202class _LIBCPP_TYPE_VIS path::iterator
1203{
1204public:
Eric Fiselier23a120c2018-07-25 03:31:48 +00001205 enum _ParserState : unsigned char {
1206 _Singular,
1207 _BeforeBegin,
1208 _InRootName,
1209 _InRootDir,
1210 _InFilenames,
1211 _InTrailingSep,
1212 _AtEnd
1213 };
1214
1215public:
Eric Fiselier435db152016-06-17 19:46:40 +00001216 typedef bidirectional_iterator_tag iterator_category;
Eric Fiselierc8dac982017-04-04 01:05:59 +00001217
Eric Fiselier435db152016-06-17 19:46:40 +00001218 typedef path value_type;
1219 typedef std::ptrdiff_t difference_type;
1220 typedef const path* pointer;
1221 typedef const path& reference;
Eric Fiselier883af112017-04-13 02:54:13 +00001222
1223 typedef void __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
Eric Fiselier23a120c2018-07-25 03:31:48 +00001224
Eric Fiselier435db152016-06-17 19:46:40 +00001225public:
1226 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfc46d252016-10-30 23:30:38 +00001227 iterator() : __stashed_elem_(), __path_ptr_(nullptr),
Eric Fiselier23a120c2018-07-25 03:31:48 +00001228 __entry_(), __state_(_Singular) {}
Eric Fiselier435db152016-06-17 19:46:40 +00001229
1230 iterator(const iterator&) = default;
1231 ~iterator() = default;
1232
1233 iterator& operator=(const iterator&) = default;
1234
1235 _LIBCPP_INLINE_VISIBILITY
1236 reference operator*() const {
Eric Fiselierfc46d252016-10-30 23:30:38 +00001237 return __stashed_elem_;
Eric Fiselier435db152016-06-17 19:46:40 +00001238 }
1239
1240 _LIBCPP_INLINE_VISIBILITY
1241 pointer operator->() const {
Eric Fiselierfc46d252016-10-30 23:30:38 +00001242 return &__stashed_elem_;
Eric Fiselier435db152016-06-17 19:46:40 +00001243 }
1244
1245 _LIBCPP_INLINE_VISIBILITY
1246 iterator& operator++() {
Eric Fiselier23a120c2018-07-25 03:31:48 +00001247 _LIBCPP_ASSERT(__state_ != _Singular,
Eric Fiselierfc46d252016-10-30 23:30:38 +00001248 "attempting to increment a singular iterator");
Eric Fiselier23a120c2018-07-25 03:31:48 +00001249 _LIBCPP_ASSERT(__state_ != _AtEnd,
Eric Fiselierfc46d252016-10-30 23:30:38 +00001250 "attempting to increment the end iterator");
Eric Fiselier435db152016-06-17 19:46:40 +00001251 return __increment();
1252 }
1253
1254 _LIBCPP_INLINE_VISIBILITY
1255 iterator operator++(int) {
1256 iterator __it(*this);
1257 this->operator++();
1258 return __it;
1259 }
1260
1261 _LIBCPP_INLINE_VISIBILITY
1262 iterator& operator--() {
Eric Fiselier23a120c2018-07-25 03:31:48 +00001263 _LIBCPP_ASSERT(__state_ != _Singular,
Eric Fiselierfc46d252016-10-30 23:30:38 +00001264 "attempting to decrement a singular iterator");
1265 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
1266 "attempting to decrement the begin iterator");
Eric Fiselier435db152016-06-17 19:46:40 +00001267 return __decrement();
1268 }
1269
1270 _LIBCPP_INLINE_VISIBILITY
1271 iterator operator--(int) {
1272 iterator __it(*this);
1273 this->operator--();
1274 return __it;
1275 }
1276
1277private:
1278 friend class path;
Eric Fiselier28175a32016-09-16 00:07:16 +00001279
1280 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00001281 friend bool operator==(const iterator&, const iterator&);
1282
Saleem Abdulrasool53a32382017-01-30 03:58:26 +00001283 iterator& __increment();
1284 iterator& __decrement();
Eric Fiselier435db152016-06-17 19:46:40 +00001285
Eric Fiselierfc46d252016-10-30 23:30:38 +00001286 path __stashed_elem_;
Eric Fiselier435db152016-06-17 19:46:40 +00001287 const path* __path_ptr_;
Eric Fiselierfc46d252016-10-30 23:30:38 +00001288 path::__string_view __entry_;
Eric Fiselier23a120c2018-07-25 03:31:48 +00001289 _ParserState __state_;
Eric Fiselier435db152016-06-17 19:46:40 +00001290};
1291
1292inline _LIBCPP_INLINE_VISIBILITY
1293bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) {
1294 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
Eric Fiselierfc46d252016-10-30 23:30:38 +00001295 __lhs.__entry_.data() == __rhs.__entry_.data();
Eric Fiselier435db152016-06-17 19:46:40 +00001296}
1297
1298inline _LIBCPP_INLINE_VISIBILITY
1299bool operator!=(const path::iterator& __lhs, const path::iterator& __rhs) {
1300 return !(__lhs == __rhs);
1301}
1302
1303class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error
1304{
1305public:
1306 _LIBCPP_INLINE_VISIBILITY
1307 filesystem_error(const string& __what, error_code __ec)
1308 : system_error(__ec, __what),
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001309 __storage_(make_shared<_Storage>(path(), path())) {
1310 __create_what(0);
1311 }
Eric Fiselier435db152016-06-17 19:46:40 +00001312
1313 _LIBCPP_INLINE_VISIBILITY
1314 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1315 : system_error(__ec, __what),
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001316 __storage_(make_shared<_Storage>(__p1, path())) {
1317 __create_what(1);
1318 }
Eric Fiselier435db152016-06-17 19:46:40 +00001319
1320 _LIBCPP_INLINE_VISIBILITY
1321 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1322 error_code __ec)
1323 : system_error(__ec, __what),
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001324 __storage_(make_shared<_Storage>(__p1, __p2)) {
1325 __create_what(2);
Eric Fiselier435db152016-06-17 19:46:40 +00001326 }
1327
1328 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001329 const path& path1() const noexcept { return __storage_->__p1_; }
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001330
1331 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001332 const path& path2() const noexcept { return __storage_->__p2_; }
Eric Fiselier435db152016-06-17 19:46:40 +00001333
Eric Fiselier435db152016-06-17 19:46:40 +00001334 ~filesystem_error() override; // key function
1335
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001336 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001337 const char* what() const noexcept override {
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001338 return __storage_->__what_.c_str();
1339 }
Eric Fiselier435db152016-06-17 19:46:40 +00001340
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001341 _LIBCPP_FUNC_VIS
1342 void __create_what(int __num_paths);
1343
1344 private:
1345 struct _Storage {
1346 _LIBCPP_INLINE_VISIBILITY
1347 _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}
1348
1349 path __p1_;
1350 path __p2_;
1351 string __what_;
1352 };
1353 shared_ptr<_Storage> __storage_;
Eric Fiselier435db152016-06-17 19:46:40 +00001354};
1355
Marshall Clowed3e2292016-08-25 17:47:09 +00001356template <class... _Args>
Louis Dionne16fe2952018-07-11 23:14:33 +00001357_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001358#ifndef _LIBCPP_NO_EXCEPTIONS
Marshall Clowed3e2292016-08-25 17:47:09 +00001359void __throw_filesystem_error(_Args && ...__args)
1360{
Marshall Clowed3e2292016-08-25 17:47:09 +00001361 throw filesystem_error(std::forward<_Args>(__args)...);
Marshall Clowed3e2292016-08-25 17:47:09 +00001362}
Eric Fiselier6003c772016-12-23 23:37:52 +00001363#else
1364void __throw_filesystem_error(_Args&&...)
1365{
1366 _VSTD::abort();
1367}
1368#endif
1369
Eric Fiselier435db152016-06-17 19:46:40 +00001370// operational functions
1371
1372_LIBCPP_FUNC_VIS
Eric Fiselier91a182b2018-04-02 23:03:41 +00001373path __absolute(const path&, error_code *__ec=nullptr);
1374_LIBCPP_FUNC_VIS
1375path __canonical(const path&, error_code *__ec=nullptr);
Eric Fiselier435db152016-06-17 19:46:40 +00001376_LIBCPP_FUNC_VIS
1377void __copy(const path& __from, const path& __to, copy_options __opt,
1378 error_code *__ec=nullptr);
1379_LIBCPP_FUNC_VIS
1380bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1381 error_code *__ec=nullptr);
1382_LIBCPP_FUNC_VIS
1383void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1384 error_code *__ec=nullptr);
1385_LIBCPP_FUNC_VIS
1386bool __create_directories(const path& p, error_code *ec=nullptr);
1387_LIBCPP_FUNC_VIS
1388bool __create_directory(const path& p, error_code *ec=nullptr);
1389_LIBCPP_FUNC_VIS
1390bool __create_directory(const path& p, const path & attributes,
1391 error_code *ec=nullptr);
1392_LIBCPP_FUNC_VIS
1393void __create_directory_symlink(const path& __to, const path& __new_symlink,
1394 error_code *__ec=nullptr);
1395_LIBCPP_FUNC_VIS
1396void __create_hard_link(const path& __to, const path& __new_hard_link,
1397 error_code *__ec=nullptr);
1398_LIBCPP_FUNC_VIS
1399void __create_symlink(const path& __to, const path& __new_symlink,
1400 error_code *__ec=nullptr);
1401_LIBCPP_FUNC_VIS
1402path __current_path(error_code *__ec=nullptr);
1403_LIBCPP_FUNC_VIS
1404void __current_path(const path&, error_code *__ec=nullptr);
1405_LIBCPP_FUNC_VIS
1406bool __equivalent(const path&, const path&, error_code *__ec=nullptr);
1407_LIBCPP_FUNC_VIS
1408uintmax_t __file_size(const path&, error_code *__ec=nullptr);
1409_LIBCPP_FUNC_VIS
1410uintmax_t __hard_link_count(const path&, error_code *__ec=nullptr);
1411_LIBCPP_FUNC_VIS
1412bool __fs_is_empty(const path& p, error_code *ec=nullptr);
1413_LIBCPP_FUNC_VIS
1414file_time_type __last_write_time(const path& p, error_code *ec=nullptr);
1415_LIBCPP_FUNC_VIS
1416void __last_write_time(const path& p, file_time_type new_time,
1417 error_code *ec=nullptr);
1418_LIBCPP_FUNC_VIS
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +00001419void __permissions(const path&, perms, perm_options, error_code* = nullptr);
Eric Fiselier435db152016-06-17 19:46:40 +00001420_LIBCPP_FUNC_VIS
1421path __read_symlink(const path& p, error_code *ec=nullptr);
1422_LIBCPP_FUNC_VIS
1423bool __remove(const path& p, error_code *ec=nullptr);
1424_LIBCPP_FUNC_VIS
1425uintmax_t __remove_all(const path& p, error_code *ec=nullptr);
1426_LIBCPP_FUNC_VIS
1427void __rename(const path& from, const path& to, error_code *ec=nullptr);
1428_LIBCPP_FUNC_VIS
1429void __resize_file(const path& p, uintmax_t size, error_code *ec=nullptr);
1430_LIBCPP_FUNC_VIS
1431space_info __space(const path&, error_code *__ec=nullptr);
1432_LIBCPP_FUNC_VIS
1433file_status __status(const path&, error_code *__ec=nullptr);
1434_LIBCPP_FUNC_VIS
1435file_status __symlink_status(const path&, error_code *__ec=nullptr);
1436_LIBCPP_FUNC_VIS
1437path __system_complete(const path&, error_code *__ec=nullptr);
1438_LIBCPP_FUNC_VIS
1439path __temp_directory_path(error_code *__ec=nullptr);
Eric Fiselier91a182b2018-04-02 23:03:41 +00001440_LIBCPP_FUNC_VIS
1441path __weakly_canonical(path const& __p, error_code *__ec=nullptr);
Eric Fiselier435db152016-06-17 19:46:40 +00001442
1443inline _LIBCPP_INLINE_VISIBILITY
1444path current_path() {
1445 return __current_path();
1446}
1447
1448inline _LIBCPP_INLINE_VISIBILITY
1449path current_path(error_code& __ec) {
1450 return __current_path(&__ec);
1451}
1452
1453inline _LIBCPP_INLINE_VISIBILITY
1454void current_path(const path& __p) {
1455 __current_path(__p);
1456}
1457
1458inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001459void current_path(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001460 __current_path(__p, &__ec);
1461}
1462
Eric Fiselier91a182b2018-04-02 23:03:41 +00001463inline _LIBCPP_INLINE_VISIBILITY
1464path absolute(const path& __p) {
1465 return __absolute(__p);
1466}
Eric Fiselier435db152016-06-17 19:46:40 +00001467
1468inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier91a182b2018-04-02 23:03:41 +00001469path absolute(const path& __p, error_code &__ec) {
1470 return __absolute(__p, &__ec);
1471}
1472
1473inline _LIBCPP_INLINE_VISIBILITY
1474path canonical(const path& __p) {
1475 return __canonical(__p);
Eric Fiselier435db152016-06-17 19:46:40 +00001476}
1477
1478inline _LIBCPP_INLINE_VISIBILITY
1479path canonical(const path& __p, error_code& __ec) {
Eric Fiselier91a182b2018-04-02 23:03:41 +00001480 return __canonical(__p, &__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00001481}
1482
1483inline _LIBCPP_INLINE_VISIBILITY
1484void copy(const path& __from, const path& __to) {
1485 __copy(__from, __to, copy_options::none);
1486}
1487
1488inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd56d5322017-10-30 18:59:59 +00001489void copy(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001490 __copy(__from, __to, copy_options::none, &__ec);
1491}
1492
1493inline _LIBCPP_INLINE_VISIBILITY
1494void copy(const path& __from, const path& __to, copy_options __opt) {
1495 __copy(__from, __to, __opt);
1496}
1497
1498inline _LIBCPP_INLINE_VISIBILITY
1499void copy(const path& __from, const path& __to,
Eric Fiselierd56d5322017-10-30 18:59:59 +00001500 copy_options __opt, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001501 __copy(__from, __to, __opt, &__ec);
1502}
1503
1504inline _LIBCPP_INLINE_VISIBILITY
1505bool copy_file(const path& __from, const path& __to) {
1506 return __copy_file(__from, __to, copy_options::none);
1507}
1508
1509inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere1164812018-02-04 07:35:36 +00001510bool copy_file(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001511 return __copy_file(__from, __to, copy_options::none, &__ec);
1512}
1513
1514inline _LIBCPP_INLINE_VISIBILITY
1515bool copy_file(const path& __from, const path& __to, copy_options __opt) {
1516 return __copy_file(__from, __to, __opt);
1517}
1518
1519inline _LIBCPP_INLINE_VISIBILITY
1520bool copy_file(const path& __from, const path& __to,
Eric Fiseliere1164812018-02-04 07:35:36 +00001521 copy_options __opt, error_code& __ec){
Eric Fiselier435db152016-06-17 19:46:40 +00001522 return __copy_file(__from, __to, __opt, &__ec);
1523}
1524
1525inline _LIBCPP_INLINE_VISIBILITY
1526void copy_symlink(const path& __existing, const path& __new) {
1527 __copy_symlink(__existing, __new);
1528}
1529
1530inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001531void copy_symlink(const path& __ext, const path& __new, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001532 __copy_symlink(__ext, __new, &__ec);
1533}
1534
1535inline _LIBCPP_INLINE_VISIBILITY
1536bool create_directories(const path& __p) {
1537 return __create_directories(__p);
1538}
1539
1540inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere1164812018-02-04 07:35:36 +00001541bool create_directories(const path& __p, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001542 return __create_directories(__p, &__ec);
1543}
1544
1545inline _LIBCPP_INLINE_VISIBILITY
1546bool create_directory(const path& __p) {
1547 return __create_directory(__p);
1548}
1549
1550inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001551bool create_directory(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001552 return __create_directory(__p, &__ec);
1553}
1554
1555inline _LIBCPP_INLINE_VISIBILITY
1556bool create_directory(const path& __p, const path& __attrs) {
1557 return __create_directory(__p, __attrs);
1558}
1559
1560inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001561bool create_directory(const path& __p, const path& __attrs, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001562 return __create_directory(__p, __attrs, &__ec);
1563}
1564
1565inline _LIBCPP_INLINE_VISIBILITY
1566void create_directory_symlink(const path& __to, const path& __new) {
1567 __create_directory_symlink(__to, __new);
1568}
1569
1570inline _LIBCPP_INLINE_VISIBILITY
1571void create_directory_symlink(const path& __to, const path& __new,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001572 error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001573 __create_directory_symlink(__to, __new, &__ec);
1574}
1575
1576inline _LIBCPP_INLINE_VISIBILITY
1577void create_hard_link(const path& __to, const path& __new) {
1578 __create_hard_link(__to, __new);
1579}
1580
1581inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001582void create_hard_link(const path& __to, const path& __new, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001583 __create_hard_link(__to, __new, &__ec);
1584}
1585
1586inline _LIBCPP_INLINE_VISIBILITY
1587void create_symlink(const path& __to, const path& __new) {
1588 __create_symlink(__to, __new);
1589}
1590
1591inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier91a182b2018-04-02 23:03:41 +00001592void create_symlink(const path& __to, const path& __new,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001593 error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001594 return __create_symlink(__to, __new, &__ec);
1595}
1596
1597inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001598bool status_known(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001599 return __s.type() != file_type::none;
1600}
1601
1602inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001603bool exists(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001604 return status_known(__s) && __s.type() != file_type::not_found;
1605}
1606
1607inline _LIBCPP_INLINE_VISIBILITY
1608bool exists(const path& __p) {
1609 return exists(__status(__p));
1610}
1611
1612inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001613bool exists(const path& __p, error_code& __ec) noexcept {
Eric Fiselier0a367d22016-06-21 22:11:16 +00001614 auto __s = __status(__p, &__ec);
1615 if (status_known(__s)) __ec.clear();
1616 return exists(__s);
Eric Fiselier435db152016-06-17 19:46:40 +00001617}
1618
1619inline _LIBCPP_INLINE_VISIBILITY
1620bool equivalent(const path& __p1, const path& __p2) {
1621 return __equivalent(__p1, __p2);
1622}
1623
1624inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001625bool equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001626 return __equivalent(__p1, __p2, &__ec);
1627}
1628
1629inline _LIBCPP_INLINE_VISIBILITY
1630uintmax_t file_size(const path& __p) {
1631 return __file_size(__p);
1632}
1633
1634inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001635uintmax_t file_size(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001636 return __file_size(__p, &__ec);
1637}
1638
1639inline _LIBCPP_INLINE_VISIBILITY
1640uintmax_t hard_link_count(const path& __p) {
1641 return __hard_link_count(__p);
1642}
1643
1644inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001645uintmax_t hard_link_count(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001646 return __hard_link_count(__p, &__ec);
1647}
1648
1649inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001650bool is_block_file(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001651 return __s.type() == file_type::block;
1652}
1653
1654inline _LIBCPP_INLINE_VISIBILITY
1655bool is_block_file(const path& __p) {
1656 return is_block_file(__status(__p));
1657}
1658
1659inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001660bool is_block_file(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001661 return is_block_file(__status(__p, &__ec));
1662}
1663
1664inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001665bool is_character_file(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001666 return __s.type() == file_type::character;
1667}
1668
1669inline _LIBCPP_INLINE_VISIBILITY
1670bool is_character_file(const path& __p) {
1671 return is_character_file(__status(__p));
1672}
1673
1674inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001675bool is_character_file(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001676 return is_character_file(__status(__p, &__ec));
1677}
1678
1679inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001680bool is_directory(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001681 return __s.type() == file_type::directory;
1682}
1683
1684inline _LIBCPP_INLINE_VISIBILITY
1685bool is_directory(const path& __p) {
1686 return is_directory(__status(__p));
1687}
1688
1689inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001690bool is_directory(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001691 return is_directory(__status(__p, &__ec));
1692}
1693
1694inline _LIBCPP_INLINE_VISIBILITY
1695bool is_empty(const path& __p) {
1696 return __fs_is_empty(__p);
1697}
1698
1699inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd56d5322017-10-30 18:59:59 +00001700bool is_empty(const path& __p, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001701 return __fs_is_empty(__p, &__ec);
1702}
1703
1704inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001705bool is_fifo(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001706 return __s.type() == file_type::fifo;
1707}
1708inline _LIBCPP_INLINE_VISIBILITY
1709bool is_fifo(const path& __p) {
1710 return is_fifo(__status(__p));
1711}
1712
1713inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001714bool is_fifo(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001715 return is_fifo(__status(__p, &__ec));
1716}
1717
1718inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001719bool is_regular_file(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001720 return __s.type() == file_type::regular;
1721}
1722
1723inline _LIBCPP_INLINE_VISIBILITY
1724bool is_regular_file(const path& __p) {
1725 return is_regular_file(__status(__p));
1726}
1727
1728inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001729bool is_regular_file(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001730 return is_regular_file(__status(__p, &__ec));
1731}
1732
1733inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001734bool is_socket(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001735 return __s.type() == file_type::socket;
1736}
1737
1738inline _LIBCPP_INLINE_VISIBILITY
1739bool is_socket(const path& __p) {
1740 return is_socket(__status(__p));
1741}
1742
1743inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001744bool is_socket(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001745 return is_socket(__status(__p, &__ec));
1746}
1747
1748inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001749bool is_symlink(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001750 return __s.type() == file_type::symlink;
1751}
1752
1753inline _LIBCPP_INLINE_VISIBILITY
1754bool is_symlink(const path& __p) {
1755 return is_symlink(__symlink_status(__p));
1756}
1757
1758inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001759bool is_symlink(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001760 return is_symlink(__symlink_status(__p, &__ec));
1761}
1762
1763inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001764bool is_other(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001765 return exists(__s)
1766 && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s);
1767}
1768
1769inline _LIBCPP_INLINE_VISIBILITY
1770bool is_other(const path& __p) {
1771 return is_other(__status(__p));
1772}
1773
1774inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001775bool is_other(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001776 return is_other(__status(__p, &__ec));
1777}
1778
1779inline _LIBCPP_INLINE_VISIBILITY
1780file_time_type last_write_time(const path& __p) {
1781 return __last_write_time(__p);
1782}
1783
1784inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001785file_time_type last_write_time(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001786 return __last_write_time(__p, &__ec);
1787}
1788
1789inline _LIBCPP_INLINE_VISIBILITY
1790void last_write_time(const path& __p, file_time_type __t) {
1791 __last_write_time(__p, __t);
1792}
1793
1794inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001795void last_write_time(const path& __p, file_time_type __t, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001796 __last_write_time(__p, __t, &__ec);
1797}
1798
1799inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +00001800void permissions(const path& __p, perms __prms,
1801 perm_options __opts = perm_options::replace) {
1802 __permissions(__p, __prms, __opts);
Eric Fiselier435db152016-06-17 19:46:40 +00001803}
1804
1805inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001806void permissions(const path& __p, perms __prms, error_code& __ec) noexcept {
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +00001807 __permissions(__p, __prms, perm_options::replace, &__ec);
1808}
1809
1810inline _LIBCPP_INLINE_VISIBILITY
1811void permissions(const path& __p, perms __prms, perm_options __opts,
1812 error_code& __ec) {
1813 __permissions(__p, __prms, __opts, &__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00001814}
1815
1816inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier91a182b2018-04-02 23:03:41 +00001817path proximate(const path& __p, const path& __base, error_code& __ec) {
1818 path __tmp = __weakly_canonical(__p, &__ec);
1819 if (__ec)
1820 return {};
1821 path __tmp_base = __weakly_canonical(__base, &__ec);
1822 if (__ec)
1823 return {};
1824 return __tmp.lexically_proximate(__tmp_base);
1825}
1826
1827inline _LIBCPP_INLINE_VISIBILITY
1828path proximate(const path& __p, error_code& __ec) {
1829 return proximate(__p, current_path(), __ec);
1830}
1831
1832inline _LIBCPP_INLINE_VISIBILITY
1833path proximate(const path& __p, const path& __base = current_path()) {
1834 return __weakly_canonical(__p).lexically_proximate(__weakly_canonical(__base));
1835}
1836
1837inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00001838path read_symlink(const path& __p) {
1839 return __read_symlink(__p);
1840}
1841
1842inline _LIBCPP_INLINE_VISIBILITY
1843path read_symlink(const path& __p, error_code& __ec) {
1844 return __read_symlink(__p, &__ec);
1845}
1846
Eric Fiselier91a182b2018-04-02 23:03:41 +00001847
1848inline _LIBCPP_INLINE_VISIBILITY
1849path relative(const path& __p, const path& __base, error_code& __ec) {
1850 path __tmp = __weakly_canonical(__p, &__ec);
1851 if (__ec)
1852 return path();
1853 path __tmpbase = __weakly_canonical(__base, &__ec);
1854 if (__ec)
1855 return path();
1856 return __tmp.lexically_relative(__tmpbase);
1857}
1858
1859inline _LIBCPP_INLINE_VISIBILITY
1860path relative(const path& __p, error_code& __ec) {
1861 return relative(__p, current_path(), __ec);
1862}
1863
1864inline _LIBCPP_INLINE_VISIBILITY
1865path relative(const path& __p, const path& __base=current_path()) {
1866 return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base));
1867}
1868
1869
Eric Fiselier435db152016-06-17 19:46:40 +00001870inline _LIBCPP_INLINE_VISIBILITY
1871bool remove(const path& __p) {
1872 return __remove(__p);
1873}
1874
1875inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001876bool remove(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001877 return __remove(__p, &__ec);
1878}
1879
1880inline _LIBCPP_INLINE_VISIBILITY
1881uintmax_t remove_all(const path& __p) {
1882 return __remove_all(__p);
1883}
1884
1885inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere1164812018-02-04 07:35:36 +00001886uintmax_t remove_all(const path& __p, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001887 return __remove_all(__p, &__ec);
1888}
1889
1890inline _LIBCPP_INLINE_VISIBILITY
1891void rename(const path& __from, const path& __to) {
1892 return __rename(__from, __to);
1893}
1894
1895inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001896void rename(const path& __from, const path& __to, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001897 return __rename(__from, __to, &__ec);
1898}
1899
1900inline _LIBCPP_INLINE_VISIBILITY
1901void resize_file(const path& __p, uintmax_t __ns) {
1902 return __resize_file(__p, __ns);
1903}
1904
1905inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001906void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001907 return __resize_file(__p, __ns, &__ec);
1908}
1909
1910inline _LIBCPP_INLINE_VISIBILITY
1911space_info space(const path& __p) {
1912 return __space(__p);
1913}
1914
1915inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001916space_info space(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001917 return __space(__p, &__ec);
1918}
1919
1920inline _LIBCPP_INLINE_VISIBILITY
1921file_status status(const path& __p) {
1922 return __status(__p);
1923}
1924
1925inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001926file_status status(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001927 return __status(__p, &__ec);
1928}
1929
1930inline _LIBCPP_INLINE_VISIBILITY
1931file_status symlink_status(const path& __p) {
1932 return __symlink_status(__p);
1933}
1934
1935inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001936file_status symlink_status(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001937 return __symlink_status(__p, &__ec);
1938}
1939
1940inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00001941path temp_directory_path() {
1942 return __temp_directory_path();
1943}
1944
1945inline _LIBCPP_INLINE_VISIBILITY
1946path temp_directory_path(error_code& __ec) {
1947 return __temp_directory_path(&__ec);
1948}
1949
Eric Fiselier91a182b2018-04-02 23:03:41 +00001950inline _LIBCPP_INLINE_VISIBILITY
1951path weakly_canonical(path const& __p) {
1952 return __weakly_canonical(__p);
1953}
1954
1955inline _LIBCPP_INLINE_VISIBILITY
1956path weakly_canonical(path const& __p, error_code& __ec) {
1957 return __weakly_canonical(__p, &__ec);
1958}
1959
Eric Fiselier435db152016-06-17 19:46:40 +00001960
Eric Fiselier70474082018-07-20 01:22:32 +00001961class directory_iterator;
1962class recursive_directory_iterator;
1963class __dir_stream;
1964
Eric Fiselier435db152016-06-17 19:46:40 +00001965class directory_entry
1966{
1967 typedef _VSTD_FS::path _Path;
1968
1969public:
1970 // constructors and destructors
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001971 directory_entry() noexcept = default;
Eric Fiselier435db152016-06-17 19:46:40 +00001972 directory_entry(directory_entry const&) = default;
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001973 directory_entry(directory_entry&&) noexcept = default;
Eric Fiselier435db152016-06-17 19:46:40 +00001974
1975 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier70474082018-07-20 01:22:32 +00001976 explicit directory_entry(_Path const& __p) : __p_(__p) {
1977 error_code __ec;
1978 __refresh(&__ec);
1979 }
1980
1981 _LIBCPP_INLINE_VISIBILITY
1982 directory_entry(_Path const& __p, error_code &__ec) : __p_(__p) {
1983 __refresh(&__ec);
1984 }
Eric Fiselier435db152016-06-17 19:46:40 +00001985
1986 ~directory_entry() {}
1987
1988 directory_entry& operator=(directory_entry const&) = default;
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001989 directory_entry& operator=(directory_entry&&) noexcept = default;
Eric Fiselier435db152016-06-17 19:46:40 +00001990
1991 _LIBCPP_INLINE_VISIBILITY
1992 void assign(_Path const& __p) {
1993 __p_ = __p;
Eric Fiselier70474082018-07-20 01:22:32 +00001994 error_code __ec;
1995 __refresh(&__ec);
1996 }
1997
1998 _LIBCPP_INLINE_VISIBILITY
1999 void assign(_Path const& __p, error_code& __ec) {
2000 __p_ = __p;
2001 __refresh(&__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00002002 }
2003
2004 _LIBCPP_INLINE_VISIBILITY
2005 void replace_filename(_Path const& __p) {
Eric Fiselier70474082018-07-20 01:22:32 +00002006 __p_.replace_filename(__p);
2007 error_code __ec;
2008 __refresh(&__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00002009 }
2010
2011 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier70474082018-07-20 01:22:32 +00002012 void replace_filename(_Path const& __p, error_code &__ec) {
2013 __p_ = __p_.parent_path() / __p;
2014 __refresh(&__ec);
2015 }
2016
2017 _LIBCPP_INLINE_VISIBILITY
2018 void refresh() {
2019 __refresh();
2020 }
2021
2022 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002023 void refresh(error_code& __ec) noexcept { __refresh(&__ec); }
Eric Fiselier70474082018-07-20 01:22:32 +00002024
2025 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002026 _Path const& path() const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002027 return __p_;
2028 }
2029
2030 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002031 operator const _Path&() const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002032 return __p_;
2033 }
2034
2035 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier70474082018-07-20 01:22:32 +00002036 bool exists() const {
2037 return _VSTD_FS::exists(file_status{__get_ft()});
2038 }
2039
2040 _LIBCPP_INLINE_VISIBILITY
2041 bool exists(error_code& __ec) const noexcept {
2042 return _VSTD_FS::exists(file_status{__get_ft(&__ec)});
2043 }
2044
2045 _LIBCPP_INLINE_VISIBILITY
2046 bool is_block_file() const {
2047 return __get_ft() == file_type::block;
2048 }
2049
2050 _LIBCPP_INLINE_VISIBILITY
2051 bool is_block_file(error_code& __ec) const noexcept {
2052 return __get_ft(&__ec) == file_type::block;
2053 }
2054
2055 _LIBCPP_INLINE_VISIBILITY
2056 bool is_character_file() const {
2057 return __get_ft() == file_type::character;
2058 }
2059
2060 _LIBCPP_INLINE_VISIBILITY
2061 bool is_character_file(error_code& __ec) const noexcept {
2062 return __get_ft(&__ec) == file_type::character;
2063 }
2064
2065 _LIBCPP_INLINE_VISIBILITY
2066 bool is_directory() const {
2067 return __get_ft() == file_type::directory;
2068 }
2069
2070 _LIBCPP_INLINE_VISIBILITY
2071 bool is_directory(error_code& __ec) const noexcept {
2072 return __get_ft(&__ec) == file_type::directory;
2073 }
2074
2075 _LIBCPP_INLINE_VISIBILITY
2076 bool is_fifo() const {
2077 return __get_ft() == file_type::fifo;
2078 }
2079
2080 _LIBCPP_INLINE_VISIBILITY
2081 bool is_fifo(error_code& __ec) const noexcept {
2082 return __get_ft(&__ec) == file_type::fifo;
2083 }
2084
2085 _LIBCPP_INLINE_VISIBILITY
2086 bool is_other() const {
2087 return _VSTD_FS::is_other(file_status{__get_ft()});
2088 }
2089
2090 _LIBCPP_INLINE_VISIBILITY
2091 bool is_other(error_code& __ec) const noexcept {
2092 return _VSTD_FS::is_other(file_status{__get_ft(&__ec)});
2093 }
2094
2095 _LIBCPP_INLINE_VISIBILITY
2096 bool is_regular_file() const {
2097 return __get_ft() == file_type::regular;
2098 }
2099
2100 _LIBCPP_INLINE_VISIBILITY
2101 bool is_regular_file(error_code& __ec) const noexcept {
2102 return __get_ft(&__ec) == file_type::regular;
2103 }
2104
2105 _LIBCPP_INLINE_VISIBILITY
2106 bool is_socket() const {
2107 return __get_ft() == file_type::socket;
2108 }
2109
2110 _LIBCPP_INLINE_VISIBILITY
2111 bool is_socket(error_code& __ec) const noexcept {
2112 return __get_ft(&__ec) == file_type::socket;
2113 }
2114
2115 _LIBCPP_INLINE_VISIBILITY
2116 bool is_symlink() const {
2117 return __get_sym_ft() == file_type::symlink;
2118 }
2119
2120 _LIBCPP_INLINE_VISIBILITY
2121 bool is_symlink(error_code& __ec) const noexcept {
2122 return __get_sym_ft(&__ec) == file_type::symlink;
2123 }
2124 _LIBCPP_INLINE_VISIBILITY
2125 uintmax_t file_size() const {
2126 return __get_size();
2127 }
2128
2129 _LIBCPP_INLINE_VISIBILITY
2130 uintmax_t file_size(error_code& __ec) const noexcept {
2131 return __get_size(&__ec);
2132 }
2133
2134 _LIBCPP_INLINE_VISIBILITY
2135 uintmax_t hard_link_count() const {
2136 return __get_nlink();
2137 }
2138
2139 _LIBCPP_INLINE_VISIBILITY
2140 uintmax_t hard_link_count(error_code& __ec) const noexcept {
2141 return __get_nlink(&__ec);
2142 }
2143
2144 _LIBCPP_INLINE_VISIBILITY
2145 file_time_type last_write_time() const {
2146 return __get_write_time();
2147 }
2148
2149 _LIBCPP_INLINE_VISIBILITY
2150 file_time_type last_write_time(error_code& __ec) const noexcept {
2151 return __get_write_time(&__ec);
2152 }
2153
2154 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00002155 file_status status() const {
Eric Fiselier70474082018-07-20 01:22:32 +00002156 return __get_status();
Eric Fiselier435db152016-06-17 19:46:40 +00002157 }
2158
2159 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002160 file_status status(error_code& __ec) const noexcept {
Eric Fiselier70474082018-07-20 01:22:32 +00002161 return __get_status(&__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00002162 }
2163
2164 _LIBCPP_INLINE_VISIBILITY
2165 file_status symlink_status() const {
Eric Fiselier70474082018-07-20 01:22:32 +00002166 return __get_symlink_status();
Eric Fiselier435db152016-06-17 19:46:40 +00002167 }
2168
2169 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002170 file_status symlink_status(error_code& __ec) const noexcept {
Eric Fiselier70474082018-07-20 01:22:32 +00002171 return __get_symlink_status(&__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00002172 }
2173
2174 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002175 bool operator< (directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002176 return __p_ < __rhs.__p_;
2177 }
2178
2179 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002180 bool operator==(directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002181 return __p_ == __rhs.__p_;
2182 }
2183
2184 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002185 bool operator!=(directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002186 return __p_ != __rhs.__p_;
2187 }
2188
2189 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002190 bool operator<=(directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002191 return __p_ <= __rhs.__p_;
2192 }
2193
2194 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002195 bool operator> (directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002196 return __p_ > __rhs.__p_;
2197 }
2198
2199 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002200 bool operator>=(directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002201 return __p_ >= __rhs.__p_;
2202 }
Eric Fiselier70474082018-07-20 01:22:32 +00002203
2204private:
2205 friend class directory_iterator;
2206 friend class recursive_directory_iterator;
2207 friend class __dir_stream;
2208
2209 enum _CacheType : unsigned char {
2210 _Empty,
2211 _IterSymlink,
2212 _IterNonSymlink,
2213 _RefreshSymlink,
2214 _RefreshSymlinkUnresolved,
2215 _RefreshNonSymlink
2216 };
2217
2218 struct __cached_data {
2219 uintmax_t __size_;
2220 uintmax_t __nlink_;
2221 file_time_type __write_time_;
2222 perms __sym_perms_;
2223 perms __non_sym_perms_;
2224 file_type __type_;
2225 _CacheType __cache_type_;
2226
2227 _LIBCPP_INLINE_VISIBILITY
2228 __cached_data() noexcept { __reset(); }
2229
2230 _LIBCPP_INLINE_VISIBILITY
2231 void __reset() {
2232 __cache_type_ = _Empty;
2233 __type_ = file_type::none;
2234 __sym_perms_ = __non_sym_perms_ = perms::unknown;
2235 __size_ = __nlink_ = uintmax_t(-1);
2236 __write_time_ = file_time_type::min();
2237 }
2238 };
2239
2240 _LIBCPP_INLINE_VISIBILITY
2241 static __cached_data __create_iter_result(file_type __ft) {
2242 __cached_data __data;
2243 __data.__type_ = __ft;
Eric Fiselierc9332892018-07-23 22:40:41 +00002244 __data.__cache_type_ = [&]() {
2245 switch (__ft) {
2246 case file_type::none:
2247 return _Empty;
2248 case file_type::symlink:
2249 return _IterSymlink;
2250 default:
2251 return _IterNonSymlink;
2252 }
2253 }();
Eric Fiselier70474082018-07-20 01:22:32 +00002254 return __data;
2255 }
2256
2257 _LIBCPP_INLINE_VISIBILITY
2258 void __assign_iter_entry(_Path&& __p, __cached_data __dt) {
2259 __p_ = std::move(__p);
2260 __data_ = __dt;
2261 }
2262
2263 _LIBCPP_FUNC_VIS
2264 error_code __do_refresh() noexcept;
2265
2266 _LIBCPP_INLINE_VISIBILITY
2267 static bool __is_dne_error(error_code const& __ec) {
2268 if (!__ec)
2269 return true;
2270 switch (static_cast<errc>(__ec.value())) {
2271 case errc::no_such_file_or_directory:
2272 case errc::not_a_directory:
2273 return true;
2274 default:
2275 return false;
2276 }
2277 }
2278
2279 _LIBCPP_INLINE_VISIBILITY
2280 void __handle_error(const char* __msg, error_code* __dest_ec,
2281 error_code const& __ec,
2282 bool __allow_dne = false) const {
2283 if (__dest_ec) {
2284 *__dest_ec = __ec;
2285 return;
2286 }
2287 if (__ec && (!__allow_dne || !__is_dne_error(__ec)))
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002288 __throw_filesystem_error(__msg, __p_, __ec);
Eric Fiselier70474082018-07-20 01:22:32 +00002289 }
2290
2291 _LIBCPP_INLINE_VISIBILITY
2292 void __refresh(error_code* __ec = nullptr) {
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002293 __handle_error("in directory_entry::refresh", __ec, __do_refresh(),
2294 /*allow_dne*/ true);
Eric Fiselier70474082018-07-20 01:22:32 +00002295 }
2296
2297 _LIBCPP_INLINE_VISIBILITY
2298 file_type __get_sym_ft(error_code *__ec = nullptr) const {
2299 switch (__data_.__cache_type_) {
2300 case _Empty:
2301 return __symlink_status(__p_, __ec).type();
2302 case _IterSymlink:
2303 case _RefreshSymlink:
2304 case _RefreshSymlinkUnresolved:
2305 if (__ec)
2306 __ec->clear();
2307 return file_type::symlink;
2308 case _IterNonSymlink:
2309 case _RefreshNonSymlink:
2310 file_status __st(__data_.__type_);
2311 if (__ec && !_VSTD_FS::exists(__st))
2312 *__ec = make_error_code(errc::no_such_file_or_directory);
2313 else if (__ec)
2314 __ec->clear();
2315 return __data_.__type_;
2316 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002317 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002318 }
2319
2320 _LIBCPP_INLINE_VISIBILITY
2321 file_type __get_ft(error_code *__ec = nullptr) const {
2322 switch (__data_.__cache_type_) {
2323 case _Empty:
2324 case _IterSymlink:
2325 case _RefreshSymlinkUnresolved:
2326 return __status(__p_, __ec).type();
2327 case _IterNonSymlink:
2328 case _RefreshNonSymlink:
2329 case _RefreshSymlink: {
2330 file_status __st(__data_.__type_);
2331 if (__ec && !_VSTD_FS::exists(__st))
2332 *__ec = make_error_code(errc::no_such_file_or_directory);
2333 else if (__ec)
2334 __ec->clear();
2335 return __data_.__type_;
2336 }
2337 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002338 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002339 }
2340
2341 _LIBCPP_INLINE_VISIBILITY
2342 file_status __get_status(error_code *__ec = nullptr) const {
2343 switch (__data_.__cache_type_) {
2344 case _Empty:
2345 case _IterNonSymlink:
2346 case _IterSymlink:
2347 case _RefreshSymlinkUnresolved:
2348 return __status(__p_, __ec);
2349 case _RefreshNonSymlink:
2350 case _RefreshSymlink:
2351 return file_status(__get_ft(__ec), __data_.__non_sym_perms_);
2352 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002353 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002354 }
2355
2356 _LIBCPP_INLINE_VISIBILITY
2357 file_status __get_symlink_status(error_code *__ec = nullptr) const {
2358 switch (__data_.__cache_type_) {
2359 case _Empty:
2360 case _IterNonSymlink:
2361 case _IterSymlink:
2362 return __symlink_status(__p_, __ec);
2363 case _RefreshNonSymlink:
2364 return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_);
2365 case _RefreshSymlink:
2366 case _RefreshSymlinkUnresolved:
2367 return file_status(__get_sym_ft(__ec), __data_.__sym_perms_);
2368 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002369 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002370 }
2371
2372
2373 _LIBCPP_INLINE_VISIBILITY
2374 uintmax_t __get_size(error_code *__ec = nullptr) const {
2375 switch (__data_.__cache_type_) {
2376 case _Empty:
2377 case _IterNonSymlink:
2378 case _IterSymlink:
2379 case _RefreshSymlinkUnresolved:
2380 return _VSTD_FS::__file_size(__p_, __ec);
2381 case _RefreshSymlink:
2382 case _RefreshNonSymlink: {
2383 error_code __m_ec;
2384 file_status __st(__get_ft(&__m_ec));
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002385 __handle_error("in directory_entry::file_size", __ec, __m_ec);
Eric Fiselier70474082018-07-20 01:22:32 +00002386 if (_VSTD_FS::exists(__st) && !_VSTD_FS::is_regular_file(__st)) {
2387 errc __err_kind = _VSTD_FS::is_directory(__st) ? errc::is_a_directory
2388 : errc::not_supported;
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002389 __handle_error("in directory_entry::file_size", __ec,
Eric Fiselier70474082018-07-20 01:22:32 +00002390 make_error_code(__err_kind));
2391 }
2392 return __data_.__size_;
2393 }
2394 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002395 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002396 }
2397
2398 _LIBCPP_INLINE_VISIBILITY
2399 uintmax_t __get_nlink(error_code *__ec = nullptr) const {
2400 switch (__data_.__cache_type_) {
2401 case _Empty:
2402 case _IterNonSymlink:
2403 case _IterSymlink:
2404 case _RefreshSymlinkUnresolved:
2405 return _VSTD_FS::__hard_link_count(__p_, __ec);
2406 case _RefreshSymlink:
2407 case _RefreshNonSymlink: {
2408 error_code __m_ec;
2409 (void)__get_ft(&__m_ec);
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002410 __handle_error("in directory_entry::hard_link_count", __ec, __m_ec);
Eric Fiselier70474082018-07-20 01:22:32 +00002411 return __data_.__nlink_;
2412 }
2413 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002414 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002415 }
2416
2417 _LIBCPP_INLINE_VISIBILITY
2418 file_time_type __get_write_time(error_code *__ec = nullptr) const {
2419 switch (__data_.__cache_type_) {
2420 case _Empty:
2421 case _IterNonSymlink:
2422 case _IterSymlink:
2423 case _RefreshSymlinkUnresolved:
2424 return _VSTD_FS::__last_write_time(__p_, __ec);
2425 case _RefreshSymlink:
2426 case _RefreshNonSymlink: {
2427 error_code __m_ec;
2428 file_status __st(__get_ft(&__m_ec));
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002429 __handle_error("in directory_entry::last_write_time", __ec, __m_ec);
Eric Fiselier70474082018-07-20 01:22:32 +00002430 if (_VSTD_FS::exists(__st) &&
2431 __data_.__write_time_ == file_time_type::min())
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002432 __handle_error("in directory_entry::last_write_time", __ec,
Eric Fiselier70474082018-07-20 01:22:32 +00002433 make_error_code(errc::value_too_large));
2434 return __data_.__write_time_;
2435 }
2436 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002437 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002438 }
Eric Fiselier435db152016-06-17 19:46:40 +00002439private:
2440 _Path __p_;
Eric Fiselier70474082018-07-20 01:22:32 +00002441 __cached_data __data_;
Eric Fiselier435db152016-06-17 19:46:40 +00002442};
2443
Eric Fiselier435db152016-06-17 19:46:40 +00002444class __dir_element_proxy {
2445public:
2446
2447 inline _LIBCPP_INLINE_VISIBILITY
2448 directory_entry operator*() { return _VSTD::move(__elem_); }
2449
2450private:
2451 friend class directory_iterator;
2452 friend class recursive_directory_iterator;
2453 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
2454 __dir_element_proxy(__dir_element_proxy&& __o) : __elem_(_VSTD::move(__o.__elem_)) {}
2455 directory_entry __elem_;
2456};
2457
2458class directory_iterator
2459{
2460public:
2461 typedef directory_entry value_type;
2462 typedef ptrdiff_t difference_type;
2463 typedef value_type const* pointer;
2464 typedef value_type const& reference;
2465 typedef input_iterator_tag iterator_category;
2466
2467public:
2468 //ctor & dtor
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002469 directory_iterator() noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00002470 { }
2471
2472 explicit directory_iterator(const path& __p)
2473 : directory_iterator(__p, nullptr)
2474 { }
2475
2476 directory_iterator(const path& __p, directory_options __opts)
2477 : directory_iterator(__p, nullptr, __opts)
2478 { }
2479
Eric Fiselierd56d5322017-10-30 18:59:59 +00002480 directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002481 : directory_iterator(__p, &__ec)
2482 { }
2483
2484 directory_iterator(const path& __p, directory_options __opts,
Eric Fiselierd56d5322017-10-30 18:59:59 +00002485 error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002486 : directory_iterator(__p, &__ec, __opts)
2487 { }
2488
2489 directory_iterator(const directory_iterator&) = default;
2490 directory_iterator(directory_iterator&&) = default;
2491 directory_iterator& operator=(const directory_iterator&) = default;
2492
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002493 directory_iterator& operator=(directory_iterator&& __o) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002494 // non-default implementation provided to support self-move assign.
2495 if (this != &__o) {
2496 __imp_ = _VSTD::move(__o.__imp_);
2497 }
2498 return *this;
2499 }
2500
2501 ~directory_iterator() = default;
2502
2503 const directory_entry& operator*() const {
2504 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002505 return __dereference();
Eric Fiselier435db152016-06-17 19:46:40 +00002506 }
2507
2508 const directory_entry* operator->() const
2509 { return &**this; }
2510
2511 directory_iterator& operator++()
2512 { return __increment(); }
2513
2514 __dir_element_proxy operator++(int) {
2515 __dir_element_proxy __p(**this);
2516 __increment();
2517 return __p;
2518 }
2519
Eric Fiselierd56d5322017-10-30 18:59:59 +00002520 directory_iterator& increment(error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002521 { return __increment(&__ec); }
2522
2523private:
Eric Fiselier28175a32016-09-16 00:07:16 +00002524 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00002525 friend bool operator==(const directory_iterator& __lhs,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002526 const directory_iterator& __rhs) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +00002527
2528 // construct the dir_stream
2529 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002530 directory_iterator(const path&, error_code *,
2531 directory_options = directory_options::none);
2532
Eric Fiselier435db152016-06-17 19:46:40 +00002533 _LIBCPP_FUNC_VIS
2534 directory_iterator& __increment(error_code * __ec = nullptr);
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002535
Eric Fiselier435db152016-06-17 19:46:40 +00002536 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002537 const directory_entry& __dereference() const;
Eric Fiselier435db152016-06-17 19:46:40 +00002538
2539private:
2540 shared_ptr<__dir_stream> __imp_;
2541};
2542
2543
2544inline _LIBCPP_INLINE_VISIBILITY
2545bool operator==(const directory_iterator& __lhs,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002546 const directory_iterator& __rhs) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002547 return __lhs.__imp_ == __rhs.__imp_;
2548}
2549
2550inline _LIBCPP_INLINE_VISIBILITY
2551bool operator!=(const directory_iterator& __lhs,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002552 const directory_iterator& __rhs) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002553 return !(__lhs == __rhs);
2554}
2555
2556// enable directory_iterator range-based for statements
2557inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002558directory_iterator begin(directory_iterator __iter) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002559 return __iter;
2560}
2561
2562inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002563directory_iterator end(const directory_iterator&) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002564 return directory_iterator();
2565}
2566
2567class recursive_directory_iterator {
2568public:
2569 using value_type = directory_entry;
2570 using difference_type = std::ptrdiff_t;
2571 using pointer = directory_entry const *;
2572 using reference = directory_entry const &;
2573 using iterator_category = std::input_iterator_tag;
2574
2575public:
2576 // constructors and destructor
2577 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002578 recursive_directory_iterator() noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00002579 : __rec_(false)
2580 {}
2581
2582 _LIBCPP_INLINE_VISIBILITY
2583 explicit recursive_directory_iterator(const path& __p,
2584 directory_options __xoptions = directory_options::none)
2585 : recursive_directory_iterator(__p, __xoptions, nullptr)
2586 { }
2587
2588 _LIBCPP_INLINE_VISIBILITY
2589 recursive_directory_iterator(const path& __p,
Eric Fiselierd56d5322017-10-30 18:59:59 +00002590 directory_options __xoptions, error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002591 : recursive_directory_iterator(__p, __xoptions, &__ec)
2592 { }
2593
2594 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd56d5322017-10-30 18:59:59 +00002595 recursive_directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002596 : recursive_directory_iterator(__p, directory_options::none, &__ec)
2597 { }
2598
2599 recursive_directory_iterator(const recursive_directory_iterator&) = default;
2600 recursive_directory_iterator(recursive_directory_iterator&&) = default;
2601
2602 recursive_directory_iterator &
2603 operator=(const recursive_directory_iterator&) = default;
2604
2605 _LIBCPP_INLINE_VISIBILITY
2606 recursive_directory_iterator &
2607 operator=(recursive_directory_iterator&& __o) noexcept {
2608 // non-default implementation provided to support self-move assign.
2609 if (this != &__o) {
2610 __imp_ = _VSTD::move(__o.__imp_);
2611 __rec_ = __o.__rec_;
2612 }
2613 return *this;
2614 }
2615
2616 ~recursive_directory_iterator() = default;
2617
2618 _LIBCPP_INLINE_VISIBILITY
2619 const directory_entry& operator*() const
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002620 { return __dereference(); }
Eric Fiselier435db152016-06-17 19:46:40 +00002621
2622 _LIBCPP_INLINE_VISIBILITY
2623 const directory_entry* operator->() const
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002624 { return &__dereference(); }
Eric Fiselier435db152016-06-17 19:46:40 +00002625
2626 recursive_directory_iterator& operator++()
2627 { return __increment(); }
2628
2629 _LIBCPP_INLINE_VISIBILITY
2630 __dir_element_proxy operator++(int) {
2631 __dir_element_proxy __p(**this);
2632 __increment();
2633 return __p;
2634 }
2635
2636 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd56d5322017-10-30 18:59:59 +00002637 recursive_directory_iterator& increment(error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002638 { return __increment(&__ec); }
2639
2640 _LIBCPP_FUNC_VIS directory_options options() const;
2641 _LIBCPP_FUNC_VIS int depth() const;
2642
2643 _LIBCPP_INLINE_VISIBILITY
2644 void pop() { __pop(); }
2645
2646 _LIBCPP_INLINE_VISIBILITY
2647 void pop(error_code& __ec)
2648 { __pop(&__ec); }
2649
2650 _LIBCPP_INLINE_VISIBILITY
2651 bool recursion_pending() const
2652 { return __rec_; }
2653
2654 _LIBCPP_INLINE_VISIBILITY
2655 void disable_recursion_pending()
2656 { __rec_ = false; }
2657
2658private:
2659 recursive_directory_iterator(const path& __p, directory_options __opt,
2660 error_code *__ec);
2661
2662 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002663 const directory_entry& __dereference() const;
Eric Fiselier435db152016-06-17 19:46:40 +00002664
2665 _LIBCPP_FUNC_VIS
2666 bool __try_recursion(error_code* __ec);
2667
2668 _LIBCPP_FUNC_VIS
2669 void __advance(error_code* __ec=nullptr);
2670
2671 _LIBCPP_FUNC_VIS
2672 recursive_directory_iterator& __increment(error_code *__ec=nullptr);
2673
2674 _LIBCPP_FUNC_VIS
2675 void __pop(error_code* __ec=nullptr);
2676
Eric Fiselier28175a32016-09-16 00:07:16 +00002677 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00002678 friend bool operator==(const recursive_directory_iterator&,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002679 const recursive_directory_iterator&) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +00002680
2681 struct __shared_imp;
2682 shared_ptr<__shared_imp> __imp_;
2683 bool __rec_;
2684}; // class recursive_directory_iterator
2685
2686
Eric Fiselier28175a32016-09-16 00:07:16 +00002687inline _LIBCPP_INLINE_VISIBILITY
2688bool operator==(const recursive_directory_iterator& __lhs,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002689 const recursive_directory_iterator& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00002690{
2691 return __lhs.__imp_ == __rhs.__imp_;
2692}
2693
2694_LIBCPP_INLINE_VISIBILITY
2695inline bool operator!=(const recursive_directory_iterator& __lhs,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002696 const recursive_directory_iterator& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00002697{
2698 return !(__lhs == __rhs);
2699}
2700// enable recursive_directory_iterator range-based for statements
2701inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002702recursive_directory_iterator begin(recursive_directory_iterator __iter) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002703 return __iter;
2704}
2705
2706inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002707recursive_directory_iterator end(const recursive_directory_iterator&) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002708 return recursive_directory_iterator();
2709}
2710
2711_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM
2712
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002713#endif // !_LIBCPP_CXX03_LANG
2714
Eric Fiselier3ad58be2018-07-20 01:51:48 +00002715_LIBCPP_POP_MACROS
2716
Eric Fiselier435db152016-06-17 19:46:40 +00002717#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM