2 //===--------------------------- filesystem -------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_FILESYSTEM
11 #define _LIBCPP_FILESYSTEM
15 namespace std { namespace filesystem {
19 void swap(path& lhs, path& rhs) noexcept;
20 size_t hash_value(const path& p) 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;
27 bool operator>=(const path& lhs, const path& rhs) noexcept;
29 path operator/ (const path& lhs, const path& rhs);
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);
36 template <class charT, class traits>
37 friend basic_istream<charT, traits>&
38 operator>>(basic_istream<charT, traits>& is, path& p);
40 template <class Source>
41 path u8path(const Source& source);
42 template <class InputIterator>
43 path u8path(InputIterator first, InputIterator last);
45 class filesystem_error;
46 class directory_entry;
48 class directory_iterator;
50 // enable directory_iterator range-based for statements
51 directory_iterator begin(directory_iterator iter) noexcept;
52 directory_iterator end(const directory_iterator&) noexcept;
54 class recursive_directory_iterator;
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;
71 enum class perm_options;
72 enum class copy_options;
73 enum class directory_options;
75 typedef chrono::time_point<trivial-clock> file_time_type;
77 // operational functions
79 path absolute(const path& p);
80 path absolute(const path& p, error_code &ec);
82 path canonical(const path& p);
83 path canonical(const path& p, error_code& ec);
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,
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,
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;
101 bool create_directories(const path& p);
102 bool create_directories(const path& p, error_code& ec);
104 bool create_directory(const path& p);
105 bool create_directory(const path& p, error_code& ec) noexcept;
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;
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;
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;
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;
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;
128 bool exists(file_status s) noexcept;
129 bool exists(const path& p);
130 bool exists(const path& p, error_code& ec) noexcept;
132 bool equivalent(const path& p1, const path& p2);
133 bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
135 uintmax_t file_size(const path& p);
136 uintmax_t file_size(const path& p, error_code& ec) noexcept;
138 uintmax_t hard_link_count(const path& p);
139 uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
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;
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;
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;
153 bool is_empty(const path& p);
154 bool is_empty(const path& p, error_code& ec) noexcept;
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;
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;
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;
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;
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;
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;
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,
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);
192 path read_symlink(const path& p);
193 path read_symlink(const path& p, error_code& ec);
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);
199 bool remove(const path& p);
200 bool remove(const path& p, error_code& ec) noexcept;
202 uintmax_t remove_all(const path& p);
203 uintmax_t remove_all(const path& p, error_code& ec);
205 void rename(const path& from, const path& to);
206 void rename(const path& from, const path& to, error_code& ec) noexcept;
208 void resize_file(const path& p, uintmax_t size);
209 void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept;
211 space_info space(const path& p);
212 space_info space(const path& p, error_code& ec) noexcept;
214 file_status status(const path& p);
215 file_status status(const path& p, error_code& ec) noexcept;
217 bool status_known(file_status s) noexcept;
219 file_status symlink_status(const path& p);
220 file_status symlink_status(const path& p, error_code& ec) noexcept;
222 path temp_directory_path();
223 path temp_directory_path(error_code& ec);
225 path weakly_canonical(path const& p);
226 path weakly_canonical(path const& p, error_code& ec);
229 } } // namespaces std::filesystem
243 #include <system_error>
245 #include <iomanip> // for quoted
246 #include <string_view>
251 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
252 #pragma GCC system_header
256 #include <__undef_macros>
258 #ifndef _LIBCPP_CXX03_LANG
260 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
262 typedef chrono::time_point<_FilesystemClock> file_time_type;
264 struct _LIBCPP_TYPE_VIS space_info {
270 enum class _LIBCPP_ENUM_VIS file_type : signed char {
283 enum class _LIBCPP_ENUM_VIS perms : unsigned {
310 _LIBCPP_INLINE_VISIBILITY
311 inline constexpr perms operator&(perms _LHS, perms _RHS) {
312 return static_cast<perms>(static_cast<unsigned>(_LHS) &
313 static_cast<unsigned>(_RHS));
316 _LIBCPP_INLINE_VISIBILITY
317 inline constexpr perms operator|(perms _LHS, perms _RHS) {
318 return static_cast<perms>(static_cast<unsigned>(_LHS) |
319 static_cast<unsigned>(_RHS));
322 _LIBCPP_INLINE_VISIBILITY
323 inline constexpr perms operator^(perms _LHS, perms _RHS) {
324 return static_cast<perms>(static_cast<unsigned>(_LHS) ^
325 static_cast<unsigned>(_RHS));
328 _LIBCPP_INLINE_VISIBILITY
329 inline constexpr perms operator~(perms _LHS) {
330 return static_cast<perms>(~static_cast<unsigned>(_LHS));
333 _LIBCPP_INLINE_VISIBILITY
334 inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; }
336 _LIBCPP_INLINE_VISIBILITY
337 inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; }
339 _LIBCPP_INLINE_VISIBILITY
340 inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; }
342 enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
349 _LIBCPP_INLINE_VISIBILITY
350 inline 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));
355 _LIBCPP_INLINE_VISIBILITY
356 inline 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));
361 _LIBCPP_INLINE_VISIBILITY
362 inline 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));
367 _LIBCPP_INLINE_VISIBILITY
368 inline constexpr perm_options operator~(perm_options _LHS) {
369 return static_cast<perm_options>(~static_cast<unsigned>(_LHS));
372 _LIBCPP_INLINE_VISIBILITY
373 inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS) {
374 return _LHS = _LHS & _RHS;
377 _LIBCPP_INLINE_VISIBILITY
378 inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS) {
379 return _LHS = _LHS | _RHS;
382 _LIBCPP_INLINE_VISIBILITY
383 inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS) {
384 return _LHS = _LHS ^ _RHS;
387 enum class _LIBCPP_ENUM_VIS copy_options : unsigned short {
390 overwrite_existing = 2,
395 directories_only = 64,
396 create_symlinks = 128,
397 create_hard_links = 256,
398 __in_recursive_copy = 512,
401 _LIBCPP_INLINE_VISIBILITY
402 inline 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));
407 _LIBCPP_INLINE_VISIBILITY
408 inline 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));
413 _LIBCPP_INLINE_VISIBILITY
414 inline 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));
419 _LIBCPP_INLINE_VISIBILITY
420 inline constexpr copy_options operator~(copy_options _LHS) {
421 return static_cast<copy_options>(~static_cast<unsigned short>(_LHS));
424 _LIBCPP_INLINE_VISIBILITY
425 inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) {
426 return _LHS = _LHS & _RHS;
429 _LIBCPP_INLINE_VISIBILITY
430 inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) {
431 return _LHS = _LHS | _RHS;
434 _LIBCPP_INLINE_VISIBILITY
435 inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) {
436 return _LHS = _LHS ^ _RHS;
439 enum class _LIBCPP_ENUM_VIS directory_options : unsigned char {
441 follow_directory_symlink = 1,
442 skip_permission_denied = 2
445 _LIBCPP_INLINE_VISIBILITY
446 inline 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));
452 _LIBCPP_INLINE_VISIBILITY
453 inline 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));
459 _LIBCPP_INLINE_VISIBILITY
460 inline 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));
466 _LIBCPP_INLINE_VISIBILITY
467 inline constexpr directory_options operator~(directory_options _LHS) {
468 return static_cast<directory_options>(~static_cast<unsigned char>(_LHS));
471 _LIBCPP_INLINE_VISIBILITY
472 inline directory_options& operator&=(directory_options& _LHS,
473 directory_options _RHS) {
474 return _LHS = _LHS & _RHS;
477 _LIBCPP_INLINE_VISIBILITY
478 inline directory_options& operator|=(directory_options& _LHS,
479 directory_options _RHS) {
480 return _LHS = _LHS | _RHS;
483 _LIBCPP_INLINE_VISIBILITY
484 inline directory_options& operator^=(directory_options& _LHS,
485 directory_options _RHS) {
486 return _LHS = _LHS ^ _RHS;
489 class _LIBCPP_TYPE_VIS file_status {
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
499 file_status(const file_status&) noexcept = default;
500 file_status(file_status&&) noexcept = default;
502 _LIBCPP_INLINE_VISIBILITY
505 file_status& operator=(const file_status&) noexcept = default;
506 file_status& operator=(file_status&&) noexcept = default;
509 _LIBCPP_INLINE_VISIBILITY
510 file_type type() const noexcept { return __ft_; }
512 _LIBCPP_INLINE_VISIBILITY
513 perms permissions() const noexcept { return __prms_; }
516 _LIBCPP_INLINE_VISIBILITY
517 void type(file_type __ft) noexcept { __ft_ = __ft; }
519 _LIBCPP_INLINE_VISIBILITY
520 void permissions(perms __p) noexcept { __prms_ = __p; }
527 class _LIBCPP_TYPE_VIS directory_entry;
530 struct __can_convert_char {
531 static const bool value = false;
534 struct __can_convert_char<const _Tp> : public __can_convert_char<_Tp> {};
536 struct __can_convert_char<char> {
537 static const bool value = true;
538 using __char_type = char;
541 struct __can_convert_char<wchar_t> {
542 static const bool value = true;
543 using __char_type = wchar_t;
546 struct __can_convert_char<char16_t> {
547 static const bool value = true;
548 using __char_type = char16_t;
551 struct __can_convert_char<char32_t> {
552 static const bool value = true;
553 using __char_type = char32_t;
556 template <class _ECharT>
557 typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
558 __is_separator(_ECharT __e) {
559 return __e == _ECharT('/');
562 struct _NullSentinal {};
567 template <class _Tp, class = void>
568 struct __is_pathable_string : public false_type {};
570 template <class _ECharT, class _Traits, class _Alloc>
571 struct __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();
581 static _ECharT __first_or_null(_Str const& __s) {
582 return __s.empty() ? _ECharT{} : __s[0];
586 template <class _ECharT, class _Traits>
587 struct __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();
597 static _ECharT __first_or_null(_Str const& __s) {
598 return __s.empty() ? _ECharT{} : __s[0];
602 template <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>
607 struct __is_pathable_char_array : false_type {};
609 template <class _Source, class _ECharT, class _UPtr>
610 struct __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>;
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{};
619 for (; *__e != __sentinal; ++__e)
624 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
627 template <class _Iter, bool _IsIt = __is_input_iterator<_Iter>::value,
629 struct __is_pathable_iter : false_type {};
631 template <class _Iter>
632 struct __is_pathable_iter<
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>;
640 static _Iter __range_begin(_Iter __b) { return __b; }
641 static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; }
643 static _ECharT __first_or_null(_Iter __b) { return *__b; }
646 template <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>
649 struct __is_pathable : false_type {
650 static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
654 struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
657 struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {
661 struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
663 template <class _ECharT>
665 static_assert(__can_convert_char<_ECharT>::value,
666 "Char type not convertible");
668 typedef __narrow_to_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Narrower;
670 static void __append_range(string& __dest, _ECharT const* __b,
671 _ECharT const* __e) {
672 _Narrower()(back_inserter(__dest), __b, __e);
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");
680 basic_string<_ECharT> __tmp(__b, __e);
681 _Narrower()(back_inserter(__dest), __tmp.data(),
682 __tmp.data() + __tmp.length());
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)
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());
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));
707 struct _PathCVT<char> {
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);
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);
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);
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));
737 class _LIBCPP_TYPE_VIS path {
738 template <class _SourceOrIter, class _Tp = path&>
739 using _EnableIfPathable =
740 typename enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
743 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
746 using _SourceCVT = _PathCVT<_SourceChar<_Tp> >;
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 = '/';
754 enum class _LIBCPP_ENUM_VIS format : unsigned char {
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_)) {}
766 _LIBCPP_INLINE_VISIBILITY
767 path(string_type&& __s, format = format::auto_format) noexcept
768 : __pn_(_VSTD::move(__s)) {}
770 template <class _Source, class = _EnableIfPathable<_Source, void> >
771 path(const _Source& __src, format = format::auto_format) {
772 _SourceCVT<_Source>::__append_source(__pn_, __src);
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);
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);
788 _LIBCPP_INLINE_VISIBILITY
792 _LIBCPP_INLINE_VISIBILITY
793 path& operator=(const path& __p) {
798 _LIBCPP_INLINE_VISIBILITY
799 path& operator=(path&& __p) noexcept {
800 __pn_ = _VSTD::move(__p.__pn_);
804 template <class = void>
805 _LIBCPP_INLINE_VISIBILITY path& operator=(string_type&& __s) noexcept {
806 __pn_ = _VSTD::move(__s);
810 _LIBCPP_INLINE_VISIBILITY
811 path& assign(string_type&& __s) noexcept {
812 __pn_ = _VSTD::move(__s);
816 template <class _Source>
817 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
818 operator=(const _Source& __src) {
819 return this->assign(__src);
822 template <class _Source>
823 _EnableIfPathable<_Source> assign(const _Source& __src) {
825 _SourceCVT<_Source>::__append_source(__pn_, __src);
829 template <class _InputIt>
830 path& assign(_InputIt __first, _InputIt __last) {
831 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
833 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
838 template <class _ECharT>
839 static bool __source_is_absolute(_ECharT __first_or_null) {
840 return __is_separator(__first_or_null);
845 path& operator/=(const path& __p) {
846 if (__p.is_absolute()) {
851 __pn_ += preferred_separator;
852 __pn_ += __p.native();
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);
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)))
871 else if (has_filename())
872 __pn_ += preferred_separator;
873 _CVT::__append_source(__pn_, __src);
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))
884 else if (has_filename())
885 __pn_ += preferred_separator;
886 _CVT::__append_range(__pn_, __first, __last);
891 _LIBCPP_INLINE_VISIBILITY
892 path& operator+=(const path& __x) {
897 _LIBCPP_INLINE_VISIBILITY
898 path& operator+=(const string_type& __x) {
903 _LIBCPP_INLINE_VISIBILITY
904 path& operator+=(__string_view __x) {
909 _LIBCPP_INLINE_VISIBILITY
910 path& operator+=(const value_type* __x) {
915 _LIBCPP_INLINE_VISIBILITY
916 path& operator+=(value_type __x) {
921 template <class _ECharT>
922 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
923 operator+=(_ECharT __x) {
924 basic_string<_ECharT> __tmp;
926 _PathCVT<_ECharT>::__append_source(__pn_, __tmp);
930 template <class _Source>
931 _EnableIfPathable<_Source> operator+=(const _Source& __x) {
932 return this->concat(__x);
935 template <class _Source>
936 _EnableIfPathable<_Source> concat(const _Source& __x) {
937 _SourceCVT<_Source>::__append_source(__pn_, __x);
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);
949 _LIBCPP_INLINE_VISIBILITY
950 void clear() noexcept { __pn_.clear(); }
952 path& make_preferred() { return *this; }
954 _LIBCPP_INLINE_VISIBILITY
955 path& remove_filename() {
956 auto __fname = __filename();
957 if (!__fname.empty())
958 __pn_.erase(__fname.data() - __pn_.data());
962 path& replace_filename(const path& __replacement) {
964 return (*this /= __replacement);
967 path& replace_extension(const path& __replacement = path());
969 _LIBCPP_INLINE_VISIBILITY
970 void swap(path& __rhs) noexcept { __pn_.swap(__rhs.__pn_); }
972 // private helper to allow reserving memory in the path
973 _LIBCPP_INLINE_VISIBILITY
974 void __reserve(size_t __s) { __pn_.reserve(__s); }
976 // native format observers
977 _LIBCPP_INLINE_VISIBILITY
978 const string_type& native() const noexcept { return __pn_; }
980 _LIBCPP_INLINE_VISIBILITY
981 const value_type* c_str() const noexcept { return __pn_.c_str(); }
983 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
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>;
992 __s.reserve(__pn_.size());
993 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
997 _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; }
998 _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const {
999 return string<wchar_t>();
1001 _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; }
1002 _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const {
1003 return string<char16_t>();
1005 _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const {
1006 return string<char32_t>();
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);
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>(); }
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;
1036 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept {
1037 return __compare(__p.__pn_);
1039 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const {
1040 return __compare(__s);
1042 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const {
1043 return __compare(__s);
1045 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const {
1046 return __compare(__s);
1050 _LIBCPP_INLINE_VISIBILITY path root_name() const {
1051 return string_type(__root_name());
1053 _LIBCPP_INLINE_VISIBILITY path root_directory() const {
1054 return string_type(__root_directory());
1056 _LIBCPP_INLINE_VISIBILITY path root_path() const {
1057 return root_name().append(string_type(__root_directory()));
1059 _LIBCPP_INLINE_VISIBILITY path relative_path() const {
1060 return string_type(__relative_path());
1062 _LIBCPP_INLINE_VISIBILITY path parent_path() const {
1063 return string_type(__parent_path());
1065 _LIBCPP_INLINE_VISIBILITY path filename() const {
1066 return string_type(__filename());
1068 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem()); }
1069 _LIBCPP_INLINE_VISIBILITY path extension() const {
1070 return string_type(__extension());
1074 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool
1075 empty() const noexcept {
1076 return __pn_.empty();
1079 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const {
1080 return !__root_name().empty();
1082 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const {
1083 return !__root_directory().empty();
1085 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const {
1086 return !__root_path_raw().empty();
1088 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const {
1089 return !__relative_path().empty();
1091 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const {
1092 return !__parent_path().empty();
1094 _LIBCPP_INLINE_VISIBILITY bool has_filename() const {
1095 return !__filename().empty();
1097 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
1098 _LIBCPP_INLINE_VISIBILITY bool has_extension() const {
1099 return !__extension().empty();
1102 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const {
1103 return has_root_directory();
1105 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
1108 path lexically_normal() const;
1109 path lexically_relative(const path& __base) const;
1111 _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
1112 path __result = this->lexically_relative(__base);
1113 if (__result.native().empty())
1119 class _LIBCPP_TYPE_VIS iterator;
1120 typedef iterator const_iterator;
1122 iterator begin() const;
1123 iterator end() const;
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());
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>());
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);
1154 friend _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) noexcept {
1155 return __lhs.compare(__rhs) == 0;
1157 friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) noexcept {
1158 return __lhs.compare(__rhs) != 0;
1160 friend _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) noexcept {
1161 return __lhs.compare(__rhs) < 0;
1163 friend _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) noexcept {
1164 return __lhs.compare(__rhs) <= 0;
1166 friend _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) noexcept {
1167 return __lhs.compare(__rhs) > 0;
1169 friend _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) noexcept {
1170 return __lhs.compare(__rhs) >= 0;
1173 friend _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs,
1174 const path& __rhs) {
1175 path __result(__lhs);
1180 inline _LIBCPP_INLINE_VISIBILITY path&
1181 __assign_view(__string_view const& __s) noexcept {
1182 __pn_ = string_type(__s);
1188 inline _LIBCPP_INLINE_VISIBILITY void swap(path& __lhs, path& __rhs) noexcept {
1193 size_t hash_value(const path& __p) noexcept;
1195 template <class _Source>
1196 _LIBCPP_INLINE_VISIBILITY
1197 typename enable_if<__is_pathable<_Source>::value, path>::type
1198 u8path(const _Source& __s) {
1200 is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1201 "u8path(Source const&) requires Source have a character type of type "
1206 template <class _InputIt>
1207 _LIBCPP_INLINE_VISIBILITY
1208 typename enable_if<__is_pathable<_InputIt>::value, path>::type
1209 u8path(_InputIt __f, _InputIt __l) {
1211 is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1212 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
1213 return path(__f, __l);
1216 class _LIBCPP_TYPE_VIS path::iterator {
1218 enum _ParserState : unsigned char {
1229 typedef bidirectional_iterator_tag iterator_category;
1231 typedef path value_type;
1232 typedef std::ptrdiff_t difference_type;
1233 typedef const path* pointer;
1234 typedef const path& reference;
1237 __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
1240 _LIBCPP_INLINE_VISIBILITY
1242 : __stashed_elem_(), __path_ptr_(nullptr), __entry_(),
1243 __state_(_Singular) {}
1245 iterator(const iterator&) = default;
1246 ~iterator() = default;
1248 iterator& operator=(const iterator&) = default;
1250 _LIBCPP_INLINE_VISIBILITY
1251 reference operator*() const { return __stashed_elem_; }
1253 _LIBCPP_INLINE_VISIBILITY
1254 pointer operator->() const { return &__stashed_elem_; }
1256 _LIBCPP_INLINE_VISIBILITY
1257 iterator& operator++() {
1258 _LIBCPP_ASSERT(__state_ != _Singular,
1259 "attempting to increment a singular iterator");
1260 _LIBCPP_ASSERT(__state_ != _AtEnd,
1261 "attempting to increment the end iterator");
1262 return __increment();
1265 _LIBCPP_INLINE_VISIBILITY
1266 iterator operator++(int) {
1267 iterator __it(*this);
1272 _LIBCPP_INLINE_VISIBILITY
1273 iterator& operator--() {
1274 _LIBCPP_ASSERT(__state_ != _Singular,
1275 "attempting to decrement a singular iterator");
1276 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
1277 "attempting to decrement the begin iterator");
1278 return __decrement();
1281 _LIBCPP_INLINE_VISIBILITY
1282 iterator operator--(int) {
1283 iterator __it(*this);
1291 inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&,
1294 iterator& __increment();
1295 iterator& __decrement();
1297 path __stashed_elem_;
1298 const path* __path_ptr_;
1299 path::__string_view __entry_;
1300 _ParserState __state_;
1303 inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs,
1304 const path::iterator& __rhs) {
1305 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
1306 __lhs.__entry_.data() == __rhs.__entry_.data();
1309 inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs,
1310 const path::iterator& __rhs) {
1311 return !(__lhs == __rhs);
1314 class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error {
1316 _LIBCPP_INLINE_VISIBILITY
1317 filesystem_error(const string& __what, error_code __ec)
1318 : system_error(__ec, __what),
1319 __storage_(make_shared<_Storage>(path(), path())) {
1323 _LIBCPP_INLINE_VISIBILITY
1324 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1325 : system_error(__ec, __what),
1326 __storage_(make_shared<_Storage>(__p1, path())) {
1330 _LIBCPP_INLINE_VISIBILITY
1331 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1333 : system_error(__ec, __what),
1334 __storage_(make_shared<_Storage>(__p1, __p2)) {
1338 _LIBCPP_INLINE_VISIBILITY
1339 const path& path1() const noexcept { return __storage_->__p1_; }
1341 _LIBCPP_INLINE_VISIBILITY
1342 const path& path2() const noexcept { return __storage_->__p2_; }
1344 ~filesystem_error() override; // key function
1346 _LIBCPP_INLINE_VISIBILITY
1347 const char* what() const noexcept override {
1348 return __storage_->__what_.c_str();
1352 void __create_what(int __num_paths);
1356 _LIBCPP_INLINE_VISIBILITY
1357 _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}
1363 shared_ptr<_Storage> __storage_;
1366 template <class... _Args>
1367 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
1368 #ifndef _LIBCPP_NO_EXCEPTIONS
1370 __throw_filesystem_error(_Args&&... __args) {
1371 throw filesystem_error(std::forward<_Args>(__args)...);
1375 __throw_filesystem_error(_Args&&...) {
1380 // operational functions
1383 path __absolute(const path&, error_code* __ec = nullptr);
1385 path __canonical(const path&, error_code* __ec = nullptr);
1387 void __copy(const path& __from, const path& __to, copy_options __opt,
1388 error_code* __ec = nullptr);
1390 bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1391 error_code* __ec = nullptr);
1393 void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1394 error_code* __ec = nullptr);
1396 bool __create_directories(const path& p, error_code* ec = nullptr);
1398 bool __create_directory(const path& p, error_code* ec = nullptr);
1400 bool __create_directory(const path& p, const path& attributes,
1401 error_code* ec = nullptr);
1403 void __create_directory_symlink(const path& __to, const path& __new_symlink,
1404 error_code* __ec = nullptr);
1406 void __create_hard_link(const path& __to, const path& __new_hard_link,
1407 error_code* __ec = nullptr);
1409 void __create_symlink(const path& __to, const path& __new_symlink,
1410 error_code* __ec = nullptr);
1412 path __current_path(error_code* __ec = nullptr);
1414 void __current_path(const path&, error_code* __ec = nullptr);
1416 bool __equivalent(const path&, const path&, error_code* __ec = nullptr);
1418 uintmax_t __file_size(const path&, error_code* __ec = nullptr);
1420 uintmax_t __hard_link_count(const path&, error_code* __ec = nullptr);
1422 bool __fs_is_empty(const path& p, error_code* ec = nullptr);
1424 file_time_type __last_write_time(const path& p, error_code* ec = nullptr);
1426 void __last_write_time(const path& p, file_time_type new_time,
1427 error_code* ec = nullptr);
1429 void __permissions(const path&, perms, perm_options, error_code* = nullptr);
1431 path __read_symlink(const path& p, error_code* ec = nullptr);
1433 bool __remove(const path& p, error_code* ec = nullptr);
1435 uintmax_t __remove_all(const path& p, error_code* ec = nullptr);
1437 void __rename(const path& from, const path& to, error_code* ec = nullptr);
1439 void __resize_file(const path& p, uintmax_t size, error_code* ec = nullptr);
1441 space_info __space(const path&, error_code* __ec = nullptr);
1443 file_status __status(const path&, error_code* __ec = nullptr);
1445 file_status __symlink_status(const path&, error_code* __ec = nullptr);
1447 path __system_complete(const path&, error_code* __ec = nullptr);
1449 path __temp_directory_path(error_code* __ec = nullptr);
1451 path __weakly_canonical(path const& __p, error_code* __ec = nullptr);
1453 inline _LIBCPP_INLINE_VISIBILITY path current_path() {
1454 return __current_path();
1457 inline _LIBCPP_INLINE_VISIBILITY path current_path(error_code& __ec) {
1458 return __current_path(&__ec);
1461 inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p) {
1462 __current_path(__p);
1465 inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p,
1466 error_code& __ec) noexcept {
1467 __current_path(__p, &__ec);
1470 inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p) {
1471 return __absolute(__p);
1474 inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p,
1476 return __absolute(__p, &__ec);
1479 inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p) {
1480 return __canonical(__p);
1483 inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p,
1485 return __canonical(__p, &__ec);
1488 inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from,
1490 __copy(__from, __to, copy_options::none);
1493 inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1495 __copy(__from, __to, copy_options::none, &__ec);
1498 inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1499 copy_options __opt) {
1500 __copy(__from, __to, __opt);
1503 inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1506 __copy(__from, __to, __opt, &__ec);
1509 inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
1511 return __copy_file(__from, __to, copy_options::none);
1514 inline _LIBCPP_INLINE_VISIBILITY bool
1515 copy_file(const path& __from, const path& __to, error_code& __ec) {
1516 return __copy_file(__from, __to, copy_options::none, &__ec);
1519 inline _LIBCPP_INLINE_VISIBILITY bool
1520 copy_file(const path& __from, const path& __to, copy_options __opt) {
1521 return __copy_file(__from, __to, __opt);
1524 inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
1528 return __copy_file(__from, __to, __opt, &__ec);
1531 inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __existing,
1532 const path& __new) {
1533 __copy_symlink(__existing, __new);
1536 inline _LIBCPP_INLINE_VISIBILITY void
1537 copy_symlink(const path& __ext, const path& __new, error_code& __ec) noexcept {
1538 __copy_symlink(__ext, __new, &__ec);
1541 inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p) {
1542 return __create_directories(__p);
1545 inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p,
1547 return __create_directories(__p, &__ec);
1550 inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p) {
1551 return __create_directory(__p);
1554 inline _LIBCPP_INLINE_VISIBILITY bool
1555 create_directory(const path& __p, error_code& __ec) noexcept {
1556 return __create_directory(__p, &__ec);
1559 inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p,
1560 const path& __attrs) {
1561 return __create_directory(__p, __attrs);
1564 inline _LIBCPP_INLINE_VISIBILITY bool
1565 create_directory(const path& __p, const path& __attrs,
1566 error_code& __ec) noexcept {
1567 return __create_directory(__p, __attrs, &__ec);
1570 inline _LIBCPP_INLINE_VISIBILITY void
1571 create_directory_symlink(const path& __to, const path& __new) {
1572 __create_directory_symlink(__to, __new);
1575 inline _LIBCPP_INLINE_VISIBILITY void
1576 create_directory_symlink(const path& __to, const path& __new,
1577 error_code& __ec) noexcept {
1578 __create_directory_symlink(__to, __new, &__ec);
1581 inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __to,
1582 const path& __new) {
1583 __create_hard_link(__to, __new);
1586 inline _LIBCPP_INLINE_VISIBILITY void
1587 create_hard_link(const path& __to, const path& __new,
1588 error_code& __ec) noexcept {
1589 __create_hard_link(__to, __new, &__ec);
1592 inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __to,
1593 const path& __new) {
1594 __create_symlink(__to, __new);
1597 inline _LIBCPP_INLINE_VISIBILITY void
1598 create_symlink(const path& __to, const path& __new, error_code& __ec) noexcept {
1599 return __create_symlink(__to, __new, &__ec);
1602 inline _LIBCPP_INLINE_VISIBILITY bool status_known(file_status __s) noexcept {
1603 return __s.type() != file_type::none;
1606 inline _LIBCPP_INLINE_VISIBILITY bool exists(file_status __s) noexcept {
1607 return status_known(__s) && __s.type() != file_type::not_found;
1610 inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p) {
1611 return exists(__status(__p));
1614 inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p,
1615 error_code& __ec) noexcept {
1616 auto __s = __status(__p, &__ec);
1617 if (status_known(__s))
1622 inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1,
1624 return __equivalent(__p1, __p2);
1627 inline _LIBCPP_INLINE_VISIBILITY bool
1628 equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept {
1629 return __equivalent(__p1, __p2, &__ec);
1632 inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p) {
1633 return __file_size(__p);
1636 inline _LIBCPP_INLINE_VISIBILITY uintmax_t
1637 file_size(const path& __p, error_code& __ec) noexcept {
1638 return __file_size(__p, &__ec);
1641 inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p) {
1642 return __hard_link_count(__p);
1645 inline _LIBCPP_INLINE_VISIBILITY uintmax_t
1646 hard_link_count(const path& __p, error_code& __ec) noexcept {
1647 return __hard_link_count(__p, &__ec);
1650 inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(file_status __s) noexcept {
1651 return __s.type() == file_type::block;
1654 inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p) {
1655 return is_block_file(__status(__p));
1658 inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p,
1659 error_code& __ec) noexcept {
1660 return is_block_file(__status(__p, &__ec));
1663 inline _LIBCPP_INLINE_VISIBILITY bool
1664 is_character_file(file_status __s) noexcept {
1665 return __s.type() == file_type::character;
1668 inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p) {
1669 return is_character_file(__status(__p));
1672 inline _LIBCPP_INLINE_VISIBILITY bool
1673 is_character_file(const path& __p, error_code& __ec) noexcept {
1674 return is_character_file(__status(__p, &__ec));
1677 inline _LIBCPP_INLINE_VISIBILITY bool is_directory(file_status __s) noexcept {
1678 return __s.type() == file_type::directory;
1681 inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p) {
1682 return is_directory(__status(__p));
1685 inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p,
1686 error_code& __ec) noexcept {
1687 return is_directory(__status(__p, &__ec));
1690 inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p) {
1691 return __fs_is_empty(__p);
1694 inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p,
1696 return __fs_is_empty(__p, &__ec);
1699 inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(file_status __s) noexcept {
1700 return __s.type() == file_type::fifo;
1702 inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p) {
1703 return is_fifo(__status(__p));
1706 inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p,
1707 error_code& __ec) noexcept {
1708 return is_fifo(__status(__p, &__ec));
1711 inline _LIBCPP_INLINE_VISIBILITY bool
1712 is_regular_file(file_status __s) noexcept {
1713 return __s.type() == file_type::regular;
1716 inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p) {
1717 return is_regular_file(__status(__p));
1720 inline _LIBCPP_INLINE_VISIBILITY bool
1721 is_regular_file(const path& __p, error_code& __ec) noexcept {
1722 return is_regular_file(__status(__p, &__ec));
1725 inline _LIBCPP_INLINE_VISIBILITY bool is_socket(file_status __s) noexcept {
1726 return __s.type() == file_type::socket;
1729 inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p) {
1730 return is_socket(__status(__p));
1733 inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p,
1734 error_code& __ec) noexcept {
1735 return is_socket(__status(__p, &__ec));
1738 inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(file_status __s) noexcept {
1739 return __s.type() == file_type::symlink;
1742 inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p) {
1743 return is_symlink(__symlink_status(__p));
1746 inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p,
1747 error_code& __ec) noexcept {
1748 return is_symlink(__symlink_status(__p, &__ec));
1751 inline _LIBCPP_INLINE_VISIBILITY bool is_other(file_status __s) noexcept {
1752 return exists(__s) && !is_regular_file(__s) && !is_directory(__s) &&
1756 inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p) {
1757 return is_other(__status(__p));
1760 inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p,
1761 error_code& __ec) noexcept {
1762 return is_other(__status(__p, &__ec));
1765 inline _LIBCPP_INLINE_VISIBILITY file_time_type
1766 last_write_time(const path& __p) {
1767 return __last_write_time(__p);
1770 inline _LIBCPP_INLINE_VISIBILITY file_time_type
1771 last_write_time(const path& __p, error_code& __ec) noexcept {
1772 return __last_write_time(__p, &__ec);
1775 inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p,
1776 file_time_type __t) {
1777 __last_write_time(__p, __t);
1780 inline _LIBCPP_INLINE_VISIBILITY void
1781 last_write_time(const path& __p, file_time_type __t,
1782 error_code& __ec) noexcept {
1783 __last_write_time(__p, __t, &__ec);
1786 inline _LIBCPP_INLINE_VISIBILITY void
1787 permissions(const path& __p, perms __prms,
1788 perm_options __opts = perm_options::replace) {
1789 __permissions(__p, __prms, __opts);
1792 inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms,
1793 error_code& __ec) noexcept {
1794 __permissions(__p, __prms, perm_options::replace, &__ec);
1797 inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms,
1798 perm_options __opts,
1800 __permissions(__p, __prms, __opts, &__ec);
1803 inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p,
1806 path __tmp = __weakly_canonical(__p, &__ec);
1809 path __tmp_base = __weakly_canonical(__base, &__ec);
1812 return __tmp.lexically_proximate(__tmp_base);
1815 inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p,
1817 return proximate(__p, current_path(), __ec);
1820 inline _LIBCPP_INLINE_VISIBILITY path
1821 proximate(const path& __p, const path& __base = current_path()) {
1822 return __weakly_canonical(__p).lexically_proximate(
1823 __weakly_canonical(__base));
1826 inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p) {
1827 return __read_symlink(__p);
1830 inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p,
1832 return __read_symlink(__p, &__ec);
1835 inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p,
1838 path __tmp = __weakly_canonical(__p, &__ec);
1841 path __tmpbase = __weakly_canonical(__base, &__ec);
1844 return __tmp.lexically_relative(__tmpbase);
1847 inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p,
1849 return relative(__p, current_path(), __ec);
1852 inline _LIBCPP_INLINE_VISIBILITY path
1853 relative(const path& __p, const path& __base = current_path()) {
1854 return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base));
1857 inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p) {
1858 return __remove(__p);
1861 inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p,
1862 error_code& __ec) noexcept {
1863 return __remove(__p, &__ec);
1866 inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p) {
1867 return __remove_all(__p);
1870 inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p,
1872 return __remove_all(__p, &__ec);
1875 inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from,
1877 return __rename(__from, __to);
1880 inline _LIBCPP_INLINE_VISIBILITY void
1881 rename(const path& __from, const path& __to, error_code& __ec) noexcept {
1882 return __rename(__from, __to, &__ec);
1885 inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p,
1887 return __resize_file(__p, __ns);
1890 inline _LIBCPP_INLINE_VISIBILITY void
1891 resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept {
1892 return __resize_file(__p, __ns, &__ec);
1895 inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p) {
1896 return __space(__p);
1899 inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p,
1900 error_code& __ec) noexcept {
1901 return __space(__p, &__ec);
1904 inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p) {
1905 return __status(__p);
1908 inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p,
1909 error_code& __ec) noexcept {
1910 return __status(__p, &__ec);
1913 inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p) {
1914 return __symlink_status(__p);
1917 inline _LIBCPP_INLINE_VISIBILITY file_status
1918 symlink_status(const path& __p, error_code& __ec) noexcept {
1919 return __symlink_status(__p, &__ec);
1922 inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path() {
1923 return __temp_directory_path();
1926 inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path(error_code& __ec) {
1927 return __temp_directory_path(&__ec);
1930 inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p) {
1931 return __weakly_canonical(__p);
1934 inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p,
1936 return __weakly_canonical(__p, &__ec);
1939 class directory_iterator;
1940 class recursive_directory_iterator;
1943 class directory_entry {
1944 typedef _VSTD_FS::path _Path;
1947 // constructors and destructors
1948 directory_entry() noexcept = default;
1949 directory_entry(directory_entry const&) = default;
1950 directory_entry(directory_entry&&) noexcept = default;
1952 _LIBCPP_INLINE_VISIBILITY
1953 explicit directory_entry(_Path const& __p) : __p_(__p) {
1958 _LIBCPP_INLINE_VISIBILITY
1959 directory_entry(_Path const& __p, error_code& __ec) : __p_(__p) {
1963 ~directory_entry() {}
1965 directory_entry& operator=(directory_entry const&) = default;
1966 directory_entry& operator=(directory_entry&&) noexcept = default;
1968 _LIBCPP_INLINE_VISIBILITY
1969 void assign(_Path const& __p) {
1975 _LIBCPP_INLINE_VISIBILITY
1976 void assign(_Path const& __p, error_code& __ec) {
1981 _LIBCPP_INLINE_VISIBILITY
1982 void replace_filename(_Path const& __p) {
1983 __p_.replace_filename(__p);
1988 _LIBCPP_INLINE_VISIBILITY
1989 void replace_filename(_Path const& __p, error_code& __ec) {
1990 __p_ = __p_.parent_path() / __p;
1994 _LIBCPP_INLINE_VISIBILITY
1995 void refresh() { __refresh(); }
1997 _LIBCPP_INLINE_VISIBILITY
1998 void refresh(error_code& __ec) noexcept { __refresh(&__ec); }
2000 _LIBCPP_INLINE_VISIBILITY
2001 _Path const& path() const noexcept { return __p_; }
2003 _LIBCPP_INLINE_VISIBILITY
2004 operator const _Path&() const noexcept { return __p_; }
2006 _LIBCPP_INLINE_VISIBILITY
2007 bool exists() const { return _VSTD_FS::exists(file_status{__get_ft()}); }
2009 _LIBCPP_INLINE_VISIBILITY
2010 bool exists(error_code& __ec) const noexcept {
2011 return _VSTD_FS::exists(file_status{__get_ft(&__ec)});
2014 _LIBCPP_INLINE_VISIBILITY
2015 bool is_block_file() const { return __get_ft() == file_type::block; }
2017 _LIBCPP_INLINE_VISIBILITY
2018 bool is_block_file(error_code& __ec) const noexcept {
2019 return __get_ft(&__ec) == file_type::block;
2022 _LIBCPP_INLINE_VISIBILITY
2023 bool is_character_file() const { return __get_ft() == file_type::character; }
2025 _LIBCPP_INLINE_VISIBILITY
2026 bool is_character_file(error_code& __ec) const noexcept {
2027 return __get_ft(&__ec) == file_type::character;
2030 _LIBCPP_INLINE_VISIBILITY
2031 bool is_directory() const { return __get_ft() == file_type::directory; }
2033 _LIBCPP_INLINE_VISIBILITY
2034 bool is_directory(error_code& __ec) const noexcept {
2035 return __get_ft(&__ec) == file_type::directory;
2038 _LIBCPP_INLINE_VISIBILITY
2039 bool is_fifo() const { return __get_ft() == file_type::fifo; }
2041 _LIBCPP_INLINE_VISIBILITY
2042 bool is_fifo(error_code& __ec) const noexcept {
2043 return __get_ft(&__ec) == file_type::fifo;
2046 _LIBCPP_INLINE_VISIBILITY
2047 bool is_other() const { return _VSTD_FS::is_other(file_status{__get_ft()}); }
2049 _LIBCPP_INLINE_VISIBILITY
2050 bool is_other(error_code& __ec) const noexcept {
2051 return _VSTD_FS::is_other(file_status{__get_ft(&__ec)});
2054 _LIBCPP_INLINE_VISIBILITY
2055 bool is_regular_file() const { return __get_ft() == file_type::regular; }
2057 _LIBCPP_INLINE_VISIBILITY
2058 bool is_regular_file(error_code& __ec) const noexcept {
2059 return __get_ft(&__ec) == file_type::regular;
2062 _LIBCPP_INLINE_VISIBILITY
2063 bool is_socket() const { return __get_ft() == file_type::socket; }
2065 _LIBCPP_INLINE_VISIBILITY
2066 bool is_socket(error_code& __ec) const noexcept {
2067 return __get_ft(&__ec) == file_type::socket;
2070 _LIBCPP_INLINE_VISIBILITY
2071 bool is_symlink() const { return __get_sym_ft() == file_type::symlink; }
2073 _LIBCPP_INLINE_VISIBILITY
2074 bool is_symlink(error_code& __ec) const noexcept {
2075 return __get_sym_ft(&__ec) == file_type::symlink;
2077 _LIBCPP_INLINE_VISIBILITY
2078 uintmax_t file_size() const { return __get_size(); }
2080 _LIBCPP_INLINE_VISIBILITY
2081 uintmax_t file_size(error_code& __ec) const noexcept {
2082 return __get_size(&__ec);
2085 _LIBCPP_INLINE_VISIBILITY
2086 uintmax_t hard_link_count() const { return __get_nlink(); }
2088 _LIBCPP_INLINE_VISIBILITY
2089 uintmax_t hard_link_count(error_code& __ec) const noexcept {
2090 return __get_nlink(&__ec);
2093 _LIBCPP_INLINE_VISIBILITY
2094 file_time_type last_write_time() const { return __get_write_time(); }
2096 _LIBCPP_INLINE_VISIBILITY
2097 file_time_type last_write_time(error_code& __ec) const noexcept {
2098 return __get_write_time(&__ec);
2101 _LIBCPP_INLINE_VISIBILITY
2102 file_status status() const { return __get_status(); }
2104 _LIBCPP_INLINE_VISIBILITY
2105 file_status status(error_code& __ec) const noexcept {
2106 return __get_status(&__ec);
2109 _LIBCPP_INLINE_VISIBILITY
2110 file_status symlink_status() const { return __get_symlink_status(); }
2112 _LIBCPP_INLINE_VISIBILITY
2113 file_status symlink_status(error_code& __ec) const noexcept {
2114 return __get_symlink_status(&__ec);
2117 _LIBCPP_INLINE_VISIBILITY
2118 bool operator<(directory_entry const& __rhs) const noexcept {
2119 return __p_ < __rhs.__p_;
2122 _LIBCPP_INLINE_VISIBILITY
2123 bool operator==(directory_entry const& __rhs) const noexcept {
2124 return __p_ == __rhs.__p_;
2127 _LIBCPP_INLINE_VISIBILITY
2128 bool operator!=(directory_entry const& __rhs) const noexcept {
2129 return __p_ != __rhs.__p_;
2132 _LIBCPP_INLINE_VISIBILITY
2133 bool operator<=(directory_entry const& __rhs) const noexcept {
2134 return __p_ <= __rhs.__p_;
2137 _LIBCPP_INLINE_VISIBILITY
2138 bool operator>(directory_entry const& __rhs) const noexcept {
2139 return __p_ > __rhs.__p_;
2142 _LIBCPP_INLINE_VISIBILITY
2143 bool operator>=(directory_entry const& __rhs) const noexcept {
2144 return __p_ >= __rhs.__p_;
2148 friend class directory_iterator;
2149 friend class recursive_directory_iterator;
2150 friend class __dir_stream;
2152 enum _CacheType : unsigned char {
2157 _RefreshSymlinkUnresolved,
2161 struct __cached_data {
2164 file_time_type __write_time_;
2166 perms __non_sym_perms_;
2168 _CacheType __cache_type_;
2170 _LIBCPP_INLINE_VISIBILITY
2171 __cached_data() noexcept { __reset(); }
2173 _LIBCPP_INLINE_VISIBILITY
2175 __cache_type_ = _Empty;
2176 __type_ = file_type::none;
2177 __sym_perms_ = __non_sym_perms_ = perms::unknown;
2178 __size_ = __nlink_ = uintmax_t(-1);
2179 __write_time_ = file_time_type::min();
2183 _LIBCPP_INLINE_VISIBILITY
2184 static __cached_data __create_iter_result(file_type __ft) {
2185 __cached_data __data;
2186 __data.__type_ = __ft;
2187 __data.__cache_type_ = [&]() {
2189 case file_type::none:
2191 case file_type::symlink:
2192 return _IterSymlink;
2194 return _IterNonSymlink;
2200 _LIBCPP_INLINE_VISIBILITY
2201 void __assign_iter_entry(_Path&& __p, __cached_data __dt) {
2202 __p_ = std::move(__p);
2207 error_code __do_refresh() noexcept;
2209 _LIBCPP_INLINE_VISIBILITY
2210 static bool __is_dne_error(error_code const& __ec) {
2213 switch (static_cast<errc>(__ec.value())) {
2214 case errc::no_such_file_or_directory:
2215 case errc::not_a_directory:
2222 _LIBCPP_INLINE_VISIBILITY
2223 void __handle_error(const char* __msg, error_code* __dest_ec,
2224 error_code const& __ec, bool __allow_dne = false) const {
2229 if (__ec && (!__allow_dne || !__is_dne_error(__ec)))
2230 __throw_filesystem_error(__msg, __p_, __ec);
2233 _LIBCPP_INLINE_VISIBILITY
2234 void __refresh(error_code* __ec = nullptr) {
2235 __handle_error("in directory_entry::refresh", __ec, __do_refresh(),
2236 /*allow_dne*/ true);
2239 _LIBCPP_INLINE_VISIBILITY
2240 file_type __get_sym_ft(error_code* __ec = nullptr) const {
2241 switch (__data_.__cache_type_) {
2243 return __symlink_status(__p_, __ec).type();
2245 case _RefreshSymlink:
2246 case _RefreshSymlinkUnresolved:
2249 return file_type::symlink;
2250 case _IterNonSymlink:
2251 case _RefreshNonSymlink:
2252 file_status __st(__data_.__type_);
2253 if (__ec && !_VSTD_FS::exists(__st))
2254 *__ec = make_error_code(errc::no_such_file_or_directory);
2257 return __data_.__type_;
2259 _LIBCPP_UNREACHABLE();
2262 _LIBCPP_INLINE_VISIBILITY
2263 file_type __get_ft(error_code* __ec = nullptr) const {
2264 switch (__data_.__cache_type_) {
2267 case _RefreshSymlinkUnresolved:
2268 return __status(__p_, __ec).type();
2269 case _IterNonSymlink:
2270 case _RefreshNonSymlink:
2271 case _RefreshSymlink: {
2272 file_status __st(__data_.__type_);
2273 if (__ec && !_VSTD_FS::exists(__st))
2274 *__ec = make_error_code(errc::no_such_file_or_directory);
2277 return __data_.__type_;
2280 _LIBCPP_UNREACHABLE();
2283 _LIBCPP_INLINE_VISIBILITY
2284 file_status __get_status(error_code* __ec = nullptr) const {
2285 switch (__data_.__cache_type_) {
2287 case _IterNonSymlink:
2289 case _RefreshSymlinkUnresolved:
2290 return __status(__p_, __ec);
2291 case _RefreshNonSymlink:
2292 case _RefreshSymlink:
2293 return file_status(__get_ft(__ec), __data_.__non_sym_perms_);
2295 _LIBCPP_UNREACHABLE();
2298 _LIBCPP_INLINE_VISIBILITY
2299 file_status __get_symlink_status(error_code* __ec = nullptr) const {
2300 switch (__data_.__cache_type_) {
2302 case _IterNonSymlink:
2304 return __symlink_status(__p_, __ec);
2305 case _RefreshNonSymlink:
2306 return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_);
2307 case _RefreshSymlink:
2308 case _RefreshSymlinkUnresolved:
2309 return file_status(__get_sym_ft(__ec), __data_.__sym_perms_);
2311 _LIBCPP_UNREACHABLE();
2314 _LIBCPP_INLINE_VISIBILITY
2315 uintmax_t __get_size(error_code* __ec = nullptr) const {
2316 switch (__data_.__cache_type_) {
2318 case _IterNonSymlink:
2320 case _RefreshSymlinkUnresolved:
2321 return _VSTD_FS::__file_size(__p_, __ec);
2322 case _RefreshSymlink:
2323 case _RefreshNonSymlink: {
2325 file_status __st(__get_ft(&__m_ec));
2326 __handle_error("in directory_entry::file_size", __ec, __m_ec);
2327 if (_VSTD_FS::exists(__st) && !_VSTD_FS::is_regular_file(__st)) {
2328 errc __err_kind = _VSTD_FS::is_directory(__st) ? errc::is_a_directory
2329 : errc::not_supported;
2330 __handle_error("in directory_entry::file_size", __ec,
2331 make_error_code(__err_kind));
2333 return __data_.__size_;
2336 _LIBCPP_UNREACHABLE();
2339 _LIBCPP_INLINE_VISIBILITY
2340 uintmax_t __get_nlink(error_code* __ec = nullptr) const {
2341 switch (__data_.__cache_type_) {
2343 case _IterNonSymlink:
2345 case _RefreshSymlinkUnresolved:
2346 return _VSTD_FS::__hard_link_count(__p_, __ec);
2347 case _RefreshSymlink:
2348 case _RefreshNonSymlink: {
2350 (void)__get_ft(&__m_ec);
2351 __handle_error("in directory_entry::hard_link_count", __ec, __m_ec);
2352 return __data_.__nlink_;
2355 _LIBCPP_UNREACHABLE();
2358 _LIBCPP_INLINE_VISIBILITY
2359 file_time_type __get_write_time(error_code* __ec = nullptr) const {
2360 switch (__data_.__cache_type_) {
2362 case _IterNonSymlink:
2364 case _RefreshSymlinkUnresolved:
2365 return _VSTD_FS::__last_write_time(__p_, __ec);
2366 case _RefreshSymlink:
2367 case _RefreshNonSymlink: {
2369 file_status __st(__get_ft(&__m_ec));
2370 __handle_error("in directory_entry::last_write_time", __ec, __m_ec);
2371 if (_VSTD_FS::exists(__st) &&
2372 __data_.__write_time_ == file_time_type::min())
2373 __handle_error("in directory_entry::last_write_time", __ec,
2374 make_error_code(errc::value_too_large));
2375 return __data_.__write_time_;
2378 _LIBCPP_UNREACHABLE();
2383 __cached_data __data_;
2386 class __dir_element_proxy {
2388 inline _LIBCPP_INLINE_VISIBILITY directory_entry operator*() {
2389 return _VSTD::move(__elem_);
2393 friend class directory_iterator;
2394 friend class recursive_directory_iterator;
2395 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
2396 __dir_element_proxy(__dir_element_proxy&& __o)
2397 : __elem_(_VSTD::move(__o.__elem_)) {}
2398 directory_entry __elem_;
2401 class directory_iterator {
2403 typedef directory_entry value_type;
2404 typedef ptrdiff_t difference_type;
2405 typedef value_type const* pointer;
2406 typedef value_type const& reference;
2407 typedef input_iterator_tag iterator_category;
2411 directory_iterator() noexcept {}
2413 explicit directory_iterator(const path& __p)
2414 : directory_iterator(__p, nullptr) {}
2416 directory_iterator(const path& __p, directory_options __opts)
2417 : directory_iterator(__p, nullptr, __opts) {}
2419 directory_iterator(const path& __p, error_code& __ec)
2420 : directory_iterator(__p, &__ec) {}
2422 directory_iterator(const path& __p, directory_options __opts,
2424 : directory_iterator(__p, &__ec, __opts) {}
2426 directory_iterator(const directory_iterator&) = default;
2427 directory_iterator(directory_iterator&&) = default;
2428 directory_iterator& operator=(const directory_iterator&) = default;
2430 directory_iterator& operator=(directory_iterator&& __o) noexcept {
2431 // non-default implementation provided to support self-move assign.
2433 __imp_ = _VSTD::move(__o.__imp_);
2438 ~directory_iterator() = default;
2440 const directory_entry& operator*() const {
2441 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
2442 return __dereference();
2445 const directory_entry* operator->() const { return &**this; }
2447 directory_iterator& operator++() { return __increment(); }
2449 __dir_element_proxy operator++(int) {
2450 __dir_element_proxy __p(**this);
2455 directory_iterator& increment(error_code& __ec) { return __increment(&__ec); }
2458 inline _LIBCPP_INLINE_VISIBILITY friend bool
2459 operator==(const directory_iterator& __lhs,
2460 const directory_iterator& __rhs) noexcept;
2462 // construct the dir_stream
2464 directory_iterator(const path&, error_code*,
2465 directory_options = directory_options::none);
2468 directory_iterator& __increment(error_code* __ec = nullptr);
2471 const directory_entry& __dereference() const;
2474 shared_ptr<__dir_stream> __imp_;
2477 inline _LIBCPP_INLINE_VISIBILITY bool
2478 operator==(const directory_iterator& __lhs,
2479 const directory_iterator& __rhs) noexcept {
2480 return __lhs.__imp_ == __rhs.__imp_;
2483 inline _LIBCPP_INLINE_VISIBILITY bool
2484 operator!=(const directory_iterator& __lhs,
2485 const directory_iterator& __rhs) noexcept {
2486 return !(__lhs == __rhs);
2489 // enable directory_iterator range-based for statements
2490 inline _LIBCPP_INLINE_VISIBILITY directory_iterator
2491 begin(directory_iterator __iter) noexcept {
2495 inline _LIBCPP_INLINE_VISIBILITY directory_iterator
2496 end(const directory_iterator&) noexcept {
2497 return directory_iterator();
2500 class recursive_directory_iterator {
2502 using value_type = directory_entry;
2503 using difference_type = std::ptrdiff_t;
2504 using pointer = directory_entry const*;
2505 using reference = directory_entry const&;
2506 using iterator_category = std::input_iterator_tag;
2509 // constructors and destructor
2510 _LIBCPP_INLINE_VISIBILITY
2511 recursive_directory_iterator() noexcept : __rec_(false) {}
2513 _LIBCPP_INLINE_VISIBILITY
2514 explicit recursive_directory_iterator(
2515 const path& __p, directory_options __xoptions = directory_options::none)
2516 : recursive_directory_iterator(__p, __xoptions, nullptr) {}
2518 _LIBCPP_INLINE_VISIBILITY
2519 recursive_directory_iterator(const path& __p, directory_options __xoptions,
2521 : recursive_directory_iterator(__p, __xoptions, &__ec) {}
2523 _LIBCPP_INLINE_VISIBILITY
2524 recursive_directory_iterator(const path& __p, error_code& __ec)
2525 : recursive_directory_iterator(__p, directory_options::none, &__ec) {}
2527 recursive_directory_iterator(const recursive_directory_iterator&) = default;
2528 recursive_directory_iterator(recursive_directory_iterator&&) = default;
2530 recursive_directory_iterator&
2531 operator=(const recursive_directory_iterator&) = default;
2533 _LIBCPP_INLINE_VISIBILITY
2534 recursive_directory_iterator&
2535 operator=(recursive_directory_iterator&& __o) noexcept {
2536 // non-default implementation provided to support self-move assign.
2538 __imp_ = _VSTD::move(__o.__imp_);
2539 __rec_ = __o.__rec_;
2544 ~recursive_directory_iterator() = default;
2546 _LIBCPP_INLINE_VISIBILITY
2547 const directory_entry& operator*() const { return __dereference(); }
2549 _LIBCPP_INLINE_VISIBILITY
2550 const directory_entry* operator->() const { return &__dereference(); }
2552 recursive_directory_iterator& operator++() { return __increment(); }
2554 _LIBCPP_INLINE_VISIBILITY
2555 __dir_element_proxy operator++(int) {
2556 __dir_element_proxy __p(**this);
2561 _LIBCPP_INLINE_VISIBILITY
2562 recursive_directory_iterator& increment(error_code& __ec) {
2563 return __increment(&__ec);
2566 _LIBCPP_FUNC_VIS directory_options options() const;
2567 _LIBCPP_FUNC_VIS int depth() const;
2569 _LIBCPP_INLINE_VISIBILITY
2570 void pop() { __pop(); }
2572 _LIBCPP_INLINE_VISIBILITY
2573 void pop(error_code& __ec) { __pop(&__ec); }
2575 _LIBCPP_INLINE_VISIBILITY
2576 bool recursion_pending() const { return __rec_; }
2578 _LIBCPP_INLINE_VISIBILITY
2579 void disable_recursion_pending() { __rec_ = false; }
2582 recursive_directory_iterator(const path& __p, directory_options __opt,
2586 const directory_entry& __dereference() const;
2589 bool __try_recursion(error_code* __ec);
2592 void __advance(error_code* __ec = nullptr);
2595 recursive_directory_iterator& __increment(error_code* __ec = nullptr);
2598 void __pop(error_code* __ec = nullptr);
2600 inline _LIBCPP_INLINE_VISIBILITY friend bool
2601 operator==(const recursive_directory_iterator&,
2602 const recursive_directory_iterator&) noexcept;
2604 struct __shared_imp;
2605 shared_ptr<__shared_imp> __imp_;
2607 }; // class recursive_directory_iterator
2609 inline _LIBCPP_INLINE_VISIBILITY bool
2610 operator==(const recursive_directory_iterator& __lhs,
2611 const recursive_directory_iterator& __rhs) noexcept {
2612 return __lhs.__imp_ == __rhs.__imp_;
2615 _LIBCPP_INLINE_VISIBILITY
2616 inline bool operator!=(const recursive_directory_iterator& __lhs,
2617 const recursive_directory_iterator& __rhs) noexcept {
2618 return !(__lhs == __rhs);
2620 // enable recursive_directory_iterator range-based for statements
2621 inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
2622 begin(recursive_directory_iterator __iter) noexcept {
2626 inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
2627 end(const recursive_directory_iterator&) noexcept {
2628 return recursive_directory_iterator();
2631 _LIBCPP_END_NAMESPACE_FILESYSTEM
2633 #endif // !_LIBCPP_CXX03_LANG
2637 #endif // _LIBCPP_FILESYSTEM