blob: 06a0eb33c4e57cfb37346516e79db60bdf8c9d26 [file] [log] [blame]
Eric Fiselier02cea5e2018-07-27 03:07:09 +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_FILESYSTEM
11#define _LIBCPP_FILESYSTEM
12/*
13 filesystem synopsis
14
15 namespace std { namespace filesystem {
16
17 class path;
18
19 void swap(path& lhs, path& rhs) noexcept;
20 size_t hash_value(const path& p) noexcept;
21
22 bool operator==(const path& lhs, const path& rhs) noexcept;
23 bool operator!=(const path& lhs, const path& rhs) noexcept;
24 bool operator< (const path& lhs, const path& rhs) noexcept;
25 bool operator<=(const path& lhs, const path& rhs) noexcept;
26 bool operator> (const path& lhs, const path& rhs) noexcept;
27 bool operator>=(const path& lhs, const path& rhs) noexcept;
28
29 path operator/ (const path& lhs, const path& rhs);
30
31 // fs.path.io operators are friends of path.
32 template <class charT, class traits>
33 friend basic_ostream<charT, traits>&
34 operator<<(basic_ostream<charT, traits>& os, const path& p);
35
36 template <class charT, class traits>
37 friend basic_istream<charT, traits>&
38 operator>>(basic_istream<charT, traits>& is, path& p);
39
40 template <class Source>
41 path u8path(const Source& source);
42 template <class InputIterator>
43 path u8path(InputIterator first, InputIterator last);
44
45 class filesystem_error;
46 class directory_entry;
47
48 class directory_iterator;
49
50 // enable directory_iterator range-based for statements
51 directory_iterator begin(directory_iterator iter) noexcept;
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;
71 enum class perm_options;
72 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
79 path absolute(const path& p);
80 path absolute(const path& p, error_code &ec);
81
82 path canonical(const path& p);
83 path canonical(const path& p, error_code& ec);
84
85 void copy(const path& from, const path& to);
86 void copy(const path& from, const path& to, error_code& ec);
87 void copy(const path& from, const path& to, copy_options options);
88 void copy(const path& from, const path& to, copy_options options,
89 error_code& ec);
90
91 bool copy_file(const path& from, const path& to);
92 bool copy_file(const path& from, const path& to, error_code& ec);
93 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,
95 error_code& ec);
96
97 void copy_symlink(const path& existing_symlink, const path& new_symlink);
98 void copy_symlink(const path& existing_symlink, const path& new_symlink,
99 error_code& ec) noexcept;
100
101 bool create_directories(const path& p);
102 bool create_directories(const path& p, error_code& ec);
103
104 bool create_directory(const path& p);
105 bool create_directory(const path& p, error_code& ec) noexcept;
106
107 bool create_directory(const path& p, const path& attributes);
108 bool create_directory(const path& p, const path& attributes,
109 error_code& ec) noexcept;
110
111 void create_directory_symlink(const path& to, const path& new_symlink);
112 void create_directory_symlink(const path& to, const path& new_symlink,
113 error_code& ec) noexcept;
114
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,
117 error_code& ec) noexcept;
118
119 void create_symlink(const path& to, const path& new_symlink);
120 void create_symlink(const path& to, const path& new_symlink,
121 error_code& ec) noexcept;
122
123 path current_path();
124 path current_path(error_code& ec);
125 void current_path(const path& p);
126 void current_path(const path& p, error_code& ec) noexcept;
127
128 bool exists(file_status s) noexcept;
129 bool exists(const path& p);
130 bool exists(const path& p, error_code& ec) noexcept;
131
132 bool equivalent(const path& p1, const path& p2);
133 bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
134
135 uintmax_t file_size(const path& p);
136 uintmax_t file_size(const path& p, error_code& ec) noexcept;
137
138 uintmax_t hard_link_count(const path& p);
139 uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
140
141 bool is_block_file(file_status s) noexcept;
142 bool is_block_file(const path& p);
143 bool is_block_file(const path& p, error_code& ec) noexcept;
144
145 bool is_character_file(file_status s) noexcept;
146 bool is_character_file(const path& p);
147 bool is_character_file(const path& p, error_code& ec) noexcept;
148
149 bool is_directory(file_status s) noexcept;
150 bool is_directory(const path& p);
151 bool is_directory(const path& p, error_code& ec) noexcept;
152
153 bool is_empty(const path& p);
154 bool is_empty(const path& p, error_code& ec) noexcept;
155
156 bool is_fifo(file_status s) noexcept;
157 bool is_fifo(const path& p);
158 bool is_fifo(const path& p, error_code& ec) noexcept;
159
160 bool is_other(file_status s) noexcept;
161 bool is_other(const path& p);
162 bool is_other(const path& p, error_code& ec) noexcept;
163
164 bool is_regular_file(file_status s) noexcept;
165 bool is_regular_file(const path& p);
166 bool is_regular_file(const path& p, error_code& ec) noexcept;
167
168 bool is_socket(file_status s) noexcept;
169 bool is_socket(const path& p);
170 bool is_socket(const path& p, error_code& ec) noexcept;
171
172 bool is_symlink(file_status s) noexcept;
173 bool is_symlink(const path& p);
174 bool is_symlink(const path& p, error_code& ec) noexcept;
175
176 file_time_type last_write_time(const path& p);
177 file_time_type last_write_time(const path& p, error_code& ec) noexcept;
178 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,
180 error_code& ec) noexcept;
181
182 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);
187
188 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
192 path read_symlink(const path& p);
193 path read_symlink(const path& p, error_code& ec);
194
195 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
199 bool remove(const path& p);
200 bool remove(const path& p, error_code& ec) noexcept;
201
202 uintmax_t remove_all(const path& p);
203 uintmax_t remove_all(const path& p, error_code& ec);
204
205 void rename(const path& from, const path& to);
206 void rename(const path& from, const path& to, error_code& ec) noexcept;
207
208 void resize_file(const path& p, uintmax_t size);
209 void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept;
210
211 space_info space(const path& p);
212 space_info space(const path& p, error_code& ec) noexcept;
213
214 file_status status(const path& p);
215 file_status status(const path& p, error_code& ec) noexcept;
216
217 bool status_known(file_status s) noexcept;
218
219 file_status symlink_status(const path& p);
220 file_status symlink_status(const path& p, error_code& ec) noexcept;
221
222 path temp_directory_path();
223 path temp_directory_path(error_code& ec);
224
225 path weakly_canonical(path const& p);
226 path weakly_canonical(path const& p, error_code& ec);
227
228
229} } // namespaces std::filesystem
230
231*/
232
233#include <__config>
234#include <cstddef>
235#include <cstdlib>
236#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
246#include <string_view>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000247#include <version>
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000248
249#include <__debug>
250
251#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
252#pragma GCC system_header
253#endif
254
255_LIBCPP_PUSH_MACROS
256#include <__undef_macros>
257
258#ifndef _LIBCPP_CXX03_LANG
259
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000260_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
261
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000262typedef chrono::time_point<_FilesystemClock> file_time_type;
263
264struct _LIBCPP_TYPE_VIS space_info {
265 uintmax_t capacity;
266 uintmax_t free;
267 uintmax_t available;
268};
269
270enum class _LIBCPP_ENUM_VIS file_type : signed char {
271 none = 0,
272 not_found = -1,
273 regular = 1,
274 directory = 2,
275 symlink = 3,
276 block = 4,
277 character = 5,
278 fifo = 6,
279 socket = 7,
280 unknown = 8
281};
282
283enum class _LIBCPP_ENUM_VIS perms : unsigned {
284 none = 0,
285
286 owner_read = 0400,
287 owner_write = 0200,
288 owner_exec = 0100,
289 owner_all = 0700,
290
291 group_read = 040,
292 group_write = 020,
293 group_exec = 010,
294 group_all = 070,
295
296 others_read = 04,
297 others_write = 02,
298 others_exec = 01,
299 others_all = 07,
300
301 all = 0777,
302
303 set_uid = 04000,
304 set_gid = 02000,
305 sticky_bit = 01000,
306 mask = 07777,
307 unknown = 0xFFFF,
308};
309
310_LIBCPP_INLINE_VISIBILITY
311inline constexpr perms operator&(perms _LHS, perms _RHS) {
312 return static_cast<perms>(static_cast<unsigned>(_LHS) &
313 static_cast<unsigned>(_RHS));
314}
315
316_LIBCPP_INLINE_VISIBILITY
317inline constexpr perms operator|(perms _LHS, perms _RHS) {
318 return static_cast<perms>(static_cast<unsigned>(_LHS) |
319 static_cast<unsigned>(_RHS));
320}
321
322_LIBCPP_INLINE_VISIBILITY
323inline constexpr perms operator^(perms _LHS, perms _RHS) {
324 return static_cast<perms>(static_cast<unsigned>(_LHS) ^
325 static_cast<unsigned>(_RHS));
326}
327
328_LIBCPP_INLINE_VISIBILITY
329inline constexpr perms operator~(perms _LHS) {
330 return static_cast<perms>(~static_cast<unsigned>(_LHS));
331}
332
333_LIBCPP_INLINE_VISIBILITY
334inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; }
335
336_LIBCPP_INLINE_VISIBILITY
337inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; }
338
339_LIBCPP_INLINE_VISIBILITY
340inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; }
341
342enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
343 replace = 1,
344 add = 2,
345 remove = 4,
346 nofollow = 8
347};
348
349_LIBCPP_INLINE_VISIBILITY
350inline constexpr perm_options operator&(perm_options _LHS, perm_options _RHS) {
351 return static_cast<perm_options>(static_cast<unsigned>(_LHS) &
352 static_cast<unsigned>(_RHS));
353}
354
355_LIBCPP_INLINE_VISIBILITY
356inline constexpr perm_options operator|(perm_options _LHS, perm_options _RHS) {
357 return static_cast<perm_options>(static_cast<unsigned>(_LHS) |
358 static_cast<unsigned>(_RHS));
359}
360
361_LIBCPP_INLINE_VISIBILITY
362inline constexpr perm_options operator^(perm_options _LHS, perm_options _RHS) {
363 return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^
364 static_cast<unsigned>(_RHS));
365}
366
367_LIBCPP_INLINE_VISIBILITY
368inline constexpr perm_options operator~(perm_options _LHS) {
369 return static_cast<perm_options>(~static_cast<unsigned>(_LHS));
370}
371
372_LIBCPP_INLINE_VISIBILITY
373inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS) {
374 return _LHS = _LHS & _RHS;
375}
376
377_LIBCPP_INLINE_VISIBILITY
378inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS) {
379 return _LHS = _LHS | _RHS;
380}
381
382_LIBCPP_INLINE_VISIBILITY
383inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS) {
384 return _LHS = _LHS ^ _RHS;
385}
386
387enum class _LIBCPP_ENUM_VIS copy_options : unsigned short {
388 none = 0,
389 skip_existing = 1,
390 overwrite_existing = 2,
391 update_existing = 4,
392 recursive = 8,
393 copy_symlinks = 16,
394 skip_symlinks = 32,
395 directories_only = 64,
396 create_symlinks = 128,
397 create_hard_links = 256,
398 __in_recursive_copy = 512,
399};
400
401_LIBCPP_INLINE_VISIBILITY
402inline constexpr copy_options operator&(copy_options _LHS, copy_options _RHS) {
403 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) &
404 static_cast<unsigned short>(_RHS));
405}
406
407_LIBCPP_INLINE_VISIBILITY
408inline constexpr copy_options operator|(copy_options _LHS, copy_options _RHS) {
409 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) |
410 static_cast<unsigned short>(_RHS));
411}
412
413_LIBCPP_INLINE_VISIBILITY
414inline constexpr copy_options operator^(copy_options _LHS, copy_options _RHS) {
415 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^
416 static_cast<unsigned short>(_RHS));
417}
418
419_LIBCPP_INLINE_VISIBILITY
420inline constexpr copy_options operator~(copy_options _LHS) {
421 return static_cast<copy_options>(~static_cast<unsigned short>(_LHS));
422}
423
424_LIBCPP_INLINE_VISIBILITY
425inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) {
426 return _LHS = _LHS & _RHS;
427}
428
429_LIBCPP_INLINE_VISIBILITY
430inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) {
431 return _LHS = _LHS | _RHS;
432}
433
434_LIBCPP_INLINE_VISIBILITY
435inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) {
436 return _LHS = _LHS ^ _RHS;
437}
438
439enum class _LIBCPP_ENUM_VIS directory_options : unsigned char {
440 none = 0,
441 follow_directory_symlink = 1,
442 skip_permission_denied = 2
443};
444
445_LIBCPP_INLINE_VISIBILITY
446inline constexpr directory_options operator&(directory_options _LHS,
447 directory_options _RHS) {
448 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) &
449 static_cast<unsigned char>(_RHS));
450}
451
452_LIBCPP_INLINE_VISIBILITY
453inline constexpr directory_options operator|(directory_options _LHS,
454 directory_options _RHS) {
455 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) |
456 static_cast<unsigned char>(_RHS));
457}
458
459_LIBCPP_INLINE_VISIBILITY
460inline constexpr directory_options operator^(directory_options _LHS,
461 directory_options _RHS) {
462 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^
463 static_cast<unsigned char>(_RHS));
464}
465
466_LIBCPP_INLINE_VISIBILITY
467inline constexpr directory_options operator~(directory_options _LHS) {
468 return static_cast<directory_options>(~static_cast<unsigned char>(_LHS));
469}
470
471_LIBCPP_INLINE_VISIBILITY
472inline directory_options& operator&=(directory_options& _LHS,
473 directory_options _RHS) {
474 return _LHS = _LHS & _RHS;
475}
476
477_LIBCPP_INLINE_VISIBILITY
478inline directory_options& operator|=(directory_options& _LHS,
479 directory_options _RHS) {
480 return _LHS = _LHS | _RHS;
481}
482
483_LIBCPP_INLINE_VISIBILITY
484inline directory_options& operator^=(directory_options& _LHS,
485 directory_options _RHS) {
486 return _LHS = _LHS ^ _RHS;
487}
488
489class _LIBCPP_TYPE_VIS file_status {
490public:
491 // constructors
492 _LIBCPP_INLINE_VISIBILITY
493 file_status() noexcept : file_status(file_type::none) {}
494 _LIBCPP_INLINE_VISIBILITY
495 explicit file_status(file_type __ft, perms __prms = perms::unknown) noexcept
496 : __ft_(__ft),
497 __prms_(__prms) {}
498
499 file_status(const file_status&) noexcept = default;
500 file_status(file_status&&) noexcept = default;
501
502 _LIBCPP_INLINE_VISIBILITY
503 ~file_status() {}
504
505 file_status& operator=(const file_status&) noexcept = default;
506 file_status& operator=(file_status&&) noexcept = default;
507
508 // observers
509 _LIBCPP_INLINE_VISIBILITY
510 file_type type() const noexcept { return __ft_; }
511
512 _LIBCPP_INLINE_VISIBILITY
513 perms permissions() const noexcept { return __prms_; }
514
515 // modifiers
516 _LIBCPP_INLINE_VISIBILITY
517 void type(file_type __ft) noexcept { __ft_ = __ft; }
518
519 _LIBCPP_INLINE_VISIBILITY
520 void permissions(perms __p) noexcept { __prms_ = __p; }
521
522private:
523 file_type __ft_;
524 perms __prms_;
525};
526
527class _LIBCPP_TYPE_VIS directory_entry;
528
529template <class _Tp>
530struct __can_convert_char {
531 static const bool value = false;
532};
533template <class _Tp>
534struct __can_convert_char<const _Tp> : public __can_convert_char<_Tp> {};
535template <>
536struct __can_convert_char<char> {
537 static const bool value = true;
538 using __char_type = char;
539};
540template <>
541struct __can_convert_char<wchar_t> {
542 static const bool value = true;
543 using __char_type = wchar_t;
544};
545template <>
546struct __can_convert_char<char16_t> {
547 static const bool value = true;
548 using __char_type = char16_t;
549};
550template <>
551struct __can_convert_char<char32_t> {
552 static const bool value = true;
553 using __char_type = char32_t;
554};
555
556template <class _ECharT>
557typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
558__is_separator(_ECharT __e) {
559 return __e == _ECharT('/');
Eric Fiselierb41db9a2018-10-01 01:59:37 +0000560}
Eric Fiselier02cea5e2018-07-27 03:07:09 +0000561
562struct _NullSentinal {};
563
564template <class _Tp>
565using _Void = void;
566
567template <class _Tp, class = void>
568struct __is_pathable_string : public false_type {};
569
570template <class _ECharT, class _Traits, class _Alloc>
571struct __is_pathable_string<
572 basic_string<_ECharT, _Traits, _Alloc>,
573 _Void<typename __can_convert_char<_ECharT>::__char_type> >
574 : public __can_convert_char<_ECharT> {
575 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
576 using _Base = __can_convert_char<_ECharT>;
577 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
578 static _ECharT const* __range_end(_Str const& __s) {
579 return __s.data() + __s.length();
580 }
581 static _ECharT __first_or_null(_Str const& __s) {
582 return __s.empty() ? _ECharT{} : __s[0];
583 }
584};
585
586template <class _ECharT, class _Traits>
587struct __is_pathable_string<
588 basic_string_view<_ECharT, _Traits>,
589 _Void<typename __can_convert_char<_ECharT>::__char_type> >
590 : public __can_convert_char<_ECharT> {
591 using _Str = basic_string_view<_ECharT, _Traits>;
592 using _Base = __can_convert_char<_ECharT>;
593 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
594 static _ECharT const* __range_end(_Str const& __s) {
595 return __s.data() + __s.length();
596 }
597 static _ECharT __first_or_null(_Str const& __s) {
598 return __s.empty() ? _ECharT{} : __s[0];
599 }
600};
601
602template <class _Source, class _DS = typename decay<_Source>::type,
603 class _UnqualPtrType =
604 typename remove_const<typename remove_pointer<_DS>::type>::type,
605 bool _IsCharPtr = is_pointer<_DS>::value&&
606 __can_convert_char<_UnqualPtrType>::value>
607struct __is_pathable_char_array : false_type {};
608
609template <class _Source, class _ECharT, class _UPtr>
610struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
611 : __can_convert_char<typename remove_const<_ECharT>::type> {
612 using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
613
614 static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
615 static _ECharT const* __range_end(const _ECharT* __b) {
616 using _Iter = const _ECharT*;
617 const _ECharT __sentinal = _ECharT{};
618 _Iter __e = __b;
619 for (; *__e != __sentinal; ++__e)
620 ;
621 return __e;
622 }
623
624 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
625};
626
627template <class _Iter, bool _IsIt = __is_input_iterator<_Iter>::value,
628 class = void>
629struct __is_pathable_iter : false_type {};
630
631template <class _Iter>
632struct __is_pathable_iter<
633 _Iter, true,
634 _Void<typename __can_convert_char<
635 typename iterator_traits<_Iter>::value_type>::__char_type> >
636 : __can_convert_char<typename iterator_traits<_Iter>::value_type> {
637 using _ECharT = typename iterator_traits<_Iter>::value_type;
638 using _Base = __can_convert_char<_ECharT>;
639
640 static _Iter __range_begin(_Iter __b) { return __b; }
641 static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; }
642
643 static _ECharT __first_or_null(_Iter __b) { return *__b; }
644};
645
646template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
647 bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
648 bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value>
649struct __is_pathable : false_type {
650 static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
651};
652
653template <class _Tp>
654struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
655
656template <class _Tp>
657struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {
658};
659
660template <class _Tp>
661struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
662
663template <class _ECharT>
664struct _PathCVT {
665 static_assert(__can_convert_char<_ECharT>::value,
666 "Char type not convertible");
667
668 typedef __narrow_to_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Narrower;
669
670 static void __append_range(string& __dest, _ECharT const* __b,
671 _ECharT const* __e) {
672 _Narrower()(back_inserter(__dest), __b, __e);
673 }
674
675 template <class _Iter>
676 static void __append_range(string& __dest, _Iter __b, _Iter __e) {
677 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
678 if (__b == __e)
679 return;
680 basic_string<_ECharT> __tmp(__b, __e);
681 _Narrower()(back_inserter(__dest), __tmp.data(),
682 __tmp.data() + __tmp.length());
683 }
684
685 template <class _Iter>
686 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
687 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
688 const _ECharT __sentinal = _ECharT{};
689 if (*__b == __sentinal)
690 return;
691 basic_string<_ECharT> __tmp;
692 for (; *__b != __sentinal; ++__b)
693 __tmp.push_back(*__b);
694 _Narrower()(back_inserter(__dest), __tmp.data(),
695 __tmp.data() + __tmp.length());
696 }
697
698 template <class _Source>
699 static void __append_source(string& __dest, _Source const& __s) {
700 using _Traits = __is_pathable<_Source>;
701 __append_range(__dest, _Traits::__range_begin(__s),
702 _Traits::__range_end(__s));
703 }
704};
705
706template <>
707struct _PathCVT<char> {
708
709 template <class _Iter>
710 static typename enable_if<__is_exactly_input_iterator<_Iter>::value>::type
711 __append_range(string& __dest, _Iter __b, _Iter __e) {
712 for (; __b != __e; ++__b)
713 __dest.push_back(*__b);
714 }
715
716 template <class _Iter>
717 static typename enable_if<__is_forward_iterator<_Iter>::value>::type
718 __append_range(string& __dest, _Iter __b, _Iter __e) {
719 __dest.__append_forward_unsafe(__b, __e);
720 }
721
722 template <class _Iter>
723 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
724 const char __sentinal = char{};
725 for (; *__b != __sentinal; ++__b)
726 __dest.push_back(*__b);
727 }
728
729 template <class _Source>
730 static void __append_source(string& __dest, _Source const& __s) {
731 using _Traits = __is_pathable<_Source>;
732 __append_range(__dest, _Traits::__range_begin(__s),
733 _Traits::__range_end(__s));
734 }
735};
736
737class _LIBCPP_TYPE_VIS path {
738 template <class _SourceOrIter, class _Tp = path&>
739 using _EnableIfPathable =
740 typename enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
741
742 template <class _Tp>
743 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
744
745 template <class _Tp>
746 using _SourceCVT = _PathCVT<_SourceChar<_Tp> >;
747
748public:
749 typedef char value_type;
750 typedef basic_string<value_type> string_type;
751 typedef _VSTD::string_view __string_view;
752 static constexpr value_type preferred_separator = '/';
753
754 enum class _LIBCPP_ENUM_VIS format : unsigned char {
755 auto_format,
756 native_format,
757 generic_format
758 };
759
760 // constructors and destructor
761 _LIBCPP_INLINE_VISIBILITY path() noexcept {}
762 _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
763 _LIBCPP_INLINE_VISIBILITY path(path&& __p) noexcept
764 : __pn_(_VSTD::move(__p.__pn_)) {}
765
766 _LIBCPP_INLINE_VISIBILITY
767 path(string_type&& __s, format = format::auto_format) noexcept
768 : __pn_(_VSTD::move(__s)) {}
769
770 template <class _Source, class = _EnableIfPathable<_Source, void> >
771 path(const _Source& __src, format = format::auto_format) {
772 _SourceCVT<_Source>::__append_source(__pn_, __src);
773 }
774
775 template <class _InputIt>
776 path(_InputIt __first, _InputIt __last, format = format::auto_format) {
777 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
778 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
779 }
780
781 // TODO Implement locale conversions.
782 template <class _Source, class = _EnableIfPathable<_Source, void> >
783 path(const _Source& __src, const locale& __loc, format = format::auto_format);
784 template <class _InputIt>
785 path(_InputIt __first, _InputIt _last, const locale& __loc,
786 format = format::auto_format);
787
788 _LIBCPP_INLINE_VISIBILITY
789 ~path() = default;
790
791 // assignments
792 _LIBCPP_INLINE_VISIBILITY
793 path& operator=(const path& __p) {
794 __pn_ = __p.__pn_;
795 return *this;
796 }
797
798 _LIBCPP_INLINE_VISIBILITY
799 path& operator=(path&& __p) noexcept {
800 __pn_ = _VSTD::move(__p.__pn_);
801 return *this;
802 }
803
804 template <class = void>
805 _LIBCPP_INLINE_VISIBILITY path& operator=(string_type&& __s) noexcept {
806 __pn_ = _VSTD::move(__s);
807 return *this;
808 }
809
810 _LIBCPP_INLINE_VISIBILITY
811 path& assign(string_type&& __s) noexcept {
812 __pn_ = _VSTD::move(__s);
813 return *this;
814 }
815
816 template <class _Source>
817 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
818 operator=(const _Source& __src) {
819 return this->assign(__src);
820 }
821
822 template <class _Source>
823 _EnableIfPathable<_Source> assign(const _Source& __src) {
824 __pn_.clear();
825 _SourceCVT<_Source>::__append_source(__pn_, __src);
826 return *this;
827 }
828
829 template <class _InputIt>
830 path& assign(_InputIt __first, _InputIt __last) {
831 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
832 __pn_.clear();
833 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
834 return *this;
835 }
836
837private:
838 template <class _ECharT>
839 static bool __source_is_absolute(_ECharT __first_or_null) {
840 return __is_separator(__first_or_null);
841 }
842
843public:
844 // appends
845 path& operator/=(const path& __p) {
846 if (__p.is_absolute()) {
847 __pn_ = __p.__pn_;
848 return *this;
849 }
850 if (has_filename())
851 __pn_ += preferred_separator;
852 __pn_ += __p.native();
853 return *this;
854 }
855
856 // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
857 // is known at compile time to be "/' since the user almost certainly intended
858 // to append a separator instead of overwriting the path with "/"
859 template <class _Source>
860 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
861 operator/=(const _Source& __src) {
862 return this->append(__src);
863 }
864
865 template <class _Source>
866 _EnableIfPathable<_Source> append(const _Source& __src) {
867 using _Traits = __is_pathable<_Source>;
868 using _CVT = _PathCVT<_SourceChar<_Source> >;
869 if (__source_is_absolute(_Traits::__first_or_null(__src)))
870 __pn_.clear();
871 else if (has_filename())
872 __pn_ += preferred_separator;
873 _CVT::__append_source(__pn_, __src);
874 return *this;
875 }
876
877 template <class _InputIt>
878 path& append(_InputIt __first, _InputIt __last) {
879 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
880 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
881 using _CVT = _PathCVT<_ItVal>;
882 if (__first != __last && __source_is_absolute(*__first))
883 __pn_.clear();
884 else if (has_filename())
885 __pn_ += preferred_separator;
886 _CVT::__append_range(__pn_, __first, __last);
887 return *this;
888 }
889
890 // concatenation
891 _LIBCPP_INLINE_VISIBILITY
892 path& operator+=(const path& __x) {
893 __pn_ += __x.__pn_;
894 return *this;
895 }
896
897 _LIBCPP_INLINE_VISIBILITY
898 path& operator+=(const string_type& __x) {
899 __pn_ += __x;
900 return *this;
901 }
902
903 _LIBCPP_INLINE_VISIBILITY
904 path& operator+=(__string_view __x) {
905 __pn_ += __x;
906 return *this;
907 }
908
909 _LIBCPP_INLINE_VISIBILITY
910 path& operator+=(const value_type* __x) {
911 __pn_ += __x;
912 return *this;
913 }
914
915 _LIBCPP_INLINE_VISIBILITY
916 path& operator+=(value_type __x) {
917 __pn_ += __x;
918 return *this;
919 }
920
921 template <class _ECharT>
922 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
923 operator+=(_ECharT __x) {
924 basic_string<_ECharT> __tmp;
925 __tmp += __x;
926 _PathCVT<_ECharT>::__append_source(__pn_, __tmp);
927 return *this;
928 }
929
930 template <class _Source>
931 _EnableIfPathable<_Source> operator+=(const _Source& __x) {
932 return this->concat(__x);
933 }
934
935 template <class _Source>
936 _EnableIfPathable<_Source> concat(const _Source& __x) {
937 _SourceCVT<_Source>::__append_source(__pn_, __x);
938 return *this;
939 }
940
941 template <class _InputIt>
942 path& concat(_InputIt __first, _InputIt __last) {
943 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
944 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
945 return *this;
946 }
947
948 // modifiers
949 _LIBCPP_INLINE_VISIBILITY
950 void clear() noexcept { __pn_.clear(); }
951
952 path& make_preferred() { return *this; }
953
954 _LIBCPP_INLINE_VISIBILITY
955 path& remove_filename() {
956 auto __fname = __filename();
957 if (!__fname.empty())
958 __pn_.erase(__fname.data() - __pn_.data());
959 return *this;
960 }
961
962 path& replace_filename(const path& __replacement) {
963 remove_filename();
964 return (*this /= __replacement);
965 }
966
967 path& replace_extension(const path& __replacement = path());
968
969 _LIBCPP_INLINE_VISIBILITY
970 void swap(path& __rhs) noexcept { __pn_.swap(__rhs.__pn_); }
971
972 // private helper to allow reserving memory in the path
973 _LIBCPP_INLINE_VISIBILITY
974 void __reserve(size_t __s) { __pn_.reserve(__s); }
975
976 // native format observers
977 _LIBCPP_INLINE_VISIBILITY
978 const string_type& native() const noexcept { return __pn_; }
979
980 _LIBCPP_INLINE_VISIBILITY
981 const value_type* c_str() const noexcept { return __pn_.c_str(); }
982
983 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
984
985 template <class _ECharT, class _Traits = char_traits<_ECharT>,
986 class _Allocator = allocator<_ECharT> >
987 basic_string<_ECharT, _Traits, _Allocator>
988 string(const _Allocator& __a = _Allocator()) const {
989 using _CVT = __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__>;
990 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
991 _Str __s(__a);
992 __s.reserve(__pn_.size());
993 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
994 return __s;
995 }
996
997 _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; }
998 _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const {
999 return string<wchar_t>();
1000 }
1001 _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; }
1002 _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const {
1003 return string<char16_t>();
1004 }
1005 _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const {
1006 return string<char32_t>();
1007 }
1008
1009 // generic format observers
1010 template <class _ECharT, class _Traits = char_traits<_ECharT>,
1011 class _Allocator = allocator<_ECharT> >
1012 basic_string<_ECharT, _Traits, _Allocator>
1013 generic_string(const _Allocator& __a = _Allocator()) const {
1014 return string<_ECharT, _Traits, _Allocator>(__a);
1015 }
1016
1017 std::string generic_string() const { return __pn_; }
1018 std::wstring generic_wstring() const { return string<wchar_t>(); }
1019 std::string generic_u8string() const { return __pn_; }
1020 std::u16string generic_u16string() const { return string<char16_t>(); }
1021 std::u32string generic_u32string() const { return string<char32_t>(); }
1022
1023private:
1024 int __compare(__string_view) const;
1025 __string_view __root_name() const;
1026 __string_view __root_directory() const;
1027 __string_view __root_path_raw() const;
1028 __string_view __relative_path() const;
1029 __string_view __parent_path() const;
1030 __string_view __filename() const;
1031 __string_view __stem() const;
1032 __string_view __extension() const;
1033
1034public:
1035 // compare
1036 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept {
1037 return __compare(__p.__pn_);
1038 }
1039 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const {
1040 return __compare(__s);
1041 }
1042 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const {
1043 return __compare(__s);
1044 }
1045 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const {
1046 return __compare(__s);
1047 }
1048
1049 // decomposition
1050 _LIBCPP_INLINE_VISIBILITY path root_name() const {
1051 return string_type(__root_name());
1052 }
1053 _LIBCPP_INLINE_VISIBILITY path root_directory() const {
1054 return string_type(__root_directory());
1055 }
1056 _LIBCPP_INLINE_VISIBILITY path root_path() const {
1057 return root_name().append(string_type(__root_directory()));
1058 }
1059 _LIBCPP_INLINE_VISIBILITY path relative_path() const {
1060 return string_type(__relative_path());
1061 }
1062 _LIBCPP_INLINE_VISIBILITY path parent_path() const {
1063 return string_type(__parent_path());
1064 }
1065 _LIBCPP_INLINE_VISIBILITY path filename() const {
1066 return string_type(__filename());
1067 }
1068 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem()); }
1069 _LIBCPP_INLINE_VISIBILITY path extension() const {
1070 return string_type(__extension());
1071 }
1072
1073 // query
1074 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool
1075 empty() const noexcept {
1076 return __pn_.empty();
1077 }
1078
1079 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const {
1080 return !__root_name().empty();
1081 }
1082 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const {
1083 return !__root_directory().empty();
1084 }
1085 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const {
1086 return !__root_path_raw().empty();
1087 }
1088 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const {
1089 return !__relative_path().empty();
1090 }
1091 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const {
1092 return !__parent_path().empty();
1093 }
1094 _LIBCPP_INLINE_VISIBILITY bool has_filename() const {
1095 return !__filename().empty();
1096 }
1097 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
1098 _LIBCPP_INLINE_VISIBILITY bool has_extension() const {
1099 return !__extension().empty();
1100 }
1101
1102 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const {
1103 return has_root_directory();
1104 }
1105 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
1106
1107 // relative paths
1108 path lexically_normal() const;
1109 path lexically_relative(const path& __base) const;
1110
1111 _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
1112 path __result = this->lexically_relative(__base);
1113 if (__result.native().empty())
1114 return *this;
1115 return __result;
1116 }
1117
1118 // iterators
1119 class _LIBCPP_TYPE_VIS iterator;
1120 typedef iterator const_iterator;
1121
1122 iterator begin() const;
1123 iterator end() const;
1124
1125 template <class _CharT, class _Traits>
1126 _LIBCPP_INLINE_VISIBILITY friend
1127 typename enable_if<is_same<_CharT, char>::value &&
1128 is_same<_Traits, char_traits<char> >::value,
1129 basic_ostream<_CharT, _Traits>&>::type
1130 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1131 __os << std::__quoted(__p.native());
1132 return __os;
1133 }
1134
1135 template <class _CharT, class _Traits>
1136 _LIBCPP_INLINE_VISIBILITY friend
1137 typename enable_if<!is_same<_CharT, char>::value ||
1138 !is_same<_Traits, char_traits<char> >::value,
1139 basic_ostream<_CharT, _Traits>&>::type
1140 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1141 __os << std::__quoted(__p.string<_CharT, _Traits>());
1142 return __os;
1143 }
1144
1145 template <class _CharT, class _Traits>
1146 _LIBCPP_INLINE_VISIBILITY friend basic_istream<_CharT, _Traits>&
1147 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) {
1148 basic_string<_CharT, _Traits> __tmp;
1149 __is >> __quoted(__tmp);
1150 __p = __tmp;
1151 return __is;
1152 }
1153
1154private:
1155 inline _LIBCPP_INLINE_VISIBILITY path&
1156 __assign_view(__string_view const& __s) noexcept {
1157 __pn_ = string_type(__s);
1158 return *this;
1159 }
1160 string_type __pn_;
1161};
1162
1163inline _LIBCPP_INLINE_VISIBILITY void swap(path& __lhs, path& __rhs) noexcept {
1164 __lhs.swap(__rhs);
1165}
1166
1167_LIBCPP_FUNC_VIS
1168size_t hash_value(const path& __p) noexcept;
1169
1170inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs,
1171 const path& __rhs) noexcept {
1172 return __lhs.compare(__rhs) == 0;
1173}
1174
1175inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs,
1176 const path& __rhs) noexcept {
1177 return __lhs.compare(__rhs) != 0;
1178}
1179
1180inline _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs,
1181 const path& __rhs) noexcept {
1182 return __lhs.compare(__rhs) < 0;
1183}
1184
1185inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs,
1186 const path& __rhs) noexcept {
1187 return __lhs.compare(__rhs) <= 0;
1188}
1189
1190inline _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs,
1191 const path& __rhs) noexcept {
1192 return __lhs.compare(__rhs) > 0;
1193}
1194
1195inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs,
1196 const path& __rhs) noexcept {
1197 return __lhs.compare(__rhs) >= 0;
1198}
1199
1200inline _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs,
1201 const path& __rhs) {
1202 path __result(__lhs);
1203 __result /= __rhs;
1204 return __result;
1205}
1206
1207template <class _Source>
1208_LIBCPP_INLINE_VISIBILITY
1209 typename enable_if<__is_pathable<_Source>::value, path>::type
1210 u8path(const _Source& __s) {
1211 static_assert(
1212 is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1213 "u8path(Source const&) requires Source have a character type of type "
1214 "'char'");
1215 return path(__s);
1216}
1217
1218template <class _InputIt>
1219_LIBCPP_INLINE_VISIBILITY
1220 typename enable_if<__is_pathable<_InputIt>::value, path>::type
1221 u8path(_InputIt __f, _InputIt __l) {
1222 static_assert(
1223 is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1224 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
1225 return path(__f, __l);
1226}
1227
1228class _LIBCPP_TYPE_VIS path::iterator {
1229public:
1230 enum _ParserState : unsigned char {
1231 _Singular,
1232 _BeforeBegin,
1233 _InRootName,
1234 _InRootDir,
1235 _InFilenames,
1236 _InTrailingSep,
1237 _AtEnd
1238 };
1239
1240public:
1241 typedef bidirectional_iterator_tag iterator_category;
1242
1243 typedef path value_type;
1244 typedef std::ptrdiff_t difference_type;
1245 typedef const path* pointer;
1246 typedef const path& reference;
1247
1248 typedef void
1249 __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
1250
1251public:
1252 _LIBCPP_INLINE_VISIBILITY
1253 iterator()
1254 : __stashed_elem_(), __path_ptr_(nullptr), __entry_(),
1255 __state_(_Singular) {}
1256
1257 iterator(const iterator&) = default;
1258 ~iterator() = default;
1259
1260 iterator& operator=(const iterator&) = default;
1261
1262 _LIBCPP_INLINE_VISIBILITY
1263 reference operator*() const { return __stashed_elem_; }
1264
1265 _LIBCPP_INLINE_VISIBILITY
1266 pointer operator->() const { return &__stashed_elem_; }
1267
1268 _LIBCPP_INLINE_VISIBILITY
1269 iterator& operator++() {
1270 _LIBCPP_ASSERT(__state_ != _Singular,
1271 "attempting to increment a singular iterator");
1272 _LIBCPP_ASSERT(__state_ != _AtEnd,
1273 "attempting to increment the end iterator");
1274 return __increment();
1275 }
1276
1277 _LIBCPP_INLINE_VISIBILITY
1278 iterator operator++(int) {
1279 iterator __it(*this);
1280 this->operator++();
1281 return __it;
1282 }
1283
1284 _LIBCPP_INLINE_VISIBILITY
1285 iterator& operator--() {
1286 _LIBCPP_ASSERT(__state_ != _Singular,
1287 "attempting to decrement a singular iterator");
1288 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
1289 "attempting to decrement the begin iterator");
1290 return __decrement();
1291 }
1292
1293 _LIBCPP_INLINE_VISIBILITY
1294 iterator operator--(int) {
1295 iterator __it(*this);
1296 this->operator--();
1297 return __it;
1298 }
1299
1300private:
1301 friend class path;
1302
1303 inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&,
1304 const iterator&);
1305
1306 iterator& __increment();
1307 iterator& __decrement();
1308
1309 path __stashed_elem_;
1310 const path* __path_ptr_;
1311 path::__string_view __entry_;
1312 _ParserState __state_;
1313};
1314
1315inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs,
1316 const path::iterator& __rhs) {
1317 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
1318 __lhs.__entry_.data() == __rhs.__entry_.data();
1319}
1320
1321inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs,
1322 const path::iterator& __rhs) {
1323 return !(__lhs == __rhs);
1324}
1325
1326class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error {
1327public:
1328 _LIBCPP_INLINE_VISIBILITY
1329 filesystem_error(const string& __what, error_code __ec)
1330 : system_error(__ec, __what),
1331 __storage_(make_shared<_Storage>(path(), path())) {
1332 __create_what(0);
1333 }
1334
1335 _LIBCPP_INLINE_VISIBILITY
1336 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1337 : system_error(__ec, __what),
1338 __storage_(make_shared<_Storage>(__p1, path())) {
1339 __create_what(1);
1340 }
1341
1342 _LIBCPP_INLINE_VISIBILITY
1343 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1344 error_code __ec)
1345 : system_error(__ec, __what),
1346 __storage_(make_shared<_Storage>(__p1, __p2)) {
1347 __create_what(2);
1348 }
1349
1350 _LIBCPP_INLINE_VISIBILITY
1351 const path& path1() const noexcept { return __storage_->__p1_; }
1352
1353 _LIBCPP_INLINE_VISIBILITY
1354 const path& path2() const noexcept { return __storage_->__p2_; }
1355
1356 ~filesystem_error() override; // key function
1357
1358 _LIBCPP_INLINE_VISIBILITY
1359 const char* what() const noexcept override {
1360 return __storage_->__what_.c_str();
1361 }
1362
1363 _LIBCPP_FUNC_VIS
1364 void __create_what(int __num_paths);
1365
1366private:
1367 struct _Storage {
1368 _LIBCPP_INLINE_VISIBILITY
1369 _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}
1370
1371 path __p1_;
1372 path __p2_;
1373 string __what_;
1374 };
1375 shared_ptr<_Storage> __storage_;
1376};
1377
1378template <class... _Args>
1379_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
1380#ifndef _LIBCPP_NO_EXCEPTIONS
1381 void
1382 __throw_filesystem_error(_Args&&... __args) {
1383 throw filesystem_error(std::forward<_Args>(__args)...);
1384}
1385#else
1386 void
1387 __throw_filesystem_error(_Args&&...) {
1388 _VSTD::abort();
1389}
1390#endif
1391
1392// operational functions
1393
1394_LIBCPP_FUNC_VIS
1395path __absolute(const path&, error_code* __ec = nullptr);
1396_LIBCPP_FUNC_VIS
1397path __canonical(const path&, error_code* __ec = nullptr);
1398_LIBCPP_FUNC_VIS
1399void __copy(const path& __from, const path& __to, copy_options __opt,
1400 error_code* __ec = nullptr);
1401_LIBCPP_FUNC_VIS
1402bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1403 error_code* __ec = nullptr);
1404_LIBCPP_FUNC_VIS
1405void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1406 error_code* __ec = nullptr);
1407_LIBCPP_FUNC_VIS
1408bool __create_directories(const path& p, error_code* ec = nullptr);
1409_LIBCPP_FUNC_VIS
1410bool __create_directory(const path& p, error_code* ec = nullptr);
1411_LIBCPP_FUNC_VIS
1412bool __create_directory(const path& p, const path& attributes,
1413 error_code* ec = nullptr);
1414_LIBCPP_FUNC_VIS
1415void __create_directory_symlink(const path& __to, const path& __new_symlink,
1416 error_code* __ec = nullptr);
1417_LIBCPP_FUNC_VIS
1418void __create_hard_link(const path& __to, const path& __new_hard_link,
1419 error_code* __ec = nullptr);
1420_LIBCPP_FUNC_VIS
1421void __create_symlink(const path& __to, const path& __new_symlink,
1422 error_code* __ec = nullptr);
1423_LIBCPP_FUNC_VIS
1424path __current_path(error_code* __ec = nullptr);
1425_LIBCPP_FUNC_VIS
1426void __current_path(const path&, error_code* __ec = nullptr);
1427_LIBCPP_FUNC_VIS
1428bool __equivalent(const path&, const path&, error_code* __ec = nullptr);
1429_LIBCPP_FUNC_VIS
1430uintmax_t __file_size(const path&, error_code* __ec = nullptr);
1431_LIBCPP_FUNC_VIS
1432uintmax_t __hard_link_count(const path&, error_code* __ec = nullptr);
1433_LIBCPP_FUNC_VIS
1434bool __fs_is_empty(const path& p, error_code* ec = nullptr);
1435_LIBCPP_FUNC_VIS
1436file_time_type __last_write_time(const path& p, error_code* ec = nullptr);
1437_LIBCPP_FUNC_VIS
1438void __last_write_time(const path& p, file_time_type new_time,
1439 error_code* ec = nullptr);
1440_LIBCPP_FUNC_VIS
1441void __permissions(const path&, perms, perm_options, error_code* = nullptr);
1442_LIBCPP_FUNC_VIS
1443path __read_symlink(const path& p, error_code* ec = nullptr);
1444_LIBCPP_FUNC_VIS
1445bool __remove(const path& p, error_code* ec = nullptr);
1446_LIBCPP_FUNC_VIS
1447uintmax_t __remove_all(const path& p, error_code* ec = nullptr);
1448_LIBCPP_FUNC_VIS
1449void __rename(const path& from, const path& to, error_code* ec = nullptr);
1450_LIBCPP_FUNC_VIS
1451void __resize_file(const path& p, uintmax_t size, error_code* ec = nullptr);
1452_LIBCPP_FUNC_VIS
1453space_info __space(const path&, error_code* __ec = nullptr);
1454_LIBCPP_FUNC_VIS
1455file_status __status(const path&, error_code* __ec = nullptr);
1456_LIBCPP_FUNC_VIS
1457file_status __symlink_status(const path&, error_code* __ec = nullptr);
1458_LIBCPP_FUNC_VIS
1459path __system_complete(const path&, error_code* __ec = nullptr);
1460_LIBCPP_FUNC_VIS
1461path __temp_directory_path(error_code* __ec = nullptr);
1462_LIBCPP_FUNC_VIS
1463path __weakly_canonical(path const& __p, error_code* __ec = nullptr);
1464
1465inline _LIBCPP_INLINE_VISIBILITY path current_path() {
1466 return __current_path();
1467}
1468
1469inline _LIBCPP_INLINE_VISIBILITY path current_path(error_code& __ec) {
1470 return __current_path(&__ec);
1471}
1472
1473inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p) {
1474 __current_path(__p);
1475}
1476
1477inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p,
1478 error_code& __ec) noexcept {
1479 __current_path(__p, &__ec);
1480}
1481
1482inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p) {
1483 return __absolute(__p);
1484}
1485
1486inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p,
1487 error_code& __ec) {
1488 return __absolute(__p, &__ec);
1489}
1490
1491inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p) {
1492 return __canonical(__p);
1493}
1494
1495inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p,
1496 error_code& __ec) {
1497 return __canonical(__p, &__ec);
1498}
1499
1500inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from,
1501 const path& __to) {
1502 __copy(__from, __to, copy_options::none);
1503}
1504
1505inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1506 error_code& __ec) {
1507 __copy(__from, __to, copy_options::none, &__ec);
1508}
1509
1510inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1511 copy_options __opt) {
1512 __copy(__from, __to, __opt);
1513}
1514
1515inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1516 copy_options __opt,
1517 error_code& __ec) {
1518 __copy(__from, __to, __opt, &__ec);
1519}
1520
1521inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
1522 const path& __to) {
1523 return __copy_file(__from, __to, copy_options::none);
1524}
1525
1526inline _LIBCPP_INLINE_VISIBILITY bool
1527copy_file(const path& __from, const path& __to, error_code& __ec) {
1528 return __copy_file(__from, __to, copy_options::none, &__ec);
1529}
1530
1531inline _LIBCPP_INLINE_VISIBILITY bool
1532copy_file(const path& __from, const path& __to, copy_options __opt) {
1533 return __copy_file(__from, __to, __opt);
1534}
1535
1536inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
1537 const path& __to,
1538 copy_options __opt,
1539 error_code& __ec) {
1540 return __copy_file(__from, __to, __opt, &__ec);
1541}
1542
1543inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __existing,
1544 const path& __new) {
1545 __copy_symlink(__existing, __new);
1546}
1547
1548inline _LIBCPP_INLINE_VISIBILITY void
1549copy_symlink(const path& __ext, const path& __new, error_code& __ec) noexcept {
1550 __copy_symlink(__ext, __new, &__ec);
1551}
1552
1553inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p) {
1554 return __create_directories(__p);
1555}
1556
1557inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p,
1558 error_code& __ec) {
1559 return __create_directories(__p, &__ec);
1560}
1561
1562inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p) {
1563 return __create_directory(__p);
1564}
1565
1566inline _LIBCPP_INLINE_VISIBILITY bool
1567create_directory(const path& __p, error_code& __ec) noexcept {
1568 return __create_directory(__p, &__ec);
1569}
1570
1571inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p,
1572 const path& __attrs) {
1573 return __create_directory(__p, __attrs);
1574}
1575
1576inline _LIBCPP_INLINE_VISIBILITY bool
1577create_directory(const path& __p, const path& __attrs,
1578 error_code& __ec) noexcept {
1579 return __create_directory(__p, __attrs, &__ec);
1580}
1581
1582inline _LIBCPP_INLINE_VISIBILITY void
1583create_directory_symlink(const path& __to, const path& __new) {
1584 __create_directory_symlink(__to, __new);
1585}
1586
1587inline _LIBCPP_INLINE_VISIBILITY void
1588create_directory_symlink(const path& __to, const path& __new,
1589 error_code& __ec) noexcept {
1590 __create_directory_symlink(__to, __new, &__ec);
1591}
1592
1593inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __to,
1594 const path& __new) {
1595 __create_hard_link(__to, __new);
1596}
1597
1598inline _LIBCPP_INLINE_VISIBILITY void
1599create_hard_link(const path& __to, const path& __new,
1600 error_code& __ec) noexcept {
1601 __create_hard_link(__to, __new, &__ec);
1602}
1603
1604inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __to,
1605 const path& __new) {
1606 __create_symlink(__to, __new);
1607}
1608
1609inline _LIBCPP_INLINE_VISIBILITY void
1610create_symlink(const path& __to, const path& __new, error_code& __ec) noexcept {
1611 return __create_symlink(__to, __new, &__ec);
1612}
1613
1614inline _LIBCPP_INLINE_VISIBILITY bool status_known(file_status __s) noexcept {
1615 return __s.type() != file_type::none;
1616}
1617
1618inline _LIBCPP_INLINE_VISIBILITY bool exists(file_status __s) noexcept {
1619 return status_known(__s) && __s.type() != file_type::not_found;
1620}
1621
1622inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p) {
1623 return exists(__status(__p));
1624}
1625
1626inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p,
1627 error_code& __ec) noexcept {
1628 auto __s = __status(__p, &__ec);
1629 if (status_known(__s))
1630 __ec.clear();
1631 return exists(__s);
1632}
1633
1634inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1,
1635 const path& __p2) {
1636 return __equivalent(__p1, __p2);
1637}
1638
1639inline _LIBCPP_INLINE_VISIBILITY bool
1640equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept {
1641 return __equivalent(__p1, __p2, &__ec);
1642}
1643
1644inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p) {
1645 return __file_size(__p);
1646}
1647
1648inline _LIBCPP_INLINE_VISIBILITY uintmax_t
1649file_size(const path& __p, error_code& __ec) noexcept {
1650 return __file_size(__p, &__ec);
1651}
1652
1653inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p) {
1654 return __hard_link_count(__p);
1655}
1656
1657inline _LIBCPP_INLINE_VISIBILITY uintmax_t
1658hard_link_count(const path& __p, error_code& __ec) noexcept {
1659 return __hard_link_count(__p, &__ec);
1660}
1661
1662inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(file_status __s) noexcept {
1663 return __s.type() == file_type::block;
1664}
1665
1666inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p) {
1667 return is_block_file(__status(__p));
1668}
1669
1670inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p,
1671 error_code& __ec) noexcept {
1672 return is_block_file(__status(__p, &__ec));
1673}
1674
1675inline _LIBCPP_INLINE_VISIBILITY bool
1676is_character_file(file_status __s) noexcept {
1677 return __s.type() == file_type::character;
1678}
1679
1680inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p) {
1681 return is_character_file(__status(__p));
1682}
1683
1684inline _LIBCPP_INLINE_VISIBILITY bool
1685is_character_file(const path& __p, error_code& __ec) noexcept {
1686 return is_character_file(__status(__p, &__ec));
1687}
1688
1689inline _LIBCPP_INLINE_VISIBILITY bool is_directory(file_status __s) noexcept {
1690 return __s.type() == file_type::directory;
1691}
1692
1693inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p) {
1694 return is_directory(__status(__p));
1695}
1696
1697inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p,
1698 error_code& __ec) noexcept {
1699 return is_directory(__status(__p, &__ec));
1700}
1701
1702inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p) {
1703 return __fs_is_empty(__p);
1704}
1705
1706inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p,
1707 error_code& __ec) {
1708 return __fs_is_empty(__p, &__ec);
1709}
1710
1711inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(file_status __s) noexcept {
1712 return __s.type() == file_type::fifo;
1713}
1714inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p) {
1715 return is_fifo(__status(__p));
1716}
1717
1718inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p,
1719 error_code& __ec) noexcept {
1720 return is_fifo(__status(__p, &__ec));
1721}
1722
1723inline _LIBCPP_INLINE_VISIBILITY bool
1724is_regular_file(file_status __s) noexcept {
1725 return __s.type() == file_type::regular;
1726}
1727
1728inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p) {
1729 return is_regular_file(__status(__p));
1730}
1731
1732inline _LIBCPP_INLINE_VISIBILITY bool
1733is_regular_file(const path& __p, error_code& __ec) noexcept {
1734 return is_regular_file(__status(__p, &__ec));
1735}
1736
1737inline _LIBCPP_INLINE_VISIBILITY bool is_socket(file_status __s) noexcept {
1738 return __s.type() == file_type::socket;
1739}
1740
1741inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p) {
1742 return is_socket(__status(__p));
1743}
1744
1745inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p,
1746 error_code& __ec) noexcept {
1747 return is_socket(__status(__p, &__ec));
1748}
1749
1750inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(file_status __s) noexcept {
1751 return __s.type() == file_type::symlink;
1752}
1753
1754inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p) {
1755 return is_symlink(__symlink_status(__p));
1756}
1757
1758inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p,
1759 error_code& __ec) noexcept {
1760 return is_symlink(__symlink_status(__p, &__ec));
1761}
1762
1763inline _LIBCPP_INLINE_VISIBILITY bool is_other(file_status __s) noexcept {
1764 return exists(__s) && !is_regular_file(__s) && !is_directory(__s) &&
1765 !is_symlink(__s);
1766}
1767
1768inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p) {
1769 return is_other(__status(__p));
1770}
1771
1772inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p,
1773 error_code& __ec) noexcept {
1774 return is_other(__status(__p, &__ec));
1775}
1776
1777inline _LIBCPP_INLINE_VISIBILITY file_time_type
1778last_write_time(const path& __p) {
1779 return __last_write_time(__p);
1780}
1781
1782inline _LIBCPP_INLINE_VISIBILITY file_time_type
1783last_write_time(const path& __p, error_code& __ec) noexcept {
1784 return __last_write_time(__p, &__ec);
1785}
1786
1787inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p,
1788 file_time_type __t) {
1789 __last_write_time(__p, __t);
1790}
1791
1792inline _LIBCPP_INLINE_VISIBILITY void
1793last_write_time(const path& __p, file_time_type __t,
1794 error_code& __ec) noexcept {
1795 __last_write_time(__p, __t, &__ec);
1796}
1797
1798inline _LIBCPP_INLINE_VISIBILITY void
1799permissions(const path& __p, perms __prms,
1800 perm_options __opts = perm_options::replace) {
1801 __permissions(__p, __prms, __opts);
1802}
1803
1804inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms,
1805 error_code& __ec) noexcept {
1806 __permissions(__p, __prms, perm_options::replace, &__ec);
1807}
1808
1809inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms,
1810 perm_options __opts,
1811 error_code& __ec) {
1812 __permissions(__p, __prms, __opts, &__ec);
1813}
1814
1815inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p,
1816 const path& __base,
1817 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 path proximate(const path& __p,
1828 error_code& __ec) {
1829 return proximate(__p, current_path(), __ec);
1830}
1831
1832inline _LIBCPP_INLINE_VISIBILITY path
1833proximate(const path& __p, const path& __base = current_path()) {
1834 return __weakly_canonical(__p).lexically_proximate(
1835 __weakly_canonical(__base));
1836}
1837
1838inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p) {
1839 return __read_symlink(__p);
1840}
1841
1842inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p,
1843 error_code& __ec) {
1844 return __read_symlink(__p, &__ec);
1845}
1846
1847inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p,
1848 const path& __base,
1849 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 path relative(const path& __p,
1860 error_code& __ec) {
1861 return relative(__p, current_path(), __ec);
1862}
1863
1864inline _LIBCPP_INLINE_VISIBILITY path
1865relative(const path& __p, const path& __base = current_path()) {
1866 return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base));
1867}
1868
1869inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p) {
1870 return __remove(__p);
1871}
1872
1873inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p,
1874 error_code& __ec) noexcept {
1875 return __remove(__p, &__ec);
1876}
1877
1878inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p) {
1879 return __remove_all(__p);
1880}
1881
1882inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p,
1883 error_code& __ec) {
1884 return __remove_all(__p, &__ec);
1885}
1886
1887inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from,
1888 const path& __to) {
1889 return __rename(__from, __to);
1890}
1891
1892inline _LIBCPP_INLINE_VISIBILITY void
1893rename(const path& __from, const path& __to, error_code& __ec) noexcept {
1894 return __rename(__from, __to, &__ec);
1895}
1896
1897inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p,
1898 uintmax_t __ns) {
1899 return __resize_file(__p, __ns);
1900}
1901
1902inline _LIBCPP_INLINE_VISIBILITY void
1903resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept {
1904 return __resize_file(__p, __ns, &__ec);
1905}
1906
1907inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p) {
1908 return __space(__p);
1909}
1910
1911inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p,
1912 error_code& __ec) noexcept {
1913 return __space(__p, &__ec);
1914}
1915
1916inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p) {
1917 return __status(__p);
1918}
1919
1920inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p,
1921 error_code& __ec) noexcept {
1922 return __status(__p, &__ec);
1923}
1924
1925inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p) {
1926 return __symlink_status(__p);
1927}
1928
1929inline _LIBCPP_INLINE_VISIBILITY file_status
1930symlink_status(const path& __p, error_code& __ec) noexcept {
1931 return __symlink_status(__p, &__ec);
1932}
1933
1934inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path() {
1935 return __temp_directory_path();
1936}
1937
1938inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path(error_code& __ec) {
1939 return __temp_directory_path(&__ec);
1940}
1941
1942inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p) {
1943 return __weakly_canonical(__p);
1944}
1945
1946inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p,
1947 error_code& __ec) {
1948 return __weakly_canonical(__p, &__ec);
1949}
1950
1951class directory_iterator;
1952class recursive_directory_iterator;
1953class __dir_stream;
1954
1955class directory_entry {
1956 typedef _VSTD_FS::path _Path;
1957
1958public:
1959 // constructors and destructors
1960 directory_entry() noexcept = default;
1961 directory_entry(directory_entry const&) = default;
1962 directory_entry(directory_entry&&) noexcept = default;
1963
1964 _LIBCPP_INLINE_VISIBILITY
1965 explicit directory_entry(_Path const& __p) : __p_(__p) {
1966 error_code __ec;
1967 __refresh(&__ec);
1968 }
1969
1970 _LIBCPP_INLINE_VISIBILITY
1971 directory_entry(_Path const& __p, error_code& __ec) : __p_(__p) {
1972 __refresh(&__ec);
1973 }
1974
1975 ~directory_entry() {}
1976
1977 directory_entry& operator=(directory_entry const&) = default;
1978 directory_entry& operator=(directory_entry&&) noexcept = default;
1979
1980 _LIBCPP_INLINE_VISIBILITY
1981 void assign(_Path const& __p) {
1982 __p_ = __p;
1983 error_code __ec;
1984 __refresh(&__ec);
1985 }
1986
1987 _LIBCPP_INLINE_VISIBILITY
1988 void assign(_Path const& __p, error_code& __ec) {
1989 __p_ = __p;
1990 __refresh(&__ec);
1991 }
1992
1993 _LIBCPP_INLINE_VISIBILITY
1994 void replace_filename(_Path const& __p) {
1995 __p_.replace_filename(__p);
1996 error_code __ec;
1997 __refresh(&__ec);
1998 }
1999
2000 _LIBCPP_INLINE_VISIBILITY
2001 void replace_filename(_Path const& __p, error_code& __ec) {
2002 __p_ = __p_.parent_path() / __p;
2003 __refresh(&__ec);
2004 }
2005
2006 _LIBCPP_INLINE_VISIBILITY
2007 void refresh() { __refresh(); }
2008
2009 _LIBCPP_INLINE_VISIBILITY
2010 void refresh(error_code& __ec) noexcept { __refresh(&__ec); }
2011
2012 _LIBCPP_INLINE_VISIBILITY
2013 _Path const& path() const noexcept { return __p_; }
2014
2015 _LIBCPP_INLINE_VISIBILITY
2016 operator const _Path&() const noexcept { return __p_; }
2017
2018 _LIBCPP_INLINE_VISIBILITY
2019 bool exists() const { return _VSTD_FS::exists(file_status{__get_ft()}); }
2020
2021 _LIBCPP_INLINE_VISIBILITY
2022 bool exists(error_code& __ec) const noexcept {
2023 return _VSTD_FS::exists(file_status{__get_ft(&__ec)});
2024 }
2025
2026 _LIBCPP_INLINE_VISIBILITY
2027 bool is_block_file() const { return __get_ft() == file_type::block; }
2028
2029 _LIBCPP_INLINE_VISIBILITY
2030 bool is_block_file(error_code& __ec) const noexcept {
2031 return __get_ft(&__ec) == file_type::block;
2032 }
2033
2034 _LIBCPP_INLINE_VISIBILITY
2035 bool is_character_file() const { return __get_ft() == file_type::character; }
2036
2037 _LIBCPP_INLINE_VISIBILITY
2038 bool is_character_file(error_code& __ec) const noexcept {
2039 return __get_ft(&__ec) == file_type::character;
2040 }
2041
2042 _LIBCPP_INLINE_VISIBILITY
2043 bool is_directory() const { return __get_ft() == file_type::directory; }
2044
2045 _LIBCPP_INLINE_VISIBILITY
2046 bool is_directory(error_code& __ec) const noexcept {
2047 return __get_ft(&__ec) == file_type::directory;
2048 }
2049
2050 _LIBCPP_INLINE_VISIBILITY
2051 bool is_fifo() const { return __get_ft() == file_type::fifo; }
2052
2053 _LIBCPP_INLINE_VISIBILITY
2054 bool is_fifo(error_code& __ec) const noexcept {
2055 return __get_ft(&__ec) == file_type::fifo;
2056 }
2057
2058 _LIBCPP_INLINE_VISIBILITY
2059 bool is_other() const { return _VSTD_FS::is_other(file_status{__get_ft()}); }
2060
2061 _LIBCPP_INLINE_VISIBILITY
2062 bool is_other(error_code& __ec) const noexcept {
2063 return _VSTD_FS::is_other(file_status{__get_ft(&__ec)});
2064 }
2065
2066 _LIBCPP_INLINE_VISIBILITY
2067 bool is_regular_file() const { return __get_ft() == file_type::regular; }
2068
2069 _LIBCPP_INLINE_VISIBILITY
2070 bool is_regular_file(error_code& __ec) const noexcept {
2071 return __get_ft(&__ec) == file_type::regular;
2072 }
2073
2074 _LIBCPP_INLINE_VISIBILITY
2075 bool is_socket() const { return __get_ft() == file_type::socket; }
2076
2077 _LIBCPP_INLINE_VISIBILITY
2078 bool is_socket(error_code& __ec) const noexcept {
2079 return __get_ft(&__ec) == file_type::socket;
2080 }
2081
2082 _LIBCPP_INLINE_VISIBILITY
2083 bool is_symlink() const { return __get_sym_ft() == file_type::symlink; }
2084
2085 _LIBCPP_INLINE_VISIBILITY
2086 bool is_symlink(error_code& __ec) const noexcept {
2087 return __get_sym_ft(&__ec) == file_type::symlink;
2088 }
2089 _LIBCPP_INLINE_VISIBILITY
2090 uintmax_t file_size() const { return __get_size(); }
2091
2092 _LIBCPP_INLINE_VISIBILITY
2093 uintmax_t file_size(error_code& __ec) const noexcept {
2094 return __get_size(&__ec);
2095 }
2096
2097 _LIBCPP_INLINE_VISIBILITY
2098 uintmax_t hard_link_count() const { return __get_nlink(); }
2099
2100 _LIBCPP_INLINE_VISIBILITY
2101 uintmax_t hard_link_count(error_code& __ec) const noexcept {
2102 return __get_nlink(&__ec);
2103 }
2104
2105 _LIBCPP_INLINE_VISIBILITY
2106 file_time_type last_write_time() const { return __get_write_time(); }
2107
2108 _LIBCPP_INLINE_VISIBILITY
2109 file_time_type last_write_time(error_code& __ec) const noexcept {
2110 return __get_write_time(&__ec);
2111 }
2112
2113 _LIBCPP_INLINE_VISIBILITY
2114 file_status status() const { return __get_status(); }
2115
2116 _LIBCPP_INLINE_VISIBILITY
2117 file_status status(error_code& __ec) const noexcept {
2118 return __get_status(&__ec);
2119 }
2120
2121 _LIBCPP_INLINE_VISIBILITY
2122 file_status symlink_status() const { return __get_symlink_status(); }
2123
2124 _LIBCPP_INLINE_VISIBILITY
2125 file_status symlink_status(error_code& __ec) const noexcept {
2126 return __get_symlink_status(&__ec);
2127 }
2128
2129 _LIBCPP_INLINE_VISIBILITY
2130 bool operator<(directory_entry const& __rhs) const noexcept {
2131 return __p_ < __rhs.__p_;
2132 }
2133
2134 _LIBCPP_INLINE_VISIBILITY
2135 bool operator==(directory_entry const& __rhs) const noexcept {
2136 return __p_ == __rhs.__p_;
2137 }
2138
2139 _LIBCPP_INLINE_VISIBILITY
2140 bool operator!=(directory_entry const& __rhs) const noexcept {
2141 return __p_ != __rhs.__p_;
2142 }
2143
2144 _LIBCPP_INLINE_VISIBILITY
2145 bool operator<=(directory_entry const& __rhs) const noexcept {
2146 return __p_ <= __rhs.__p_;
2147 }
2148
2149 _LIBCPP_INLINE_VISIBILITY
2150 bool operator>(directory_entry const& __rhs) const noexcept {
2151 return __p_ > __rhs.__p_;
2152 }
2153
2154 _LIBCPP_INLINE_VISIBILITY
2155 bool operator>=(directory_entry const& __rhs) const noexcept {
2156 return __p_ >= __rhs.__p_;
2157 }
2158
2159private:
2160 friend class directory_iterator;
2161 friend class recursive_directory_iterator;
2162 friend class __dir_stream;
2163
2164 enum _CacheType : unsigned char {
2165 _Empty,
2166 _IterSymlink,
2167 _IterNonSymlink,
2168 _RefreshSymlink,
2169 _RefreshSymlinkUnresolved,
2170 _RefreshNonSymlink
2171 };
2172
2173 struct __cached_data {
2174 uintmax_t __size_;
2175 uintmax_t __nlink_;
2176 file_time_type __write_time_;
2177 perms __sym_perms_;
2178 perms __non_sym_perms_;
2179 file_type __type_;
2180 _CacheType __cache_type_;
2181
2182 _LIBCPP_INLINE_VISIBILITY
2183 __cached_data() noexcept { __reset(); }
2184
2185 _LIBCPP_INLINE_VISIBILITY
2186 void __reset() {
2187 __cache_type_ = _Empty;
2188 __type_ = file_type::none;
2189 __sym_perms_ = __non_sym_perms_ = perms::unknown;
2190 __size_ = __nlink_ = uintmax_t(-1);
2191 __write_time_ = file_time_type::min();
2192 }
2193 };
2194
2195 _LIBCPP_INLINE_VISIBILITY
2196 static __cached_data __create_iter_result(file_type __ft) {
2197 __cached_data __data;
2198 __data.__type_ = __ft;
2199 __data.__cache_type_ = [&]() {
2200 switch (__ft) {
2201 case file_type::none:
2202 return _Empty;
2203 case file_type::symlink:
2204 return _IterSymlink;
2205 default:
2206 return _IterNonSymlink;
2207 }
2208 }();
2209 return __data;
2210 }
2211
2212 _LIBCPP_INLINE_VISIBILITY
2213 void __assign_iter_entry(_Path&& __p, __cached_data __dt) {
2214 __p_ = std::move(__p);
2215 __data_ = __dt;
2216 }
2217
2218 _LIBCPP_FUNC_VIS
2219 error_code __do_refresh() noexcept;
2220
2221 _LIBCPP_INLINE_VISIBILITY
2222 static bool __is_dne_error(error_code const& __ec) {
2223 if (!__ec)
2224 return true;
2225 switch (static_cast<errc>(__ec.value())) {
2226 case errc::no_such_file_or_directory:
2227 case errc::not_a_directory:
2228 return true;
2229 default:
2230 return false;
2231 }
2232 }
2233
2234 _LIBCPP_INLINE_VISIBILITY
2235 void __handle_error(const char* __msg, error_code* __dest_ec,
2236 error_code const& __ec, bool __allow_dne = false) const {
2237 if (__dest_ec) {
2238 *__dest_ec = __ec;
2239 return;
2240 }
2241 if (__ec && (!__allow_dne || !__is_dne_error(__ec)))
2242 __throw_filesystem_error(__msg, __p_, __ec);
2243 }
2244
2245 _LIBCPP_INLINE_VISIBILITY
2246 void __refresh(error_code* __ec = nullptr) {
2247 __handle_error("in directory_entry::refresh", __ec, __do_refresh(),
2248 /*allow_dne*/ true);
2249 }
2250
2251 _LIBCPP_INLINE_VISIBILITY
2252 file_type __get_sym_ft(error_code* __ec = nullptr) const {
2253 switch (__data_.__cache_type_) {
2254 case _Empty:
2255 return __symlink_status(__p_, __ec).type();
2256 case _IterSymlink:
2257 case _RefreshSymlink:
2258 case _RefreshSymlinkUnresolved:
2259 if (__ec)
2260 __ec->clear();
2261 return file_type::symlink;
2262 case _IterNonSymlink:
2263 case _RefreshNonSymlink:
2264 file_status __st(__data_.__type_);
2265 if (__ec && !_VSTD_FS::exists(__st))
2266 *__ec = make_error_code(errc::no_such_file_or_directory);
2267 else if (__ec)
2268 __ec->clear();
2269 return __data_.__type_;
2270 }
2271 _LIBCPP_UNREACHABLE();
2272 }
2273
2274 _LIBCPP_INLINE_VISIBILITY
2275 file_type __get_ft(error_code* __ec = nullptr) const {
2276 switch (__data_.__cache_type_) {
2277 case _Empty:
2278 case _IterSymlink:
2279 case _RefreshSymlinkUnresolved:
2280 return __status(__p_, __ec).type();
2281 case _IterNonSymlink:
2282 case _RefreshNonSymlink:
2283 case _RefreshSymlink: {
2284 file_status __st(__data_.__type_);
2285 if (__ec && !_VSTD_FS::exists(__st))
2286 *__ec = make_error_code(errc::no_such_file_or_directory);
2287 else if (__ec)
2288 __ec->clear();
2289 return __data_.__type_;
2290 }
2291 }
2292 _LIBCPP_UNREACHABLE();
2293 }
2294
2295 _LIBCPP_INLINE_VISIBILITY
2296 file_status __get_status(error_code* __ec = nullptr) const {
2297 switch (__data_.__cache_type_) {
2298 case _Empty:
2299 case _IterNonSymlink:
2300 case _IterSymlink:
2301 case _RefreshSymlinkUnresolved:
2302 return __status(__p_, __ec);
2303 case _RefreshNonSymlink:
2304 case _RefreshSymlink:
2305 return file_status(__get_ft(__ec), __data_.__non_sym_perms_);
2306 }
2307 _LIBCPP_UNREACHABLE();
2308 }
2309
2310 _LIBCPP_INLINE_VISIBILITY
2311 file_status __get_symlink_status(error_code* __ec = nullptr) const {
2312 switch (__data_.__cache_type_) {
2313 case _Empty:
2314 case _IterNonSymlink:
2315 case _IterSymlink:
2316 return __symlink_status(__p_, __ec);
2317 case _RefreshNonSymlink:
2318 return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_);
2319 case _RefreshSymlink:
2320 case _RefreshSymlinkUnresolved:
2321 return file_status(__get_sym_ft(__ec), __data_.__sym_perms_);
2322 }
2323 _LIBCPP_UNREACHABLE();
2324 }
2325
2326 _LIBCPP_INLINE_VISIBILITY
2327 uintmax_t __get_size(error_code* __ec = nullptr) const {
2328 switch (__data_.__cache_type_) {
2329 case _Empty:
2330 case _IterNonSymlink:
2331 case _IterSymlink:
2332 case _RefreshSymlinkUnresolved:
2333 return _VSTD_FS::__file_size(__p_, __ec);
2334 case _RefreshSymlink:
2335 case _RefreshNonSymlink: {
2336 error_code __m_ec;
2337 file_status __st(__get_ft(&__m_ec));
2338 __handle_error("in directory_entry::file_size", __ec, __m_ec);
2339 if (_VSTD_FS::exists(__st) && !_VSTD_FS::is_regular_file(__st)) {
2340 errc __err_kind = _VSTD_FS::is_directory(__st) ? errc::is_a_directory
2341 : errc::not_supported;
2342 __handle_error("in directory_entry::file_size", __ec,
2343 make_error_code(__err_kind));
2344 }
2345 return __data_.__size_;
2346 }
2347 }
2348 _LIBCPP_UNREACHABLE();
2349 }
2350
2351 _LIBCPP_INLINE_VISIBILITY
2352 uintmax_t __get_nlink(error_code* __ec = nullptr) const {
2353 switch (__data_.__cache_type_) {
2354 case _Empty:
2355 case _IterNonSymlink:
2356 case _IterSymlink:
2357 case _RefreshSymlinkUnresolved:
2358 return _VSTD_FS::__hard_link_count(__p_, __ec);
2359 case _RefreshSymlink:
2360 case _RefreshNonSymlink: {
2361 error_code __m_ec;
2362 (void)__get_ft(&__m_ec);
2363 __handle_error("in directory_entry::hard_link_count", __ec, __m_ec);
2364 return __data_.__nlink_;
2365 }
2366 }
2367 _LIBCPP_UNREACHABLE();
2368 }
2369
2370 _LIBCPP_INLINE_VISIBILITY
2371 file_time_type __get_write_time(error_code* __ec = nullptr) const {
2372 switch (__data_.__cache_type_) {
2373 case _Empty:
2374 case _IterNonSymlink:
2375 case _IterSymlink:
2376 case _RefreshSymlinkUnresolved:
2377 return _VSTD_FS::__last_write_time(__p_, __ec);
2378 case _RefreshSymlink:
2379 case _RefreshNonSymlink: {
2380 error_code __m_ec;
2381 file_status __st(__get_ft(&__m_ec));
2382 __handle_error("in directory_entry::last_write_time", __ec, __m_ec);
2383 if (_VSTD_FS::exists(__st) &&
2384 __data_.__write_time_ == file_time_type::min())
2385 __handle_error("in directory_entry::last_write_time", __ec,
2386 make_error_code(errc::value_too_large));
2387 return __data_.__write_time_;
2388 }
2389 }
2390 _LIBCPP_UNREACHABLE();
2391 }
2392
2393private:
2394 _Path __p_;
2395 __cached_data __data_;
2396};
2397
2398class __dir_element_proxy {
2399public:
2400 inline _LIBCPP_INLINE_VISIBILITY directory_entry operator*() {
2401 return _VSTD::move(__elem_);
2402 }
2403
2404private:
2405 friend class directory_iterator;
2406 friend class recursive_directory_iterator;
2407 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
2408 __dir_element_proxy(__dir_element_proxy&& __o)
2409 : __elem_(_VSTD::move(__o.__elem_)) {}
2410 directory_entry __elem_;
2411};
2412
2413class directory_iterator {
2414public:
2415 typedef directory_entry value_type;
2416 typedef ptrdiff_t difference_type;
2417 typedef value_type const* pointer;
2418 typedef value_type const& reference;
2419 typedef input_iterator_tag iterator_category;
2420
2421public:
2422 //ctor & dtor
2423 directory_iterator() noexcept {}
2424
2425 explicit directory_iterator(const path& __p)
2426 : directory_iterator(__p, nullptr) {}
2427
2428 directory_iterator(const path& __p, directory_options __opts)
2429 : directory_iterator(__p, nullptr, __opts) {}
2430
2431 directory_iterator(const path& __p, error_code& __ec)
2432 : directory_iterator(__p, &__ec) {}
2433
2434 directory_iterator(const path& __p, directory_options __opts,
2435 error_code& __ec)
2436 : directory_iterator(__p, &__ec, __opts) {}
2437
2438 directory_iterator(const directory_iterator&) = default;
2439 directory_iterator(directory_iterator&&) = default;
2440 directory_iterator& operator=(const directory_iterator&) = default;
2441
2442 directory_iterator& operator=(directory_iterator&& __o) noexcept {
2443 // non-default implementation provided to support self-move assign.
2444 if (this != &__o) {
2445 __imp_ = _VSTD::move(__o.__imp_);
2446 }
2447 return *this;
2448 }
2449
2450 ~directory_iterator() = default;
2451
2452 const directory_entry& operator*() const {
2453 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
2454 return __dereference();
2455 }
2456
2457 const directory_entry* operator->() const { return &**this; }
2458
2459 directory_iterator& operator++() { return __increment(); }
2460
2461 __dir_element_proxy operator++(int) {
2462 __dir_element_proxy __p(**this);
2463 __increment();
2464 return __p;
2465 }
2466
2467 directory_iterator& increment(error_code& __ec) { return __increment(&__ec); }
2468
2469private:
2470 inline _LIBCPP_INLINE_VISIBILITY friend bool
2471 operator==(const directory_iterator& __lhs,
2472 const directory_iterator& __rhs) noexcept;
2473
2474 // construct the dir_stream
2475 _LIBCPP_FUNC_VIS
2476 directory_iterator(const path&, error_code*,
2477 directory_options = directory_options::none);
2478
2479 _LIBCPP_FUNC_VIS
2480 directory_iterator& __increment(error_code* __ec = nullptr);
2481
2482 _LIBCPP_FUNC_VIS
2483 const directory_entry& __dereference() const;
2484
2485private:
2486 shared_ptr<__dir_stream> __imp_;
2487};
2488
2489inline _LIBCPP_INLINE_VISIBILITY bool
2490operator==(const directory_iterator& __lhs,
2491 const directory_iterator& __rhs) noexcept {
2492 return __lhs.__imp_ == __rhs.__imp_;
2493}
2494
2495inline _LIBCPP_INLINE_VISIBILITY bool
2496operator!=(const directory_iterator& __lhs,
2497 const directory_iterator& __rhs) noexcept {
2498 return !(__lhs == __rhs);
2499}
2500
2501// enable directory_iterator range-based for statements
2502inline _LIBCPP_INLINE_VISIBILITY directory_iterator
2503begin(directory_iterator __iter) noexcept {
2504 return __iter;
2505}
2506
2507inline _LIBCPP_INLINE_VISIBILITY directory_iterator
2508end(const directory_iterator&) noexcept {
2509 return directory_iterator();
2510}
2511
2512class recursive_directory_iterator {
2513public:
2514 using value_type = directory_entry;
2515 using difference_type = std::ptrdiff_t;
2516 using pointer = directory_entry const*;
2517 using reference = directory_entry const&;
2518 using iterator_category = std::input_iterator_tag;
2519
2520public:
2521 // constructors and destructor
2522 _LIBCPP_INLINE_VISIBILITY
2523 recursive_directory_iterator() noexcept : __rec_(false) {}
2524
2525 _LIBCPP_INLINE_VISIBILITY
2526 explicit recursive_directory_iterator(
2527 const path& __p, directory_options __xoptions = directory_options::none)
2528 : recursive_directory_iterator(__p, __xoptions, nullptr) {}
2529
2530 _LIBCPP_INLINE_VISIBILITY
2531 recursive_directory_iterator(const path& __p, directory_options __xoptions,
2532 error_code& __ec)
2533 : recursive_directory_iterator(__p, __xoptions, &__ec) {}
2534
2535 _LIBCPP_INLINE_VISIBILITY
2536 recursive_directory_iterator(const path& __p, error_code& __ec)
2537 : recursive_directory_iterator(__p, directory_options::none, &__ec) {}
2538
2539 recursive_directory_iterator(const recursive_directory_iterator&) = default;
2540 recursive_directory_iterator(recursive_directory_iterator&&) = default;
2541
2542 recursive_directory_iterator&
2543 operator=(const recursive_directory_iterator&) = default;
2544
2545 _LIBCPP_INLINE_VISIBILITY
2546 recursive_directory_iterator&
2547 operator=(recursive_directory_iterator&& __o) noexcept {
2548 // non-default implementation provided to support self-move assign.
2549 if (this != &__o) {
2550 __imp_ = _VSTD::move(__o.__imp_);
2551 __rec_ = __o.__rec_;
2552 }
2553 return *this;
2554 }
2555
2556 ~recursive_directory_iterator() = default;
2557
2558 _LIBCPP_INLINE_VISIBILITY
2559 const directory_entry& operator*() const { return __dereference(); }
2560
2561 _LIBCPP_INLINE_VISIBILITY
2562 const directory_entry* operator->() const { return &__dereference(); }
2563
2564 recursive_directory_iterator& operator++() { return __increment(); }
2565
2566 _LIBCPP_INLINE_VISIBILITY
2567 __dir_element_proxy operator++(int) {
2568 __dir_element_proxy __p(**this);
2569 __increment();
2570 return __p;
2571 }
2572
2573 _LIBCPP_INLINE_VISIBILITY
2574 recursive_directory_iterator& increment(error_code& __ec) {
2575 return __increment(&__ec);
2576 }
2577
2578 _LIBCPP_FUNC_VIS directory_options options() const;
2579 _LIBCPP_FUNC_VIS int depth() const;
2580
2581 _LIBCPP_INLINE_VISIBILITY
2582 void pop() { __pop(); }
2583
2584 _LIBCPP_INLINE_VISIBILITY
2585 void pop(error_code& __ec) { __pop(&__ec); }
2586
2587 _LIBCPP_INLINE_VISIBILITY
2588 bool recursion_pending() const { return __rec_; }
2589
2590 _LIBCPP_INLINE_VISIBILITY
2591 void disable_recursion_pending() { __rec_ = false; }
2592
2593private:
2594 recursive_directory_iterator(const path& __p, directory_options __opt,
2595 error_code* __ec);
2596
2597 _LIBCPP_FUNC_VIS
2598 const directory_entry& __dereference() const;
2599
2600 _LIBCPP_FUNC_VIS
2601 bool __try_recursion(error_code* __ec);
2602
2603 _LIBCPP_FUNC_VIS
2604 void __advance(error_code* __ec = nullptr);
2605
2606 _LIBCPP_FUNC_VIS
2607 recursive_directory_iterator& __increment(error_code* __ec = nullptr);
2608
2609 _LIBCPP_FUNC_VIS
2610 void __pop(error_code* __ec = nullptr);
2611
2612 inline _LIBCPP_INLINE_VISIBILITY friend bool
2613 operator==(const recursive_directory_iterator&,
2614 const recursive_directory_iterator&) noexcept;
2615
2616 struct __shared_imp;
2617 shared_ptr<__shared_imp> __imp_;
2618 bool __rec_;
2619}; // class recursive_directory_iterator
2620
2621inline _LIBCPP_INLINE_VISIBILITY bool
2622operator==(const recursive_directory_iterator& __lhs,
2623 const recursive_directory_iterator& __rhs) noexcept {
2624 return __lhs.__imp_ == __rhs.__imp_;
2625}
2626
2627_LIBCPP_INLINE_VISIBILITY
2628inline bool operator!=(const recursive_directory_iterator& __lhs,
2629 const recursive_directory_iterator& __rhs) noexcept {
2630 return !(__lhs == __rhs);
2631}
2632// enable recursive_directory_iterator range-based for statements
2633inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
2634begin(recursive_directory_iterator __iter) noexcept {
2635 return __iter;
2636}
2637
2638inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
2639end(const recursive_directory_iterator&) noexcept {
2640 return recursive_directory_iterator();
2641}
2642
2643_LIBCPP_END_NAMESPACE_FILESYSTEM
2644
2645#endif // !_LIBCPP_CXX03_LANG
2646
2647_LIBCPP_POP_MACROS
2648
2649#endif // _LIBCPP_FILESYSTEM