2 //===--------------------------- filesystem -------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP_FILESYSTEM
10 #define _LIBCPP_FILESYSTEM
14 namespace std { namespace filesystem {
18 void swap(path& lhs, path& rhs) noexcept;
19 size_t hash_value(const path& p) noexcept;
21 bool operator==(const path& lhs, const path& rhs) noexcept;
22 bool operator!=(const path& lhs, const path& rhs) noexcept;
23 bool operator< (const path& lhs, const path& rhs) noexcept;
24 bool operator<=(const path& lhs, const path& rhs) noexcept;
25 bool operator> (const path& lhs, const path& rhs) noexcept;
26 bool operator>=(const path& lhs, const path& rhs) noexcept;
28 path operator/ (const path& lhs, const path& rhs);
30 // fs.path.io operators are friends of path.
31 template <class charT, class traits>
32 friend basic_ostream<charT, traits>&
33 operator<<(basic_ostream<charT, traits>& os, const path& p);
35 template <class charT, class traits>
36 friend basic_istream<charT, traits>&
37 operator>>(basic_istream<charT, traits>& is, path& p);
39 template <class Source>
40 path u8path(const Source& source);
41 template <class InputIterator>
42 path u8path(InputIterator first, InputIterator last);
44 class filesystem_error;
45 class directory_entry;
47 class directory_iterator;
49 // enable directory_iterator range-based for statements
50 directory_iterator begin(directory_iterator iter) noexcept;
51 directory_iterator end(const directory_iterator&) noexcept;
53 class recursive_directory_iterator;
55 // enable recursive_directory_iterator range-based for statements
56 recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
57 recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
70 enum class perm_options;
71 enum class copy_options;
72 enum class directory_options;
74 typedef chrono::time_point<trivial-clock> file_time_type;
76 // operational functions
78 path absolute(const path& p);
79 path absolute(const path& p, error_code &ec);
81 path canonical(const path& p);
82 path canonical(const path& p, error_code& ec);
84 void copy(const path& from, const path& to);
85 void copy(const path& from, const path& to, error_code& ec);
86 void copy(const path& from, const path& to, copy_options options);
87 void copy(const path& from, const path& to, copy_options options,
90 bool copy_file(const path& from, const path& to);
91 bool copy_file(const path& from, const path& to, error_code& ec);
92 bool copy_file(const path& from, const path& to, copy_options option);
93 bool copy_file(const path& from, const path& to, copy_options option,
96 void copy_symlink(const path& existing_symlink, const path& new_symlink);
97 void copy_symlink(const path& existing_symlink, const path& new_symlink,
98 error_code& ec) noexcept;
100 bool create_directories(const path& p);
101 bool create_directories(const path& p, error_code& ec);
103 bool create_directory(const path& p);
104 bool create_directory(const path& p, error_code& ec) noexcept;
106 bool create_directory(const path& p, const path& attributes);
107 bool create_directory(const path& p, const path& attributes,
108 error_code& ec) noexcept;
110 void create_directory_symlink(const path& to, const path& new_symlink);
111 void create_directory_symlink(const path& to, const path& new_symlink,
112 error_code& ec) noexcept;
114 void create_hard_link(const path& to, const path& new_hard_link);
115 void create_hard_link(const path& to, const path& new_hard_link,
116 error_code& ec) noexcept;
118 void create_symlink(const path& to, const path& new_symlink);
119 void create_symlink(const path& to, const path& new_symlink,
120 error_code& ec) noexcept;
123 path current_path(error_code& ec);
124 void current_path(const path& p);
125 void current_path(const path& p, error_code& ec) noexcept;
127 bool exists(file_status s) noexcept;
128 bool exists(const path& p);
129 bool exists(const path& p, error_code& ec) noexcept;
131 bool equivalent(const path& p1, const path& p2);
132 bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
134 uintmax_t file_size(const path& p);
135 uintmax_t file_size(const path& p, error_code& ec) noexcept;
137 uintmax_t hard_link_count(const path& p);
138 uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
140 bool is_block_file(file_status s) noexcept;
141 bool is_block_file(const path& p);
142 bool is_block_file(const path& p, error_code& ec) noexcept;
144 bool is_character_file(file_status s) noexcept;
145 bool is_character_file(const path& p);
146 bool is_character_file(const path& p, error_code& ec) noexcept;
148 bool is_directory(file_status s) noexcept;
149 bool is_directory(const path& p);
150 bool is_directory(const path& p, error_code& ec) noexcept;
152 bool is_empty(const path& p);
153 bool is_empty(const path& p, error_code& ec) noexcept;
155 bool is_fifo(file_status s) noexcept;
156 bool is_fifo(const path& p);
157 bool is_fifo(const path& p, error_code& ec) noexcept;
159 bool is_other(file_status s) noexcept;
160 bool is_other(const path& p);
161 bool is_other(const path& p, error_code& ec) noexcept;
163 bool is_regular_file(file_status s) noexcept;
164 bool is_regular_file(const path& p);
165 bool is_regular_file(const path& p, error_code& ec) noexcept;
167 bool is_socket(file_status s) noexcept;
168 bool is_socket(const path& p);
169 bool is_socket(const path& p, error_code& ec) noexcept;
171 bool is_symlink(file_status s) noexcept;
172 bool is_symlink(const path& p);
173 bool is_symlink(const path& p, error_code& ec) noexcept;
175 file_time_type last_write_time(const path& p);
176 file_time_type last_write_time(const path& p, error_code& ec) noexcept;
177 void last_write_time(const path& p, file_time_type new_time);
178 void last_write_time(const path& p, file_time_type new_time,
179 error_code& ec) noexcept;
181 void permissions(const path& p, perms prms,
182 perm_options opts=perm_options::replace);
183 void permissions(const path& p, perms prms, error_code& ec) noexcept;
184 void permissions(const path& p, perms prms, perm_options opts,
187 path proximate(const path& p, error_code& ec);
188 path proximate(const path& p, const path& base = current_path());
189 path proximate(const path& p, const path& base, error_code &ec);
191 path read_symlink(const path& p);
192 path read_symlink(const path& p, error_code& ec);
194 path relative(const path& p, error_code& ec);
195 path relative(const path& p, const path& base=current_path());
196 path relative(const path& p, const path& base, error_code& ec);
198 bool remove(const path& p);
199 bool remove(const path& p, error_code& ec) noexcept;
201 uintmax_t remove_all(const path& p);
202 uintmax_t remove_all(const path& p, error_code& ec);
204 void rename(const path& from, const path& to);
205 void rename(const path& from, const path& to, error_code& ec) noexcept;
207 void resize_file(const path& p, uintmax_t size);
208 void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept;
210 space_info space(const path& p);
211 space_info space(const path& p, error_code& ec) noexcept;
213 file_status status(const path& p);
214 file_status status(const path& p, error_code& ec) noexcept;
216 bool status_known(file_status s) noexcept;
218 file_status symlink_status(const path& p);
219 file_status symlink_status(const path& p, error_code& ec) noexcept;
221 path temp_directory_path();
222 path temp_directory_path(error_code& ec);
224 path weakly_canonical(path const& p);
225 path weakly_canonical(path const& p, error_code& ec);
228 } } // namespaces std::filesystem
242 #include <system_error>
244 #include <iomanip> // for quoted
245 #include <string_view>
250 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
251 #pragma GCC system_header
255 #include <__undef_macros>
257 #ifndef _LIBCPP_CXX03_LANG
259 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
261 _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
263 typedef chrono::time_point<_FilesystemClock> file_time_type;
265 struct _LIBCPP_TYPE_VIS space_info {
271 enum class _LIBCPP_ENUM_VIS file_type : signed char {
284 enum class _LIBCPP_ENUM_VIS perms : unsigned {
311 _LIBCPP_INLINE_VISIBILITY
312 inline constexpr perms operator&(perms _LHS, perms _RHS) {
313 return static_cast<perms>(static_cast<unsigned>(_LHS) &
314 static_cast<unsigned>(_RHS));
317 _LIBCPP_INLINE_VISIBILITY
318 inline constexpr perms operator|(perms _LHS, perms _RHS) {
319 return static_cast<perms>(static_cast<unsigned>(_LHS) |
320 static_cast<unsigned>(_RHS));
323 _LIBCPP_INLINE_VISIBILITY
324 inline constexpr perms operator^(perms _LHS, perms _RHS) {
325 return static_cast<perms>(static_cast<unsigned>(_LHS) ^
326 static_cast<unsigned>(_RHS));
329 _LIBCPP_INLINE_VISIBILITY
330 inline constexpr perms operator~(perms _LHS) {
331 return static_cast<perms>(~static_cast<unsigned>(_LHS));
334 _LIBCPP_INLINE_VISIBILITY
335 inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; }
337 _LIBCPP_INLINE_VISIBILITY
338 inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; }
340 _LIBCPP_INLINE_VISIBILITY
341 inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; }
343 enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
350 _LIBCPP_INLINE_VISIBILITY
351 inline constexpr perm_options operator&(perm_options _LHS, perm_options _RHS) {
352 return static_cast<perm_options>(static_cast<unsigned>(_LHS) &
353 static_cast<unsigned>(_RHS));
356 _LIBCPP_INLINE_VISIBILITY
357 inline constexpr perm_options operator|(perm_options _LHS, perm_options _RHS) {
358 return static_cast<perm_options>(static_cast<unsigned>(_LHS) |
359 static_cast<unsigned>(_RHS));
362 _LIBCPP_INLINE_VISIBILITY
363 inline constexpr perm_options operator^(perm_options _LHS, perm_options _RHS) {
364 return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^
365 static_cast<unsigned>(_RHS));
368 _LIBCPP_INLINE_VISIBILITY
369 inline constexpr perm_options operator~(perm_options _LHS) {
370 return static_cast<perm_options>(~static_cast<unsigned>(_LHS));
373 _LIBCPP_INLINE_VISIBILITY
374 inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS) {
375 return _LHS = _LHS & _RHS;
378 _LIBCPP_INLINE_VISIBILITY
379 inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS) {
380 return _LHS = _LHS | _RHS;
383 _LIBCPP_INLINE_VISIBILITY
384 inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS) {
385 return _LHS = _LHS ^ _RHS;
388 enum class _LIBCPP_ENUM_VIS copy_options : unsigned short {
391 overwrite_existing = 2,
396 directories_only = 64,
397 create_symlinks = 128,
398 create_hard_links = 256,
399 __in_recursive_copy = 512,
402 _LIBCPP_INLINE_VISIBILITY
403 inline constexpr copy_options operator&(copy_options _LHS, copy_options _RHS) {
404 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) &
405 static_cast<unsigned short>(_RHS));
408 _LIBCPP_INLINE_VISIBILITY
409 inline constexpr copy_options operator|(copy_options _LHS, copy_options _RHS) {
410 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) |
411 static_cast<unsigned short>(_RHS));
414 _LIBCPP_INLINE_VISIBILITY
415 inline constexpr copy_options operator^(copy_options _LHS, copy_options _RHS) {
416 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^
417 static_cast<unsigned short>(_RHS));
420 _LIBCPP_INLINE_VISIBILITY
421 inline constexpr copy_options operator~(copy_options _LHS) {
422 return static_cast<copy_options>(~static_cast<unsigned short>(_LHS));
425 _LIBCPP_INLINE_VISIBILITY
426 inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) {
427 return _LHS = _LHS & _RHS;
430 _LIBCPP_INLINE_VISIBILITY
431 inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) {
432 return _LHS = _LHS | _RHS;
435 _LIBCPP_INLINE_VISIBILITY
436 inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) {
437 return _LHS = _LHS ^ _RHS;
440 enum class _LIBCPP_ENUM_VIS directory_options : unsigned char {
442 follow_directory_symlink = 1,
443 skip_permission_denied = 2
446 _LIBCPP_INLINE_VISIBILITY
447 inline constexpr directory_options operator&(directory_options _LHS,
448 directory_options _RHS) {
449 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) &
450 static_cast<unsigned char>(_RHS));
453 _LIBCPP_INLINE_VISIBILITY
454 inline constexpr directory_options operator|(directory_options _LHS,
455 directory_options _RHS) {
456 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) |
457 static_cast<unsigned char>(_RHS));
460 _LIBCPP_INLINE_VISIBILITY
461 inline constexpr directory_options operator^(directory_options _LHS,
462 directory_options _RHS) {
463 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^
464 static_cast<unsigned char>(_RHS));
467 _LIBCPP_INLINE_VISIBILITY
468 inline constexpr directory_options operator~(directory_options _LHS) {
469 return static_cast<directory_options>(~static_cast<unsigned char>(_LHS));
472 _LIBCPP_INLINE_VISIBILITY
473 inline directory_options& operator&=(directory_options& _LHS,
474 directory_options _RHS) {
475 return _LHS = _LHS & _RHS;
478 _LIBCPP_INLINE_VISIBILITY
479 inline directory_options& operator|=(directory_options& _LHS,
480 directory_options _RHS) {
481 return _LHS = _LHS | _RHS;
484 _LIBCPP_INLINE_VISIBILITY
485 inline directory_options& operator^=(directory_options& _LHS,
486 directory_options _RHS) {
487 return _LHS = _LHS ^ _RHS;
490 class _LIBCPP_TYPE_VIS file_status {
493 _LIBCPP_INLINE_VISIBILITY
494 file_status() noexcept : file_status(file_type::none) {}
495 _LIBCPP_INLINE_VISIBILITY
496 explicit file_status(file_type __ft, perms __prms = perms::unknown) noexcept
500 file_status(const file_status&) noexcept = default;
501 file_status(file_status&&) noexcept = default;
503 _LIBCPP_INLINE_VISIBILITY
506 file_status& operator=(const file_status&) noexcept = default;
507 file_status& operator=(file_status&&) noexcept = default;
510 _LIBCPP_INLINE_VISIBILITY
511 file_type type() const noexcept { return __ft_; }
513 _LIBCPP_INLINE_VISIBILITY
514 perms permissions() const noexcept { return __prms_; }
517 _LIBCPP_INLINE_VISIBILITY
518 void type(file_type __ft) noexcept { __ft_ = __ft; }
520 _LIBCPP_INLINE_VISIBILITY
521 void permissions(perms __p) noexcept { __prms_ = __p; }
528 class _LIBCPP_TYPE_VIS directory_entry;
531 struct __can_convert_char {
532 static const bool value = false;
535 struct __can_convert_char<const _Tp> : public __can_convert_char<_Tp> {};
537 struct __can_convert_char<char> {
538 static const bool value = true;
539 using __char_type = char;
542 struct __can_convert_char<wchar_t> {
543 static const bool value = true;
544 using __char_type = wchar_t;
547 struct __can_convert_char<char16_t> {
548 static const bool value = true;
549 using __char_type = char16_t;
552 struct __can_convert_char<char32_t> {
553 static const bool value = true;
554 using __char_type = char32_t;
557 template <class _ECharT>
558 typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
559 __is_separator(_ECharT __e) {
560 return __e == _ECharT('/');
563 struct _NullSentinal {};
568 template <class _Tp, class = void>
569 struct __is_pathable_string : public false_type {};
571 template <class _ECharT, class _Traits, class _Alloc>
572 struct __is_pathable_string<
573 basic_string<_ECharT, _Traits, _Alloc>,
574 _Void<typename __can_convert_char<_ECharT>::__char_type> >
575 : public __can_convert_char<_ECharT> {
576 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
577 using _Base = __can_convert_char<_ECharT>;
578 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
579 static _ECharT const* __range_end(_Str const& __s) {
580 return __s.data() + __s.length();
582 static _ECharT __first_or_null(_Str const& __s) {
583 return __s.empty() ? _ECharT{} : __s[0];
587 template <class _ECharT, class _Traits>
588 struct __is_pathable_string<
589 basic_string_view<_ECharT, _Traits>,
590 _Void<typename __can_convert_char<_ECharT>::__char_type> >
591 : public __can_convert_char<_ECharT> {
592 using _Str = basic_string_view<_ECharT, _Traits>;
593 using _Base = __can_convert_char<_ECharT>;
594 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
595 static _ECharT const* __range_end(_Str const& __s) {
596 return __s.data() + __s.length();
598 static _ECharT __first_or_null(_Str const& __s) {
599 return __s.empty() ? _ECharT{} : __s[0];
603 template <class _Source, class _DS = typename decay<_Source>::type,
604 class _UnqualPtrType =
605 typename remove_const<typename remove_pointer<_DS>::type>::type,
606 bool _IsCharPtr = is_pointer<_DS>::value&&
607 __can_convert_char<_UnqualPtrType>::value>
608 struct __is_pathable_char_array : false_type {};
610 template <class _Source, class _ECharT, class _UPtr>
611 struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
612 : __can_convert_char<typename remove_const<_ECharT>::type> {
613 using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
615 static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
616 static _ECharT const* __range_end(const _ECharT* __b) {
617 using _Iter = const _ECharT*;
618 const _ECharT __sentinal = _ECharT{};
620 for (; *__e != __sentinal; ++__e)
625 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
628 template <class _Iter, bool _IsIt = __is_cpp17_input_iterator<_Iter>::value,
630 struct __is_pathable_iter : false_type {};
632 template <class _Iter>
633 struct __is_pathable_iter<
635 _Void<typename __can_convert_char<
636 typename iterator_traits<_Iter>::value_type>::__char_type> >
637 : __can_convert_char<typename iterator_traits<_Iter>::value_type> {
638 using _ECharT = typename iterator_traits<_Iter>::value_type;
639 using _Base = __can_convert_char<_ECharT>;
641 static _Iter __range_begin(_Iter __b) { return __b; }
642 static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; }
644 static _ECharT __first_or_null(_Iter __b) { return *__b; }
647 template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
648 bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
649 bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value>
650 struct __is_pathable : false_type {
651 static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
655 struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
658 struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {
662 struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
664 template <class _ECharT>
666 static_assert(__can_convert_char<_ECharT>::value,
667 "Char type not convertible");
669 typedef __narrow_to_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Narrower;
671 static void __append_range(string& __dest, _ECharT const* __b,
672 _ECharT const* __e) {
673 _Narrower()(back_inserter(__dest), __b, __e);
676 template <class _Iter>
677 static void __append_range(string& __dest, _Iter __b, _Iter __e) {
678 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
681 basic_string<_ECharT> __tmp(__b, __e);
682 _Narrower()(back_inserter(__dest), __tmp.data(),
683 __tmp.data() + __tmp.length());
686 template <class _Iter>
687 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
688 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
689 const _ECharT __sentinal = _ECharT{};
690 if (*__b == __sentinal)
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());
699 template <class _Source>
700 static void __append_source(string& __dest, _Source const& __s) {
701 using _Traits = __is_pathable<_Source>;
702 __append_range(__dest, _Traits::__range_begin(__s),
703 _Traits::__range_end(__s));
708 struct _PathCVT<char> {
710 template <class _Iter>
711 static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
712 __append_range(string& __dest, _Iter __b, _Iter __e) {
713 for (; __b != __e; ++__b)
714 __dest.push_back(*__b);
717 template <class _Iter>
718 static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
719 __append_range(string& __dest, _Iter __b, _Iter __e) {
720 __dest.__append_forward_unsafe(__b, __e);
723 template <class _Iter>
724 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
725 const char __sentinal = char{};
726 for (; *__b != __sentinal; ++__b)
727 __dest.push_back(*__b);
730 template <class _Source>
731 static void __append_source(string& __dest, _Source const& __s) {
732 using _Traits = __is_pathable<_Source>;
733 __append_range(__dest, _Traits::__range_begin(__s),
734 _Traits::__range_end(__s));
738 class _LIBCPP_TYPE_VIS path {
739 template <class _SourceOrIter, class _Tp = path&>
740 using _EnableIfPathable =
741 typename enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
744 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
747 using _SourceCVT = _PathCVT<_SourceChar<_Tp> >;
750 typedef char value_type;
751 typedef basic_string<value_type> string_type;
752 typedef _VSTD::string_view __string_view;
753 static constexpr value_type preferred_separator = '/';
755 enum class _LIBCPP_ENUM_VIS format : unsigned char {
761 // constructors and destructor
762 _LIBCPP_INLINE_VISIBILITY path() noexcept {}
763 _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
764 _LIBCPP_INLINE_VISIBILITY path(path&& __p) noexcept
765 : __pn_(_VSTD::move(__p.__pn_)) {}
767 _LIBCPP_INLINE_VISIBILITY
768 path(string_type&& __s, format = format::auto_format) noexcept
769 : __pn_(_VSTD::move(__s)) {}
771 template <class _Source, class = _EnableIfPathable<_Source, void> >
772 path(const _Source& __src, format = format::auto_format) {
773 _SourceCVT<_Source>::__append_source(__pn_, __src);
776 template <class _InputIt>
777 path(_InputIt __first, _InputIt __last, format = format::auto_format) {
778 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
779 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
782 // TODO Implement locale conversions.
783 template <class _Source, class = _EnableIfPathable<_Source, void> >
784 path(const _Source& __src, const locale& __loc, format = format::auto_format);
785 template <class _InputIt>
786 path(_InputIt __first, _InputIt _last, const locale& __loc,
787 format = format::auto_format);
789 _LIBCPP_INLINE_VISIBILITY
793 _LIBCPP_INLINE_VISIBILITY
794 path& operator=(const path& __p) {
799 _LIBCPP_INLINE_VISIBILITY
800 path& operator=(path&& __p) noexcept {
801 __pn_ = _VSTD::move(__p.__pn_);
805 template <class = void>
806 _LIBCPP_INLINE_VISIBILITY path& operator=(string_type&& __s) noexcept {
807 __pn_ = _VSTD::move(__s);
811 _LIBCPP_INLINE_VISIBILITY
812 path& assign(string_type&& __s) noexcept {
813 __pn_ = _VSTD::move(__s);
817 template <class _Source>
818 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
819 operator=(const _Source& __src) {
820 return this->assign(__src);
823 template <class _Source>
824 _EnableIfPathable<_Source> assign(const _Source& __src) {
826 _SourceCVT<_Source>::__append_source(__pn_, __src);
830 template <class _InputIt>
831 path& assign(_InputIt __first, _InputIt __last) {
832 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
834 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
839 template <class _ECharT>
840 static bool __source_is_absolute(_ECharT __first_or_null) {
841 return __is_separator(__first_or_null);
846 path& operator/=(const path& __p) {
847 if (__p.is_absolute()) {
852 __pn_ += preferred_separator;
853 __pn_ += __p.native();
857 // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
858 // is known at compile time to be "/' since the user almost certainly intended
859 // to append a separator instead of overwriting the path with "/"
860 template <class _Source>
861 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
862 operator/=(const _Source& __src) {
863 return this->append(__src);
866 template <class _Source>
867 _EnableIfPathable<_Source> append(const _Source& __src) {
868 using _Traits = __is_pathable<_Source>;
869 using _CVT = _PathCVT<_SourceChar<_Source> >;
870 if (__source_is_absolute(_Traits::__first_or_null(__src)))
872 else if (has_filename())
873 __pn_ += preferred_separator;
874 _CVT::__append_source(__pn_, __src);
878 template <class _InputIt>
879 path& append(_InputIt __first, _InputIt __last) {
880 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
881 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
882 using _CVT = _PathCVT<_ItVal>;
883 if (__first != __last && __source_is_absolute(*__first))
885 else if (has_filename())
886 __pn_ += preferred_separator;
887 _CVT::__append_range(__pn_, __first, __last);
892 _LIBCPP_INLINE_VISIBILITY
893 path& operator+=(const path& __x) {
898 _LIBCPP_INLINE_VISIBILITY
899 path& operator+=(const string_type& __x) {
904 _LIBCPP_INLINE_VISIBILITY
905 path& operator+=(__string_view __x) {
910 _LIBCPP_INLINE_VISIBILITY
911 path& operator+=(const value_type* __x) {
916 _LIBCPP_INLINE_VISIBILITY
917 path& operator+=(value_type __x) {
922 template <class _ECharT>
923 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
924 operator+=(_ECharT __x) {
925 basic_string<_ECharT> __tmp;
927 _PathCVT<_ECharT>::__append_source(__pn_, __tmp);
931 template <class _Source>
932 _EnableIfPathable<_Source> operator+=(const _Source& __x) {
933 return this->concat(__x);
936 template <class _Source>
937 _EnableIfPathable<_Source> concat(const _Source& __x) {
938 _SourceCVT<_Source>::__append_source(__pn_, __x);
942 template <class _InputIt>
943 path& concat(_InputIt __first, _InputIt __last) {
944 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
945 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
950 _LIBCPP_INLINE_VISIBILITY
951 void clear() noexcept { __pn_.clear(); }
953 path& make_preferred() { return *this; }
955 _LIBCPP_INLINE_VISIBILITY
956 path& remove_filename() {
957 auto __fname = __filename();
958 if (!__fname.empty())
959 __pn_.erase(__fname.data() - __pn_.data());
963 path& replace_filename(const path& __replacement) {
965 return (*this /= __replacement);
968 path& replace_extension(const path& __replacement = path());
970 _LIBCPP_INLINE_VISIBILITY
971 void swap(path& __rhs) noexcept { __pn_.swap(__rhs.__pn_); }
973 // private helper to allow reserving memory in the path
974 _LIBCPP_INLINE_VISIBILITY
975 void __reserve(size_t __s) { __pn_.reserve(__s); }
977 // native format observers
978 _LIBCPP_INLINE_VISIBILITY
979 const string_type& native() const noexcept { return __pn_; }
981 _LIBCPP_INLINE_VISIBILITY
982 const value_type* c_str() const noexcept { return __pn_.c_str(); }
984 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
986 template <class _ECharT, class _Traits = char_traits<_ECharT>,
987 class _Allocator = allocator<_ECharT> >
988 basic_string<_ECharT, _Traits, _Allocator>
989 string(const _Allocator& __a = _Allocator()) const {
990 using _CVT = __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__>;
991 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
993 __s.reserve(__pn_.size());
994 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
998 _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; }
999 _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const {
1000 return string<wchar_t>();
1002 _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; }
1003 _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const {
1004 return string<char16_t>();
1006 _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const {
1007 return string<char32_t>();
1010 // generic format observers
1011 template <class _ECharT, class _Traits = char_traits<_ECharT>,
1012 class _Allocator = allocator<_ECharT> >
1013 basic_string<_ECharT, _Traits, _Allocator>
1014 generic_string(const _Allocator& __a = _Allocator()) const {
1015 return string<_ECharT, _Traits, _Allocator>(__a);
1018 std::string generic_string() const { return __pn_; }
1019 std::wstring generic_wstring() const { return string<wchar_t>(); }
1020 std::string generic_u8string() const { return __pn_; }
1021 std::u16string generic_u16string() const { return string<char16_t>(); }
1022 std::u32string generic_u32string() const { return string<char32_t>(); }
1025 int __compare(__string_view) const;
1026 __string_view __root_name() const;
1027 __string_view __root_directory() const;
1028 __string_view __root_path_raw() const;
1029 __string_view __relative_path() const;
1030 __string_view __parent_path() const;
1031 __string_view __filename() const;
1032 __string_view __stem() const;
1033 __string_view __extension() const;
1037 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept {
1038 return __compare(__p.__pn_);
1040 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const {
1041 return __compare(__s);
1043 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const {
1044 return __compare(__s);
1046 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const {
1047 return __compare(__s);
1051 _LIBCPP_INLINE_VISIBILITY path root_name() const {
1052 return string_type(__root_name());
1054 _LIBCPP_INLINE_VISIBILITY path root_directory() const {
1055 return string_type(__root_directory());
1057 _LIBCPP_INLINE_VISIBILITY path root_path() const {
1058 return root_name().append(string_type(__root_directory()));
1060 _LIBCPP_INLINE_VISIBILITY path relative_path() const {
1061 return string_type(__relative_path());
1063 _LIBCPP_INLINE_VISIBILITY path parent_path() const {
1064 return string_type(__parent_path());
1066 _LIBCPP_INLINE_VISIBILITY path filename() const {
1067 return string_type(__filename());
1069 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem()); }
1070 _LIBCPP_INLINE_VISIBILITY path extension() const {
1071 return string_type(__extension());
1075 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool
1076 empty() const noexcept {
1077 return __pn_.empty();
1080 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const {
1081 return !__root_name().empty();
1083 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const {
1084 return !__root_directory().empty();
1086 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const {
1087 return !__root_path_raw().empty();
1089 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const {
1090 return !__relative_path().empty();
1092 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const {
1093 return !__parent_path().empty();
1095 _LIBCPP_INLINE_VISIBILITY bool has_filename() const {
1096 return !__filename().empty();
1098 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
1099 _LIBCPP_INLINE_VISIBILITY bool has_extension() const {
1100 return !__extension().empty();
1103 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const {
1104 return has_root_directory();
1106 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
1109 path lexically_normal() const;
1110 path lexically_relative(const path& __base) const;
1112 _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
1113 path __result = this->lexically_relative(__base);
1114 if (__result.native().empty())
1120 class _LIBCPP_TYPE_VIS iterator;
1121 typedef iterator const_iterator;
1123 iterator begin() const;
1124 iterator end() const;
1126 template <class _CharT, class _Traits>
1127 _LIBCPP_INLINE_VISIBILITY friend
1128 typename enable_if<is_same<_CharT, char>::value &&
1129 is_same<_Traits, char_traits<char> >::value,
1130 basic_ostream<_CharT, _Traits>&>::type
1131 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1132 __os << std::__quoted(__p.native());
1136 template <class _CharT, class _Traits>
1137 _LIBCPP_INLINE_VISIBILITY friend
1138 typename enable_if<!is_same<_CharT, char>::value ||
1139 !is_same<_Traits, char_traits<char> >::value,
1140 basic_ostream<_CharT, _Traits>&>::type
1141 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1142 __os << std::__quoted(__p.string<_CharT, _Traits>());
1146 template <class _CharT, class _Traits>
1147 _LIBCPP_INLINE_VISIBILITY friend basic_istream<_CharT, _Traits>&
1148 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) {
1149 basic_string<_CharT, _Traits> __tmp;
1150 __is >> __quoted(__tmp);
1155 friend _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) noexcept {
1156 return __lhs.compare(__rhs) == 0;
1158 friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) noexcept {
1159 return __lhs.compare(__rhs) != 0;
1161 friend _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) noexcept {
1162 return __lhs.compare(__rhs) < 0;
1164 friend _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) noexcept {
1165 return __lhs.compare(__rhs) <= 0;
1167 friend _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) noexcept {
1168 return __lhs.compare(__rhs) > 0;
1170 friend _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) noexcept {
1171 return __lhs.compare(__rhs) >= 0;
1174 friend _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs,
1175 const path& __rhs) {
1176 path __result(__lhs);
1181 inline _LIBCPP_INLINE_VISIBILITY path&
1182 __assign_view(__string_view const& __s) noexcept {
1183 __pn_ = string_type(__s);
1189 inline _LIBCPP_INLINE_VISIBILITY void swap(path& __lhs, path& __rhs) noexcept {
1194 size_t hash_value(const path& __p) noexcept;
1196 template <class _Source>
1197 _LIBCPP_INLINE_VISIBILITY
1198 typename enable_if<__is_pathable<_Source>::value, path>::type
1199 u8path(const _Source& __s) {
1201 is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1202 "u8path(Source const&) requires Source have a character type of type "
1207 template <class _InputIt>
1208 _LIBCPP_INLINE_VISIBILITY
1209 typename enable_if<__is_pathable<_InputIt>::value, path>::type
1210 u8path(_InputIt __f, _InputIt __l) {
1212 is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1213 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
1214 return path(__f, __l);
1217 class _LIBCPP_TYPE_VIS path::iterator {
1219 enum _ParserState : unsigned char {
1230 typedef bidirectional_iterator_tag iterator_category;
1232 typedef path value_type;
1233 typedef std::ptrdiff_t difference_type;
1234 typedef const path* pointer;
1235 typedef const path& reference;
1238 __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
1241 _LIBCPP_INLINE_VISIBILITY
1243 : __stashed_elem_(), __path_ptr_(nullptr), __entry_(),
1244 __state_(_Singular) {}
1246 iterator(const iterator&) = default;
1247 ~iterator() = default;
1249 iterator& operator=(const iterator&) = default;
1251 _LIBCPP_INLINE_VISIBILITY
1252 reference operator*() const { return __stashed_elem_; }
1254 _LIBCPP_INLINE_VISIBILITY
1255 pointer operator->() const { return &__stashed_elem_; }
1257 _LIBCPP_INLINE_VISIBILITY
1258 iterator& operator++() {
1259 _LIBCPP_ASSERT(__state_ != _Singular,
1260 "attempting to increment a singular iterator");
1261 _LIBCPP_ASSERT(__state_ != _AtEnd,
1262 "attempting to increment the end iterator");
1263 return __increment();
1266 _LIBCPP_INLINE_VISIBILITY
1267 iterator operator++(int) {
1268 iterator __it(*this);
1273 _LIBCPP_INLINE_VISIBILITY
1274 iterator& operator--() {
1275 _LIBCPP_ASSERT(__state_ != _Singular,
1276 "attempting to decrement a singular iterator");
1277 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
1278 "attempting to decrement the begin iterator");
1279 return __decrement();
1282 _LIBCPP_INLINE_VISIBILITY
1283 iterator operator--(int) {
1284 iterator __it(*this);
1292 inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&,
1295 iterator& __increment();
1296 iterator& __decrement();
1298 path __stashed_elem_;
1299 const path* __path_ptr_;
1300 path::__string_view __entry_;
1301 _ParserState __state_;
1304 inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs,
1305 const path::iterator& __rhs) {
1306 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
1307 __lhs.__entry_.data() == __rhs.__entry_.data();
1310 inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs,
1311 const path::iterator& __rhs) {
1312 return !(__lhs == __rhs);
1315 // TODO(ldionne): We need to pop the pragma and push it again after
1316 // filesystem_error to work around PR41078.
1317 _LIBCPP_AVAILABILITY_FILESYSTEM_POP
1319 class _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error {
1321 _LIBCPP_INLINE_VISIBILITY
1322 filesystem_error(const string& __what, error_code __ec)
1323 : system_error(__ec, __what),
1324 __storage_(make_shared<_Storage>(path(), path())) {
1328 _LIBCPP_INLINE_VISIBILITY
1329 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1330 : system_error(__ec, __what),
1331 __storage_(make_shared<_Storage>(__p1, path())) {
1335 _LIBCPP_INLINE_VISIBILITY
1336 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1338 : system_error(__ec, __what),
1339 __storage_(make_shared<_Storage>(__p1, __p2)) {
1343 _LIBCPP_INLINE_VISIBILITY
1344 const path& path1() const noexcept { return __storage_->__p1_; }
1346 _LIBCPP_INLINE_VISIBILITY
1347 const path& path2() const noexcept { return __storage_->__p2_; }
1349 ~filesystem_error() override; // key function
1351 _LIBCPP_INLINE_VISIBILITY
1352 const char* what() const noexcept override {
1353 return __storage_->__what_.c_str();
1356 void __create_what(int __num_paths);
1359 struct _LIBCPP_HIDDEN _Storage {
1360 _LIBCPP_INLINE_VISIBILITY
1361 _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}
1367 shared_ptr<_Storage> __storage_;
1370 _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
1372 template <class... _Args>
1373 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
1374 #ifndef _LIBCPP_NO_EXCEPTIONS
1375 void __throw_filesystem_error(_Args&&... __args) {
1376 throw filesystem_error(std::forward<_Args>(__args)...);
1379 void __throw_filesystem_error(_Args&&...) {
1384 // operational functions
1387 path __absolute(const path&, error_code* __ec = nullptr);
1389 path __canonical(const path&, error_code* __ec = nullptr);
1391 void __copy(const path& __from, const path& __to, copy_options __opt,
1392 error_code* __ec = nullptr);
1394 bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1395 error_code* __ec = nullptr);
1397 void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1398 error_code* __ec = nullptr);
1400 bool __create_directories(const path& p, error_code* ec = nullptr);
1402 bool __create_directory(const path& p, error_code* ec = nullptr);
1404 bool __create_directory(const path& p, const path& attributes,
1405 error_code* ec = nullptr);
1407 void __create_directory_symlink(const path& __to, const path& __new_symlink,
1408 error_code* __ec = nullptr);
1410 void __create_hard_link(const path& __to, const path& __new_hard_link,
1411 error_code* __ec = nullptr);
1413 void __create_symlink(const path& __to, const path& __new_symlink,
1414 error_code* __ec = nullptr);
1416 path __current_path(error_code* __ec = nullptr);
1418 void __current_path(const path&, error_code* __ec = nullptr);
1420 bool __equivalent(const path&, const path&, error_code* __ec = nullptr);
1422 uintmax_t __file_size(const path&, error_code* __ec = nullptr);
1424 uintmax_t __hard_link_count(const path&, error_code* __ec = nullptr);
1426 bool __fs_is_empty(const path& p, error_code* ec = nullptr);
1428 file_time_type __last_write_time(const path& p, error_code* ec = nullptr);
1430 void __last_write_time(const path& p, file_time_type new_time,
1431 error_code* ec = nullptr);
1433 void __permissions(const path&, perms, perm_options, error_code* = nullptr);
1435 path __read_symlink(const path& p, error_code* ec = nullptr);
1437 bool __remove(const path& p, error_code* ec = nullptr);
1439 uintmax_t __remove_all(const path& p, error_code* ec = nullptr);
1441 void __rename(const path& from, const path& to, error_code* ec = nullptr);
1443 void __resize_file(const path& p, uintmax_t size, error_code* ec = nullptr);
1445 space_info __space(const path&, error_code* __ec = nullptr);
1447 file_status __status(const path&, error_code* __ec = nullptr);
1449 file_status __symlink_status(const path&, error_code* __ec = nullptr);
1451 path __system_complete(const path&, error_code* __ec = nullptr);
1453 path __temp_directory_path(error_code* __ec = nullptr);
1455 path __weakly_canonical(path const& __p, error_code* __ec = nullptr);
1457 inline _LIBCPP_INLINE_VISIBILITY path current_path() {
1458 return __current_path();
1461 inline _LIBCPP_INLINE_VISIBILITY path current_path(error_code& __ec) {
1462 return __current_path(&__ec);
1465 inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p) {
1466 __current_path(__p);
1469 inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p,
1470 error_code& __ec) noexcept {
1471 __current_path(__p, &__ec);
1474 inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p) {
1475 return __absolute(__p);
1478 inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p,
1480 return __absolute(__p, &__ec);
1483 inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p) {
1484 return __canonical(__p);
1487 inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p,
1489 return __canonical(__p, &__ec);
1492 inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from,
1494 __copy(__from, __to, copy_options::none);
1497 inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1499 __copy(__from, __to, copy_options::none, &__ec);
1502 inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1503 copy_options __opt) {
1504 __copy(__from, __to, __opt);
1507 inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1510 __copy(__from, __to, __opt, &__ec);
1513 inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
1515 return __copy_file(__from, __to, copy_options::none);
1518 inline _LIBCPP_INLINE_VISIBILITY bool
1519 copy_file(const path& __from, const path& __to, error_code& __ec) {
1520 return __copy_file(__from, __to, copy_options::none, &__ec);
1523 inline _LIBCPP_INLINE_VISIBILITY bool
1524 copy_file(const path& __from, const path& __to, copy_options __opt) {
1525 return __copy_file(__from, __to, __opt);
1528 inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
1532 return __copy_file(__from, __to, __opt, &__ec);
1535 inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __existing,
1536 const path& __new) {
1537 __copy_symlink(__existing, __new);
1540 inline _LIBCPP_INLINE_VISIBILITY void
1541 copy_symlink(const path& __ext, const path& __new, error_code& __ec) noexcept {
1542 __copy_symlink(__ext, __new, &__ec);
1545 inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p) {
1546 return __create_directories(__p);
1549 inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p,
1551 return __create_directories(__p, &__ec);
1554 inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p) {
1555 return __create_directory(__p);
1558 inline _LIBCPP_INLINE_VISIBILITY bool
1559 create_directory(const path& __p, error_code& __ec) noexcept {
1560 return __create_directory(__p, &__ec);
1563 inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p,
1564 const path& __attrs) {
1565 return __create_directory(__p, __attrs);
1568 inline _LIBCPP_INLINE_VISIBILITY bool
1569 create_directory(const path& __p, const path& __attrs,
1570 error_code& __ec) noexcept {
1571 return __create_directory(__p, __attrs, &__ec);
1574 inline _LIBCPP_INLINE_VISIBILITY void
1575 create_directory_symlink(const path& __to, const path& __new) {
1576 __create_directory_symlink(__to, __new);
1579 inline _LIBCPP_INLINE_VISIBILITY void
1580 create_directory_symlink(const path& __to, const path& __new,
1581 error_code& __ec) noexcept {
1582 __create_directory_symlink(__to, __new, &__ec);
1585 inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __to,
1586 const path& __new) {
1587 __create_hard_link(__to, __new);
1590 inline _LIBCPP_INLINE_VISIBILITY void
1591 create_hard_link(const path& __to, const path& __new,
1592 error_code& __ec) noexcept {
1593 __create_hard_link(__to, __new, &__ec);
1596 inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __to,
1597 const path& __new) {
1598 __create_symlink(__to, __new);
1601 inline _LIBCPP_INLINE_VISIBILITY void
1602 create_symlink(const path& __to, const path& __new, error_code& __ec) noexcept {
1603 return __create_symlink(__to, __new, &__ec);
1606 inline _LIBCPP_INLINE_VISIBILITY bool status_known(file_status __s) noexcept {
1607 return __s.type() != file_type::none;
1610 inline _LIBCPP_INLINE_VISIBILITY bool exists(file_status __s) noexcept {
1611 return status_known(__s) && __s.type() != file_type::not_found;
1614 inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p) {
1615 return exists(__status(__p));
1618 inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p,
1619 error_code& __ec) noexcept {
1620 auto __s = __status(__p, &__ec);
1621 if (status_known(__s))
1626 inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1,
1628 return __equivalent(__p1, __p2);
1631 inline _LIBCPP_INLINE_VISIBILITY bool
1632 equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept {
1633 return __equivalent(__p1, __p2, &__ec);
1636 inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p) {
1637 return __file_size(__p);
1640 inline _LIBCPP_INLINE_VISIBILITY uintmax_t
1641 file_size(const path& __p, error_code& __ec) noexcept {
1642 return __file_size(__p, &__ec);
1645 inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p) {
1646 return __hard_link_count(__p);
1649 inline _LIBCPP_INLINE_VISIBILITY uintmax_t
1650 hard_link_count(const path& __p, error_code& __ec) noexcept {
1651 return __hard_link_count(__p, &__ec);
1654 inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(file_status __s) noexcept {
1655 return __s.type() == file_type::block;
1658 inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p) {
1659 return is_block_file(__status(__p));
1662 inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p,
1663 error_code& __ec) noexcept {
1664 return is_block_file(__status(__p, &__ec));
1667 inline _LIBCPP_INLINE_VISIBILITY bool
1668 is_character_file(file_status __s) noexcept {
1669 return __s.type() == file_type::character;
1672 inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p) {
1673 return is_character_file(__status(__p));
1676 inline _LIBCPP_INLINE_VISIBILITY bool
1677 is_character_file(const path& __p, error_code& __ec) noexcept {
1678 return is_character_file(__status(__p, &__ec));
1681 inline _LIBCPP_INLINE_VISIBILITY bool is_directory(file_status __s) noexcept {
1682 return __s.type() == file_type::directory;
1685 inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p) {
1686 return is_directory(__status(__p));
1689 inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p,
1690 error_code& __ec) noexcept {
1691 return is_directory(__status(__p, &__ec));
1694 inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p) {
1695 return __fs_is_empty(__p);
1698 inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p,
1700 return __fs_is_empty(__p, &__ec);
1703 inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(file_status __s) noexcept {
1704 return __s.type() == file_type::fifo;
1706 inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p) {
1707 return is_fifo(__status(__p));
1710 inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p,
1711 error_code& __ec) noexcept {
1712 return is_fifo(__status(__p, &__ec));
1715 inline _LIBCPP_INLINE_VISIBILITY bool
1716 is_regular_file(file_status __s) noexcept {
1717 return __s.type() == file_type::regular;
1720 inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p) {
1721 return is_regular_file(__status(__p));
1724 inline _LIBCPP_INLINE_VISIBILITY bool
1725 is_regular_file(const path& __p, error_code& __ec) noexcept {
1726 return is_regular_file(__status(__p, &__ec));
1729 inline _LIBCPP_INLINE_VISIBILITY bool is_socket(file_status __s) noexcept {
1730 return __s.type() == file_type::socket;
1733 inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p) {
1734 return is_socket(__status(__p));
1737 inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p,
1738 error_code& __ec) noexcept {
1739 return is_socket(__status(__p, &__ec));
1742 inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(file_status __s) noexcept {
1743 return __s.type() == file_type::symlink;
1746 inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p) {
1747 return is_symlink(__symlink_status(__p));
1750 inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p,
1751 error_code& __ec) noexcept {
1752 return is_symlink(__symlink_status(__p, &__ec));
1755 inline _LIBCPP_INLINE_VISIBILITY bool is_other(file_status __s) noexcept {
1756 return exists(__s) && !is_regular_file(__s) && !is_directory(__s) &&
1760 inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p) {
1761 return is_other(__status(__p));
1764 inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p,
1765 error_code& __ec) noexcept {
1766 return is_other(__status(__p, &__ec));
1769 inline _LIBCPP_INLINE_VISIBILITY file_time_type
1770 last_write_time(const path& __p) {
1771 return __last_write_time(__p);
1774 inline _LIBCPP_INLINE_VISIBILITY file_time_type
1775 last_write_time(const path& __p, error_code& __ec) noexcept {
1776 return __last_write_time(__p, &__ec);
1779 inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p,
1780 file_time_type __t) {
1781 __last_write_time(__p, __t);
1784 inline _LIBCPP_INLINE_VISIBILITY void
1785 last_write_time(const path& __p, file_time_type __t,
1786 error_code& __ec) noexcept {
1787 __last_write_time(__p, __t, &__ec);
1790 inline _LIBCPP_INLINE_VISIBILITY void
1791 permissions(const path& __p, perms __prms,
1792 perm_options __opts = perm_options::replace) {
1793 __permissions(__p, __prms, __opts);
1796 inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms,
1797 error_code& __ec) noexcept {
1798 __permissions(__p, __prms, perm_options::replace, &__ec);
1801 inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms,
1802 perm_options __opts,
1804 __permissions(__p, __prms, __opts, &__ec);
1807 inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p,
1810 path __tmp = __weakly_canonical(__p, &__ec);
1813 path __tmp_base = __weakly_canonical(__base, &__ec);
1816 return __tmp.lexically_proximate(__tmp_base);
1819 inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p,
1821 return proximate(__p, current_path(), __ec);
1824 inline _LIBCPP_INLINE_VISIBILITY path
1825 proximate(const path& __p, const path& __base = current_path()) {
1826 return __weakly_canonical(__p).lexically_proximate(
1827 __weakly_canonical(__base));
1830 inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p) {
1831 return __read_symlink(__p);
1834 inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p,
1836 return __read_symlink(__p, &__ec);
1839 inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p,
1842 path __tmp = __weakly_canonical(__p, &__ec);
1845 path __tmpbase = __weakly_canonical(__base, &__ec);
1848 return __tmp.lexically_relative(__tmpbase);
1851 inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p,
1853 return relative(__p, current_path(), __ec);
1856 inline _LIBCPP_INLINE_VISIBILITY path
1857 relative(const path& __p, const path& __base = current_path()) {
1858 return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base));
1861 inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p) {
1862 return __remove(__p);
1865 inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p,
1866 error_code& __ec) noexcept {
1867 return __remove(__p, &__ec);
1870 inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p) {
1871 return __remove_all(__p);
1874 inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p,
1876 return __remove_all(__p, &__ec);
1879 inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from,
1881 return __rename(__from, __to);
1884 inline _LIBCPP_INLINE_VISIBILITY void
1885 rename(const path& __from, const path& __to, error_code& __ec) noexcept {
1886 return __rename(__from, __to, &__ec);
1889 inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p,
1891 return __resize_file(__p, __ns);
1894 inline _LIBCPP_INLINE_VISIBILITY void
1895 resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept {
1896 return __resize_file(__p, __ns, &__ec);
1899 inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p) {
1900 return __space(__p);
1903 inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p,
1904 error_code& __ec) noexcept {
1905 return __space(__p, &__ec);
1908 inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p) {
1909 return __status(__p);
1912 inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p,
1913 error_code& __ec) noexcept {
1914 return __status(__p, &__ec);
1917 inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p) {
1918 return __symlink_status(__p);
1921 inline _LIBCPP_INLINE_VISIBILITY file_status
1922 symlink_status(const path& __p, error_code& __ec) noexcept {
1923 return __symlink_status(__p, &__ec);
1926 inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path() {
1927 return __temp_directory_path();
1930 inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path(error_code& __ec) {
1931 return __temp_directory_path(&__ec);
1934 inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p) {
1935 return __weakly_canonical(__p);
1938 inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p,
1940 return __weakly_canonical(__p, &__ec);
1943 class directory_iterator;
1944 class recursive_directory_iterator;
1945 class _LIBCPP_HIDDEN __dir_stream;
1947 class directory_entry {
1948 typedef _VSTD_FS::path _Path;
1951 // constructors and destructors
1952 directory_entry() noexcept = default;
1953 directory_entry(directory_entry const&) = default;
1954 directory_entry(directory_entry&&) noexcept = default;
1956 _LIBCPP_INLINE_VISIBILITY
1957 explicit directory_entry(_Path const& __p) : __p_(__p) {
1962 _LIBCPP_INLINE_VISIBILITY
1963 directory_entry(_Path const& __p, error_code& __ec) : __p_(__p) {
1967 ~directory_entry() {}
1969 directory_entry& operator=(directory_entry const&) = default;
1970 directory_entry& operator=(directory_entry&&) noexcept = default;
1972 _LIBCPP_INLINE_VISIBILITY
1973 void assign(_Path const& __p) {
1979 _LIBCPP_INLINE_VISIBILITY
1980 void assign(_Path const& __p, error_code& __ec) {
1985 _LIBCPP_INLINE_VISIBILITY
1986 void replace_filename(_Path const& __p) {
1987 __p_.replace_filename(__p);
1992 _LIBCPP_INLINE_VISIBILITY
1993 void replace_filename(_Path const& __p, error_code& __ec) {
1994 __p_ = __p_.parent_path() / __p;
1998 _LIBCPP_INLINE_VISIBILITY
1999 void refresh() { __refresh(); }
2001 _LIBCPP_INLINE_VISIBILITY
2002 void refresh(error_code& __ec) noexcept { __refresh(&__ec); }
2004 _LIBCPP_INLINE_VISIBILITY
2005 _Path const& path() const noexcept { return __p_; }
2007 _LIBCPP_INLINE_VISIBILITY
2008 operator const _Path&() const noexcept { return __p_; }
2010 _LIBCPP_INLINE_VISIBILITY
2011 bool exists() const { return _VSTD_FS::exists(file_status{__get_ft()}); }
2013 _LIBCPP_INLINE_VISIBILITY
2014 bool exists(error_code& __ec) const noexcept {
2015 return _VSTD_FS::exists(file_status{__get_ft(&__ec)});
2018 _LIBCPP_INLINE_VISIBILITY
2019 bool is_block_file() const { return __get_ft() == file_type::block; }
2021 _LIBCPP_INLINE_VISIBILITY
2022 bool is_block_file(error_code& __ec) const noexcept {
2023 return __get_ft(&__ec) == file_type::block;
2026 _LIBCPP_INLINE_VISIBILITY
2027 bool is_character_file() const { return __get_ft() == file_type::character; }
2029 _LIBCPP_INLINE_VISIBILITY
2030 bool is_character_file(error_code& __ec) const noexcept {
2031 return __get_ft(&__ec) == file_type::character;
2034 _LIBCPP_INLINE_VISIBILITY
2035 bool is_directory() const { return __get_ft() == file_type::directory; }
2037 _LIBCPP_INLINE_VISIBILITY
2038 bool is_directory(error_code& __ec) const noexcept {
2039 return __get_ft(&__ec) == file_type::directory;
2042 _LIBCPP_INLINE_VISIBILITY
2043 bool is_fifo() const { return __get_ft() == file_type::fifo; }
2045 _LIBCPP_INLINE_VISIBILITY
2046 bool is_fifo(error_code& __ec) const noexcept {
2047 return __get_ft(&__ec) == file_type::fifo;
2050 _LIBCPP_INLINE_VISIBILITY
2051 bool is_other() const { return _VSTD_FS::is_other(file_status{__get_ft()}); }
2053 _LIBCPP_INLINE_VISIBILITY
2054 bool is_other(error_code& __ec) const noexcept {
2055 return _VSTD_FS::is_other(file_status{__get_ft(&__ec)});
2058 _LIBCPP_INLINE_VISIBILITY
2059 bool is_regular_file() const { return __get_ft() == file_type::regular; }
2061 _LIBCPP_INLINE_VISIBILITY
2062 bool is_regular_file(error_code& __ec) const noexcept {
2063 return __get_ft(&__ec) == file_type::regular;
2066 _LIBCPP_INLINE_VISIBILITY
2067 bool is_socket() const { return __get_ft() == file_type::socket; }
2069 _LIBCPP_INLINE_VISIBILITY
2070 bool is_socket(error_code& __ec) const noexcept {
2071 return __get_ft(&__ec) == file_type::socket;
2074 _LIBCPP_INLINE_VISIBILITY
2075 bool is_symlink() const { return __get_sym_ft() == file_type::symlink; }
2077 _LIBCPP_INLINE_VISIBILITY
2078 bool is_symlink(error_code& __ec) const noexcept {
2079 return __get_sym_ft(&__ec) == file_type::symlink;
2081 _LIBCPP_INLINE_VISIBILITY
2082 uintmax_t file_size() const { return __get_size(); }
2084 _LIBCPP_INLINE_VISIBILITY
2085 uintmax_t file_size(error_code& __ec) const noexcept {
2086 return __get_size(&__ec);
2089 _LIBCPP_INLINE_VISIBILITY
2090 uintmax_t hard_link_count() const { return __get_nlink(); }
2092 _LIBCPP_INLINE_VISIBILITY
2093 uintmax_t hard_link_count(error_code& __ec) const noexcept {
2094 return __get_nlink(&__ec);
2097 _LIBCPP_INLINE_VISIBILITY
2098 file_time_type last_write_time() const { return __get_write_time(); }
2100 _LIBCPP_INLINE_VISIBILITY
2101 file_time_type last_write_time(error_code& __ec) const noexcept {
2102 return __get_write_time(&__ec);
2105 _LIBCPP_INLINE_VISIBILITY
2106 file_status status() const { return __get_status(); }
2108 _LIBCPP_INLINE_VISIBILITY
2109 file_status status(error_code& __ec) const noexcept {
2110 return __get_status(&__ec);
2113 _LIBCPP_INLINE_VISIBILITY
2114 file_status symlink_status() const { return __get_symlink_status(); }
2116 _LIBCPP_INLINE_VISIBILITY
2117 file_status symlink_status(error_code& __ec) const noexcept {
2118 return __get_symlink_status(&__ec);
2121 _LIBCPP_INLINE_VISIBILITY
2122 bool operator<(directory_entry const& __rhs) const noexcept {
2123 return __p_ < __rhs.__p_;
2126 _LIBCPP_INLINE_VISIBILITY
2127 bool operator==(directory_entry const& __rhs) const noexcept {
2128 return __p_ == __rhs.__p_;
2131 _LIBCPP_INLINE_VISIBILITY
2132 bool operator!=(directory_entry const& __rhs) const noexcept {
2133 return __p_ != __rhs.__p_;
2136 _LIBCPP_INLINE_VISIBILITY
2137 bool operator<=(directory_entry const& __rhs) const noexcept {
2138 return __p_ <= __rhs.__p_;
2141 _LIBCPP_INLINE_VISIBILITY
2142 bool operator>(directory_entry const& __rhs) const noexcept {
2143 return __p_ > __rhs.__p_;
2146 _LIBCPP_INLINE_VISIBILITY
2147 bool operator>=(directory_entry const& __rhs) const noexcept {
2148 return __p_ >= __rhs.__p_;
2152 friend class directory_iterator;
2153 friend class recursive_directory_iterator;
2154 friend class __dir_stream;
2156 enum _CacheType : unsigned char {
2161 _RefreshSymlinkUnresolved,
2165 struct __cached_data {
2168 file_time_type __write_time_;
2170 perms __non_sym_perms_;
2172 _CacheType __cache_type_;
2174 _LIBCPP_INLINE_VISIBILITY
2175 __cached_data() noexcept { __reset(); }
2177 _LIBCPP_INLINE_VISIBILITY
2179 __cache_type_ = _Empty;
2180 __type_ = file_type::none;
2181 __sym_perms_ = __non_sym_perms_ = perms::unknown;
2182 __size_ = __nlink_ = uintmax_t(-1);
2183 __write_time_ = file_time_type::min();
2187 _LIBCPP_INLINE_VISIBILITY
2188 static __cached_data __create_iter_result(file_type __ft) {
2189 __cached_data __data;
2190 __data.__type_ = __ft;
2191 __data.__cache_type_ = [&]() {
2193 case file_type::none:
2195 case file_type::symlink:
2196 return _IterSymlink;
2198 return _IterNonSymlink;
2204 _LIBCPP_INLINE_VISIBILITY
2205 void __assign_iter_entry(_Path&& __p, __cached_data __dt) {
2206 __p_ = std::move(__p);
2211 error_code __do_refresh() noexcept;
2213 _LIBCPP_INLINE_VISIBILITY
2214 static bool __is_dne_error(error_code const& __ec) {
2217 switch (static_cast<errc>(__ec.value())) {
2218 case errc::no_such_file_or_directory:
2219 case errc::not_a_directory:
2226 _LIBCPP_INLINE_VISIBILITY
2227 void __handle_error(const char* __msg, error_code* __dest_ec,
2228 error_code const& __ec, bool __allow_dne = false) const {
2233 if (__ec && (!__allow_dne || !__is_dne_error(__ec)))
2234 __throw_filesystem_error(__msg, __p_, __ec);
2237 _LIBCPP_INLINE_VISIBILITY
2238 void __refresh(error_code* __ec = nullptr) {
2239 __handle_error("in directory_entry::refresh", __ec, __do_refresh(),
2240 /*allow_dne*/ true);
2243 _LIBCPP_INLINE_VISIBILITY
2244 file_type __get_sym_ft(error_code* __ec = nullptr) const {
2245 switch (__data_.__cache_type_) {
2247 return __symlink_status(__p_, __ec).type();
2249 case _RefreshSymlink:
2250 case _RefreshSymlinkUnresolved:
2253 return file_type::symlink;
2254 case _IterNonSymlink:
2255 case _RefreshNonSymlink:
2256 file_status __st(__data_.__type_);
2257 if (__ec && !_VSTD_FS::exists(__st))
2258 *__ec = make_error_code(errc::no_such_file_or_directory);
2261 return __data_.__type_;
2263 _LIBCPP_UNREACHABLE();
2266 _LIBCPP_INLINE_VISIBILITY
2267 file_type __get_ft(error_code* __ec = nullptr) const {
2268 switch (__data_.__cache_type_) {
2271 case _RefreshSymlinkUnresolved:
2272 return __status(__p_, __ec).type();
2273 case _IterNonSymlink:
2274 case _RefreshNonSymlink:
2275 case _RefreshSymlink: {
2276 file_status __st(__data_.__type_);
2277 if (__ec && !_VSTD_FS::exists(__st))
2278 *__ec = make_error_code(errc::no_such_file_or_directory);
2281 return __data_.__type_;
2284 _LIBCPP_UNREACHABLE();
2287 _LIBCPP_INLINE_VISIBILITY
2288 file_status __get_status(error_code* __ec = nullptr) const {
2289 switch (__data_.__cache_type_) {
2291 case _IterNonSymlink:
2293 case _RefreshSymlinkUnresolved:
2294 return __status(__p_, __ec);
2295 case _RefreshNonSymlink:
2296 case _RefreshSymlink:
2297 return file_status(__get_ft(__ec), __data_.__non_sym_perms_);
2299 _LIBCPP_UNREACHABLE();
2302 _LIBCPP_INLINE_VISIBILITY
2303 file_status __get_symlink_status(error_code* __ec = nullptr) const {
2304 switch (__data_.__cache_type_) {
2306 case _IterNonSymlink:
2308 return __symlink_status(__p_, __ec);
2309 case _RefreshNonSymlink:
2310 return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_);
2311 case _RefreshSymlink:
2312 case _RefreshSymlinkUnresolved:
2313 return file_status(__get_sym_ft(__ec), __data_.__sym_perms_);
2315 _LIBCPP_UNREACHABLE();
2318 _LIBCPP_INLINE_VISIBILITY
2319 uintmax_t __get_size(error_code* __ec = nullptr) const {
2320 switch (__data_.__cache_type_) {
2322 case _IterNonSymlink:
2324 case _RefreshSymlinkUnresolved:
2325 return _VSTD_FS::__file_size(__p_, __ec);
2326 case _RefreshSymlink:
2327 case _RefreshNonSymlink: {
2329 file_status __st(__get_ft(&__m_ec));
2330 __handle_error("in directory_entry::file_size", __ec, __m_ec);
2331 if (_VSTD_FS::exists(__st) && !_VSTD_FS::is_regular_file(__st)) {
2332 errc __err_kind = _VSTD_FS::is_directory(__st) ? errc::is_a_directory
2333 : errc::not_supported;
2334 __handle_error("in directory_entry::file_size", __ec,
2335 make_error_code(__err_kind));
2337 return __data_.__size_;
2340 _LIBCPP_UNREACHABLE();
2343 _LIBCPP_INLINE_VISIBILITY
2344 uintmax_t __get_nlink(error_code* __ec = nullptr) const {
2345 switch (__data_.__cache_type_) {
2347 case _IterNonSymlink:
2349 case _RefreshSymlinkUnresolved:
2350 return _VSTD_FS::__hard_link_count(__p_, __ec);
2351 case _RefreshSymlink:
2352 case _RefreshNonSymlink: {
2354 (void)__get_ft(&__m_ec);
2355 __handle_error("in directory_entry::hard_link_count", __ec, __m_ec);
2356 return __data_.__nlink_;
2359 _LIBCPP_UNREACHABLE();
2362 _LIBCPP_INLINE_VISIBILITY
2363 file_time_type __get_write_time(error_code* __ec = nullptr) const {
2364 switch (__data_.__cache_type_) {
2366 case _IterNonSymlink:
2368 case _RefreshSymlinkUnresolved:
2369 return _VSTD_FS::__last_write_time(__p_, __ec);
2370 case _RefreshSymlink:
2371 case _RefreshNonSymlink: {
2373 file_status __st(__get_ft(&__m_ec));
2374 __handle_error("in directory_entry::last_write_time", __ec, __m_ec);
2375 if (_VSTD_FS::exists(__st) &&
2376 __data_.__write_time_ == file_time_type::min())
2377 __handle_error("in directory_entry::last_write_time", __ec,
2378 make_error_code(errc::value_too_large));
2379 return __data_.__write_time_;
2382 _LIBCPP_UNREACHABLE();
2387 __cached_data __data_;
2390 class __dir_element_proxy {
2392 inline _LIBCPP_INLINE_VISIBILITY directory_entry operator*() {
2393 return _VSTD::move(__elem_);
2397 friend class directory_iterator;
2398 friend class recursive_directory_iterator;
2399 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
2400 __dir_element_proxy(__dir_element_proxy&& __o)
2401 : __elem_(_VSTD::move(__o.__elem_)) {}
2402 directory_entry __elem_;
2405 class directory_iterator {
2407 typedef directory_entry value_type;
2408 typedef ptrdiff_t difference_type;
2409 typedef value_type const* pointer;
2410 typedef value_type const& reference;
2411 typedef input_iterator_tag iterator_category;
2415 directory_iterator() noexcept {}
2417 explicit directory_iterator(const path& __p)
2418 : directory_iterator(__p, nullptr) {}
2420 directory_iterator(const path& __p, directory_options __opts)
2421 : directory_iterator(__p, nullptr, __opts) {}
2423 directory_iterator(const path& __p, error_code& __ec)
2424 : directory_iterator(__p, &__ec) {}
2426 directory_iterator(const path& __p, directory_options __opts,
2428 : directory_iterator(__p, &__ec, __opts) {}
2430 directory_iterator(const directory_iterator&) = default;
2431 directory_iterator(directory_iterator&&) = default;
2432 directory_iterator& operator=(const directory_iterator&) = default;
2434 directory_iterator& operator=(directory_iterator&& __o) noexcept {
2435 // non-default implementation provided to support self-move assign.
2437 __imp_ = _VSTD::move(__o.__imp_);
2442 ~directory_iterator() = default;
2444 const directory_entry& operator*() const {
2445 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
2446 return __dereference();
2449 const directory_entry* operator->() const { return &**this; }
2451 directory_iterator& operator++() { return __increment(); }
2453 __dir_element_proxy operator++(int) {
2454 __dir_element_proxy __p(**this);
2459 directory_iterator& increment(error_code& __ec) { return __increment(&__ec); }
2462 inline _LIBCPP_INLINE_VISIBILITY friend bool
2463 operator==(const directory_iterator& __lhs,
2464 const directory_iterator& __rhs) noexcept;
2466 // construct the dir_stream
2468 directory_iterator(const path&, error_code*,
2469 directory_options = directory_options::none);
2472 directory_iterator& __increment(error_code* __ec = nullptr);
2475 const directory_entry& __dereference() const;
2478 shared_ptr<__dir_stream> __imp_;
2481 inline _LIBCPP_INLINE_VISIBILITY bool
2482 operator==(const directory_iterator& __lhs,
2483 const directory_iterator& __rhs) noexcept {
2484 return __lhs.__imp_ == __rhs.__imp_;
2487 inline _LIBCPP_INLINE_VISIBILITY bool
2488 operator!=(const directory_iterator& __lhs,
2489 const directory_iterator& __rhs) noexcept {
2490 return !(__lhs == __rhs);
2493 // enable directory_iterator range-based for statements
2494 inline _LIBCPP_INLINE_VISIBILITY directory_iterator
2495 begin(directory_iterator __iter) noexcept {
2499 inline _LIBCPP_INLINE_VISIBILITY directory_iterator
2500 end(const directory_iterator&) noexcept {
2501 return directory_iterator();
2504 class recursive_directory_iterator {
2506 using value_type = directory_entry;
2507 using difference_type = std::ptrdiff_t;
2508 using pointer = directory_entry const*;
2509 using reference = directory_entry const&;
2510 using iterator_category = std::input_iterator_tag;
2513 // constructors and destructor
2514 _LIBCPP_INLINE_VISIBILITY
2515 recursive_directory_iterator() noexcept : __rec_(false) {}
2517 _LIBCPP_INLINE_VISIBILITY
2518 explicit recursive_directory_iterator(
2519 const path& __p, directory_options __xoptions = directory_options::none)
2520 : recursive_directory_iterator(__p, __xoptions, nullptr) {}
2522 _LIBCPP_INLINE_VISIBILITY
2523 recursive_directory_iterator(const path& __p, directory_options __xoptions,
2525 : recursive_directory_iterator(__p, __xoptions, &__ec) {}
2527 _LIBCPP_INLINE_VISIBILITY
2528 recursive_directory_iterator(const path& __p, error_code& __ec)
2529 : recursive_directory_iterator(__p, directory_options::none, &__ec) {}
2531 recursive_directory_iterator(const recursive_directory_iterator&) = default;
2532 recursive_directory_iterator(recursive_directory_iterator&&) = default;
2534 recursive_directory_iterator&
2535 operator=(const recursive_directory_iterator&) = default;
2537 _LIBCPP_INLINE_VISIBILITY
2538 recursive_directory_iterator&
2539 operator=(recursive_directory_iterator&& __o) noexcept {
2540 // non-default implementation provided to support self-move assign.
2542 __imp_ = _VSTD::move(__o.__imp_);
2543 __rec_ = __o.__rec_;
2548 ~recursive_directory_iterator() = default;
2550 _LIBCPP_INLINE_VISIBILITY
2551 const directory_entry& operator*() const { return __dereference(); }
2553 _LIBCPP_INLINE_VISIBILITY
2554 const directory_entry* operator->() const { return &__dereference(); }
2556 recursive_directory_iterator& operator++() { return __increment(); }
2558 _LIBCPP_INLINE_VISIBILITY
2559 __dir_element_proxy operator++(int) {
2560 __dir_element_proxy __p(**this);
2565 _LIBCPP_INLINE_VISIBILITY
2566 recursive_directory_iterator& increment(error_code& __ec) {
2567 return __increment(&__ec);
2570 _LIBCPP_FUNC_VIS directory_options options() const;
2571 _LIBCPP_FUNC_VIS int depth() const;
2573 _LIBCPP_INLINE_VISIBILITY
2574 void pop() { __pop(); }
2576 _LIBCPP_INLINE_VISIBILITY
2577 void pop(error_code& __ec) { __pop(&__ec); }
2579 _LIBCPP_INLINE_VISIBILITY
2580 bool recursion_pending() const { return __rec_; }
2582 _LIBCPP_INLINE_VISIBILITY
2583 void disable_recursion_pending() { __rec_ = false; }
2587 recursive_directory_iterator(const path& __p, directory_options __opt,
2591 const directory_entry& __dereference() const;
2594 bool __try_recursion(error_code* __ec);
2597 void __advance(error_code* __ec = nullptr);
2600 recursive_directory_iterator& __increment(error_code* __ec = nullptr);
2603 void __pop(error_code* __ec = nullptr);
2605 inline _LIBCPP_INLINE_VISIBILITY friend bool
2606 operator==(const recursive_directory_iterator&,
2607 const recursive_directory_iterator&) noexcept;
2609 struct _LIBCPP_HIDDEN __shared_imp;
2610 shared_ptr<__shared_imp> __imp_;
2612 }; // class recursive_directory_iterator
2614 inline _LIBCPP_INLINE_VISIBILITY bool
2615 operator==(const recursive_directory_iterator& __lhs,
2616 const recursive_directory_iterator& __rhs) noexcept {
2617 return __lhs.__imp_ == __rhs.__imp_;
2620 _LIBCPP_INLINE_VISIBILITY
2621 inline bool operator!=(const recursive_directory_iterator& __lhs,
2622 const recursive_directory_iterator& __rhs) noexcept {
2623 return !(__lhs == __rhs);
2625 // enable recursive_directory_iterator range-based for statements
2626 inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
2627 begin(recursive_directory_iterator __iter) noexcept {
2631 inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
2632 end(const recursive_directory_iterator&) noexcept {
2633 return recursive_directory_iterator();
2636 _LIBCPP_AVAILABILITY_FILESYSTEM_POP
2638 _LIBCPP_END_NAMESPACE_FILESYSTEM
2640 #endif // !_LIBCPP_CXX03_LANG
2644 #endif // _LIBCPP_FILESYSTEM