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