blob: 47cc0c5aa70f284268d4c63e8e3ff0e0333cef95 [file] [log] [blame]
Eric Fiselier6e9a6942016-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 Fiselier0b47a652018-02-04 03:10:53 +000031 // fs.path.io operators are friends of path.
Eric Fiselier6e9a6942016-06-17 19:46:40 +000032 template <class charT, class traits>
Eric Fiselier0b47a652018-02-04 03:10:53 +000033 friend basic_ostream<charT, traits>&
Eric Fiselier6e9a6942016-06-17 19:46:40 +000034 operator<<(basic_ostream<charT, traits>& os, const path& p);
35
36 template <class charT, class traits>
Eric Fiselier0b47a652018-02-04 03:10:53 +000037 friend basic_istream<charT, traits>&
Eric Fiselier6e9a6942016-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 Fiselierf2c93732018-03-26 06:23:55 +000071 enum class perm_options;
Eric Fiselier6e9a6942016-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
79 path absolute(const path& p, const path& base=current_path());
80
81 path canonical(const path& p, const path& base = current_path());
82 path canonical(const path& p, error_code& ec);
83 path canonical(const path& p, const path& base, error_code& ec);
84
85 void copy(const path& from, const path& to);
Eric Fiseliera4c272d2017-10-30 18:59:59 +000086 void copy(const path& from, const path& to, error_code& ec);
Eric Fiselier6e9a6942016-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 Fiseliera4c272d2017-10-30 18:59:59 +000089 error_code& ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +000090
91 bool copy_file(const path& from, const path& to);
Eric Fiselier4d0f4282018-02-04 07:35:36 +000092 bool copy_file(const path& from, const path& to, error_code& ec);
Eric Fiselier6e9a6942016-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 Fiselier4d0f4282018-02-04 07:35:36 +000095 error_code& ec);
Eric Fiselier6e9a6942016-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 Fiselier4d0f4282018-02-04 07:35:36 +0000102 bool create_directories(const path& p, error_code& ec);
Eric Fiselier6e9a6942016-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 Fiselierf2c93732018-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 Fiselier6e9a6942016-06-17 19:46:40 +0000187
188 path read_symlink(const path& p);
189 path read_symlink(const path& p, error_code& ec);
190
191 bool remove(const path& p);
192 bool remove(const path& p, error_code& ec) _NOEXCEPT;
193
194 uintmax_t remove_all(const path& p);
Eric Fiselier4d0f4282018-02-04 07:35:36 +0000195 uintmax_t remove_all(const path& p, error_code& ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000196
197 void rename(const path& from, const path& to);
198 void rename(const path& from, const path& to, error_code& ec) _NOEXCEPT;
199
200 void resize_file(const path& p, uintmax_t size);
201 void resize_file(const path& p, uintmax_t size, error_code& ec) _NOEXCEPT;
202
203 space_info space(const path& p);
204 space_info space(const path& p, error_code& ec) _NOEXCEPT;
205
206 file_status status(const path& p);
207 file_status status(const path& p, error_code& ec) _NOEXCEPT;
208
209 bool status_known(file_status s) _NOEXCEPT;
210
211 file_status symlink_status(const path& p);
212 file_status symlink_status(const path& p, error_code& ec) _NOEXCEPT;
213
214 path system_complete(const path& p);
215 path system_complete(const path& p, error_code& ec);
216
217 path temp_directory_path();
218 path temp_directory_path(error_code& ec);
219
220} } } } // namespaces std::experimental::filesystem::v1
221
222*/
223
224#include <experimental/__config>
225#include <cstddef>
226#include <chrono>
227#include <iterator>
228#include <iosfwd>
229#include <locale>
230#include <memory>
231#include <stack>
232#include <string>
233#include <system_error>
234#include <utility>
235#include <iomanip> // for quoted
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000236#include <string_view>
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000237
238#include <__debug>
239
240#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
241#pragma GCC system_header
242#endif
243
244#define __cpp_lib_experimental_filesystem 201406
245
246_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM
247
248typedef chrono::time_point<std::chrono::system_clock> file_time_type;
249
250struct _LIBCPP_TYPE_VIS space_info
251{
252 uintmax_t capacity;
253 uintmax_t free;
254 uintmax_t available;
255};
256
Eric Fiselier833d6442016-09-15 22:27:07 +0000257enum class _LIBCPP_ENUM_VIS file_type : signed char
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000258{
259 none = 0,
260 not_found = -1,
261 regular = 1,
262 directory = 2,
263 symlink = 3,
264 block = 4,
265 character = 5,
266 fifo = 6,
267 socket = 7,
268 unknown = 8
269};
270
Eric Fiselier833d6442016-09-15 22:27:07 +0000271enum class _LIBCPP_ENUM_VIS perms : unsigned
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000272{
273 none = 0,
274
275 owner_read = 0400,
276 owner_write = 0200,
277 owner_exec = 0100,
278 owner_all = 0700,
279
280 group_read = 040,
281 group_write = 020,
282 group_exec = 010,
283 group_all = 070,
284
285 others_read = 04,
286 others_write = 02,
287 others_exec = 01,
288 others_all = 07,
289
290 all = 0777,
291
292 set_uid = 04000,
293 set_gid = 02000,
294 sticky_bit = 01000,
295 mask = 07777,
296 unknown = 0xFFFF,
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000297};
298
299_LIBCPP_INLINE_VISIBILITY
300inline _LIBCPP_CONSTEXPR perms operator&(perms _LHS, perms _RHS)
301{ return static_cast<perms>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); }
302
303_LIBCPP_INLINE_VISIBILITY
304inline _LIBCPP_CONSTEXPR perms operator|(perms _LHS, perms _RHS)
305{ return static_cast<perms>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); }
306
307_LIBCPP_INLINE_VISIBILITY
308inline _LIBCPP_CONSTEXPR perms operator^(perms _LHS, perms _RHS)
309{ return static_cast<perms>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); }
310
311_LIBCPP_INLINE_VISIBILITY
312inline _LIBCPP_CONSTEXPR perms operator~(perms _LHS)
313{ return static_cast<perms>(~static_cast<unsigned>(_LHS)); }
314
315_LIBCPP_INLINE_VISIBILITY
316inline perms& operator&=(perms& _LHS, perms _RHS)
317{ return _LHS = _LHS & _RHS; }
318
319_LIBCPP_INLINE_VISIBILITY
320inline perms& operator|=(perms& _LHS, perms _RHS)
321{ return _LHS = _LHS | _RHS; }
322
323_LIBCPP_INLINE_VISIBILITY
324inline perms& operator^=(perms& _LHS, perms _RHS)
325{ return _LHS = _LHS ^ _RHS; }
326
Eric Fiselierf2c93732018-03-26 06:23:55 +0000327enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
328 replace = 1,
329 add = 2,
330 remove = 4,
331 nofollow = 8
332};
333
334_LIBCPP_INLINE_VISIBILITY
335inline _LIBCPP_CONSTEXPR perm_options operator&(perm_options _LHS, perm_options _RHS)
336{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); }
337
338_LIBCPP_INLINE_VISIBILITY
339inline _LIBCPP_CONSTEXPR perm_options operator|(perm_options _LHS, perm_options _RHS)
340{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); }
341
342_LIBCPP_INLINE_VISIBILITY
343inline _LIBCPP_CONSTEXPR perm_options operator^(perm_options _LHS, perm_options _RHS)
344{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); }
345
346_LIBCPP_INLINE_VISIBILITY
347inline _LIBCPP_CONSTEXPR perm_options operator~(perm_options _LHS)
348{ return static_cast<perm_options>(~static_cast<unsigned>(_LHS)); }
349
350_LIBCPP_INLINE_VISIBILITY
351inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS)
352{ return _LHS = _LHS & _RHS; }
353
354_LIBCPP_INLINE_VISIBILITY
355inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS)
356{ return _LHS = _LHS | _RHS; }
357
358_LIBCPP_INLINE_VISIBILITY
359inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS)
360{ return _LHS = _LHS ^ _RHS; }
361
Eric Fiselier833d6442016-09-15 22:27:07 +0000362enum class _LIBCPP_ENUM_VIS copy_options : unsigned short
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000363{
364 none = 0,
365 skip_existing = 1,
366 overwrite_existing = 2,
367 update_existing = 4,
368 recursive = 8,
369 copy_symlinks = 16,
370 skip_symlinks = 32,
371 directories_only = 64,
372 create_symlinks = 128,
373 create_hard_links = 256,
374 __in_recursive_copy = 512,
375};
376
377_LIBCPP_INLINE_VISIBILITY
378inline _LIBCPP_CONSTEXPR copy_options operator&(copy_options _LHS, copy_options _RHS)
379{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) & static_cast<unsigned short>(_RHS)); }
380
381_LIBCPP_INLINE_VISIBILITY
382inline _LIBCPP_CONSTEXPR copy_options operator|(copy_options _LHS, copy_options _RHS)
383{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) | static_cast<unsigned short>(_RHS)); }
384
385_LIBCPP_INLINE_VISIBILITY
386inline _LIBCPP_CONSTEXPR copy_options operator^(copy_options _LHS, copy_options _RHS)
387{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^ static_cast<unsigned short>(_RHS)); }
388
389_LIBCPP_INLINE_VISIBILITY
390inline _LIBCPP_CONSTEXPR copy_options operator~(copy_options _LHS)
391{ return static_cast<copy_options>(~static_cast<unsigned short>(_LHS)); }
392
393_LIBCPP_INLINE_VISIBILITY
394inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS)
395{ return _LHS = _LHS & _RHS; }
396
397_LIBCPP_INLINE_VISIBILITY
398inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS)
399{ return _LHS = _LHS | _RHS; }
400
401_LIBCPP_INLINE_VISIBILITY
402inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS)
403{ return _LHS = _LHS ^ _RHS; }
404
405
Eric Fiselier833d6442016-09-15 22:27:07 +0000406enum class _LIBCPP_ENUM_VIS directory_options : unsigned char
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000407{
408 none = 0,
409 follow_directory_symlink = 1,
410 skip_permission_denied = 2
411};
412
413_LIBCPP_INLINE_VISIBILITY
414inline _LIBCPP_CONSTEXPR directory_options operator&(directory_options _LHS, directory_options _RHS)
415{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) & static_cast<unsigned char>(_RHS)); }
416
417_LIBCPP_INLINE_VISIBILITY
418inline _LIBCPP_CONSTEXPR directory_options operator|(directory_options _LHS, directory_options _RHS)
419{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) | static_cast<unsigned char>(_RHS)); }
420
421_LIBCPP_INLINE_VISIBILITY
422inline _LIBCPP_CONSTEXPR directory_options operator^(directory_options _LHS, directory_options _RHS)
423{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^ static_cast<unsigned char>(_RHS)); }
424
425_LIBCPP_INLINE_VISIBILITY
426inline _LIBCPP_CONSTEXPR directory_options operator~(directory_options _LHS)
427{ return static_cast<directory_options>(~static_cast<unsigned char>(_LHS)); }
428
429_LIBCPP_INLINE_VISIBILITY
430inline directory_options& operator&=(directory_options& _LHS, directory_options _RHS)
431{ return _LHS = _LHS & _RHS; }
432
433_LIBCPP_INLINE_VISIBILITY
434inline directory_options& operator|=(directory_options& _LHS, directory_options _RHS)
435{ return _LHS = _LHS | _RHS; }
436
437_LIBCPP_INLINE_VISIBILITY
438inline directory_options& operator^=(directory_options& _LHS, directory_options _RHS)
439{ return _LHS = _LHS ^ _RHS; }
440
441
442class _LIBCPP_TYPE_VIS file_status
443{
444public:
445 // constructors
446 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier7c7df642017-03-06 21:02:06 +0000447 file_status() _NOEXCEPT : file_status(file_type::none) {}
448 _LIBCPP_INLINE_VISIBILITY
449 explicit file_status(file_type __ft,
450 perms __prms = perms::unknown) _NOEXCEPT
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000451 : __ft_(__ft), __prms_(__prms)
452 {}
453
454 file_status(const file_status&) _NOEXCEPT = default;
455 file_status(file_status&&) _NOEXCEPT = default;
456
457 _LIBCPP_INLINE_VISIBILITY
458 ~file_status() {}
459
460 file_status& operator=(const file_status&) _NOEXCEPT = default;
461 file_status& operator=(file_status&&) _NOEXCEPT = default;
462
463 // observers
464 _LIBCPP_ALWAYS_INLINE
465 file_type type() const _NOEXCEPT {
466 return __ft_;
467 }
468
469 _LIBCPP_ALWAYS_INLINE
470 perms permissions() const _NOEXCEPT {
471 return __prms_;
472 }
473
474 // modifiers
475 _LIBCPP_ALWAYS_INLINE
476 void type(file_type __ft) _NOEXCEPT {
477 __ft_ = __ft;
478 }
479
480 _LIBCPP_ALWAYS_INLINE
481 void permissions(perms __p) _NOEXCEPT {
482 __prms_ = __p;
483 }
484private:
485 file_type __ft_;
486 perms __prms_;
487};
488
489class _LIBCPP_TYPE_VIS directory_entry;
490
491template <class _Tp> struct __can_convert_char {
492 static const bool value = false;
493};
Eric Fiselier113315b2016-08-28 21:26:01 +0000494template <class _Tp> struct __can_convert_char<const _Tp>
495 : public __can_convert_char<_Tp> {
496};
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000497template <> struct __can_convert_char<char> {
498 static const bool value = true;
499 using __char_type = char;
500};
501template <> struct __can_convert_char<wchar_t> {
502 static const bool value = true;
503 using __char_type = wchar_t;
504};
505template <> struct __can_convert_char<char16_t> {
506 static const bool value = true;
507 using __char_type = char16_t;
508};
509template <> struct __can_convert_char<char32_t> {
510 static const bool value = true;
511 using __char_type = char32_t;
512};
513
514template <class _ECharT>
515typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
516__is_separator(_ECharT __e) {
517 return __e == _ECharT('/');
518};
519
520struct _NullSentinal {};
521
522template <class _Tp>
523using _Void = void;
524
525template <class _Tp, class = void>
526struct __is_pathable_string : public false_type {};
527
528template <class _ECharT, class _Traits, class _Alloc>
529struct __is_pathable_string<basic_string<_ECharT, _Traits, _Alloc>,
530 _Void<typename __can_convert_char<_ECharT>::__char_type>>
531: public __can_convert_char<_ECharT>
532{
533 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
534 using _Base = __can_convert_char<_ECharT>;
535 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
536 static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
537 static _ECharT __first_or_null(_Str const& __s) {
538 return __s.empty() ? _ECharT{} : __s[0];
539 }
540};
541
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000542
543template <class _ECharT, class _Traits>
544struct __is_pathable_string<basic_string_view<_ECharT, _Traits>,
545 _Void<typename __can_convert_char<_ECharT>::__char_type>>
546: public __can_convert_char<_ECharT>
547{
548 using _Str = basic_string_view<_ECharT, _Traits>;
549 using _Base = __can_convert_char<_ECharT>;
550 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
551 static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
552 static _ECharT __first_or_null(_Str const& __s) {
553 return __s.empty() ? _ECharT{} : __s[0];
554 }
555};
556
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000557template <class _Source,
558 class _DS = typename decay<_Source>::type,
559 class _UnqualPtrType = typename remove_const<
560 typename remove_pointer<_DS>::type>::type,
561 bool _IsCharPtr = is_pointer<_DS>::value &&
562 __can_convert_char<_UnqualPtrType>::value
563 >
564struct __is_pathable_char_array : false_type {};
565
566template <class _Source, class _ECharT, class _UPtr>
567struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
568 : __can_convert_char<typename remove_const<_ECharT>::type>
569{
570 using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
571
572 static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
573 static _ECharT const* __range_end(const _ECharT* __b)
574 {
575 using _Iter = const _ECharT*;
576 const _ECharT __sentinal = _ECharT{};
577 _Iter __e = __b;
578 for (; *__e != __sentinal; ++__e)
579 ;
580 return __e;
581 }
582
583 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
584};
585
586template <class _Iter, bool _IsIt = __is_input_iterator<_Iter>::value, class = void>
587struct __is_pathable_iter : false_type {};
588
589template <class _Iter>
590struct __is_pathable_iter<_Iter, true,
591 _Void<typename __can_convert_char<typename iterator_traits<_Iter>::value_type>::__char_type>>
592 : __can_convert_char<typename iterator_traits<_Iter>::value_type>
593{
594 using _ECharT = typename iterator_traits<_Iter>::value_type;
595 using _Base = __can_convert_char<_ECharT>;
596
597 static _Iter __range_begin(_Iter __b) { return __b; }
598 static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; }
599
600 static _ECharT __first_or_null(_Iter __b) { return *__b; }
601};
602
603template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
604 bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
605 bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value
606 >
607struct __is_pathable : false_type {
608 static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
609};
610
611template <class _Tp>
612struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
613
614
615template <class _Tp>
616struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {};
617
618
619template <class _Tp>
620struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
621
622
623template <class _ECharT>
624struct _PathCVT {
625 static_assert(__can_convert_char<_ECharT>::value, "Char type not convertible");
626
627 typedef __narrow_to_utf8<sizeof(_ECharT)*__CHAR_BIT__> _Narrower;
628
629 static void __append_range(string& __dest, _ECharT const* __b, _ECharT const* __e) {
630 _Narrower()(back_inserter(__dest), __b, __e);
631 }
632
633 template <class _Iter>
634 static void __append_range(string& __dest, _Iter __b, _Iter __e) {
635 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
636 if (__b == __e) return;
637 basic_string<_ECharT> __tmp(__b, __e);
638 _Narrower()(back_inserter(__dest), __tmp.data(),
639 __tmp.data() + __tmp.length());
640 }
641
642 template <class _Iter>
643 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
644 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
645 const _ECharT __sentinal = _ECharT{};
646 if (*__b == __sentinal) return;
647 basic_string<_ECharT> __tmp;
648 for (; *__b != __sentinal; ++__b)
649 __tmp.push_back(*__b);
650 _Narrower()(back_inserter(__dest), __tmp.data(),
651 __tmp.data() + __tmp.length());
652 }
653
654 template <class _Source>
655 static void __append_source(string& __dest, _Source const& __s)
656 {
657 using _Traits = __is_pathable<_Source>;
658 __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s));
659 }
660};
661
662template <>
663struct _PathCVT<char> {
Eric Fiselierad1a12c2016-10-30 23:53:50 +0000664
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000665 template <class _Iter>
Eric Fiselier026d38e2016-10-31 02:46:25 +0000666 static typename enable_if<
667 __is_exactly_input_iterator<_Iter>::value
668 >::type __append_range(string& __dest, _Iter __b, _Iter __e) {
669 for (; __b != __e; ++__b)
670 __dest.push_back(*__b);
671 }
672
673 template <class _Iter>
674 static typename enable_if<
675 __is_forward_iterator<_Iter>::value
676 >::type __append_range(string& __dest, _Iter __b, _Iter __e) {
677 __dest.__append_forward_unsafe(__b, __e);
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000678 }
679
680 template <class _Iter>
681 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
682 const char __sentinal = char{};
683 for (; *__b != __sentinal; ++__b)
684 __dest.push_back(*__b);
685 }
686
687 template <class _Source>
688 static void __append_source(string& __dest, _Source const& __s)
689 {
690 using _Traits = __is_pathable<_Source>;
Eric Fiselierad1a12c2016-10-30 23:53:50 +0000691 __append_range(__dest, _Traits::__range_begin(__s),
692 _Traits::__range_end(__s));
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000693 }
694};
695
696
697class _LIBCPP_TYPE_VIS path
698{
699 template <class _SourceOrIter, class _Tp = path&>
700 using _EnableIfPathable = typename
701 enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
702
703 template <class _Tp>
704 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
705
706 template <class _Tp>
707 using _SourceCVT = _PathCVT<_SourceChar<_Tp>>;
708
709public:
710 typedef char value_type;
711 typedef basic_string<value_type> string_type;
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000712 typedef _VSTD::string_view __string_view;
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000713 static _LIBCPP_CONSTEXPR value_type preferred_separator = '/';
714
715 // constructors and destructor
716 _LIBCPP_INLINE_VISIBILITY path() _NOEXCEPT {}
717 _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
718 _LIBCPP_INLINE_VISIBILITY path(path&& __p) _NOEXCEPT : __pn_(_VSTD::move(__p.__pn_)) {}
719
720 _LIBCPP_INLINE_VISIBILITY
721 path(string_type&& __s) _NOEXCEPT : __pn_(_VSTD::move(__s)) {}
722
723 template <
724 class _Source,
725 class = _EnableIfPathable<_Source, void>
726 >
727 path(const _Source& __src) {
728 _SourceCVT<_Source>::__append_source(__pn_, __src);
729 }
730
731 template <class _InputIt>
732 path(_InputIt __first, _InputIt __last) {
733 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
734 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
735 }
736
737 // TODO Implement locale conversions.
738 template <class _Source,
739 class = _EnableIfPathable<_Source, void>
740 >
741 path(const _Source& __src, const locale& __loc);
742 template <class _InputIt>
743 path(_InputIt __first, _InputIt _last, const locale& __loc);
744
745 _LIBCPP_INLINE_VISIBILITY
746 ~path() = default;
747
748 // assignments
749 _LIBCPP_INLINE_VISIBILITY
750 path& operator=(const path& __p) {
751 __pn_ = __p.__pn_;
752 return *this;
753 }
754
755 _LIBCPP_INLINE_VISIBILITY
756 path& operator=(path&& __p) _NOEXCEPT {
757 __pn_ = _VSTD::move(__p.__pn_);
758 return *this;
759 }
760
Eric Fiselierf2b48892017-01-18 05:48:55 +0000761 template <class = void>
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000762 _LIBCPP_INLINE_VISIBILITY
763 path& operator=(string_type&& __s) _NOEXCEPT {
764 __pn_ = _VSTD::move(__s);
765 return *this;
766 }
767
768 _LIBCPP_INLINE_VISIBILITY
769 path& assign(string_type&& __s) _NOEXCEPT {
770 __pn_ = _VSTD::move(__s);
771 return *this;
772 }
773
774 template <class _Source>
775 _LIBCPP_INLINE_VISIBILITY
776 _EnableIfPathable<_Source>
777 operator=(const _Source& __src)
778 { return this->assign(__src); }
779
780
781 template <class _Source>
782 _EnableIfPathable<_Source>
783 assign(const _Source& __src) {
784 __pn_.clear();
785 _SourceCVT<_Source>::__append_source(__pn_, __src);
786 return *this;
787 }
788
789 template <class _InputIt>
790 path& assign(_InputIt __first, _InputIt __last) {
791 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
792 __pn_.clear();
793 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
794 return *this;
795 }
796
797private:
798 template <class _ECharT>
799 void __append_sep_if_needed(_ECharT __first_or_null) {
800 const _ECharT __null_val = {};
801 bool __append_sep = !empty() &&
802 !__is_separator(__pn_.back()) &&
803 __first_or_null != __null_val && // non-empty
804 !__is_separator(__first_or_null);
805 if (__append_sep)
806 __pn_ += preferred_separator;
807 }
808
809public:
810 // appends
811 path& operator/=(const path& __p) {
Eric Fiselier4ca4e502016-10-15 21:29:44 +0000812 _LIBCPP_ASSERT(!__p.has_root_name(),
813 "cannot append to a path with a root name");
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000814 __append_sep_if_needed(__p.empty() ? char{} : __p.__pn_[0]);
815 __pn_ += __p.native();
816 return *this;
817 }
818
819 template <class _Source>
820 _LIBCPP_INLINE_VISIBILITY
821 _EnableIfPathable<_Source>
822 operator/=(const _Source& __src) {
823 return this->append(__src);
824 }
825
826 template <class _Source>
827 _EnableIfPathable<_Source>
828 append(const _Source& __src) {
829 using _Traits = __is_pathable<_Source>;
830 using _CVT = _PathCVT<_SourceChar<_Source>>;
831 __append_sep_if_needed(_Traits::__first_or_null(__src));
832 _CVT::__append_source(__pn_, __src);
833 return *this;
834 }
835
836 template <class _InputIt>
837 path& append(_InputIt __first, _InputIt __last) {
838 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
839 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
840 using _CVT = _PathCVT<_ItVal>;
841 if (__first != __last) {
842 __append_sep_if_needed(*__first);
843 _CVT::__append_range(__pn_, __first, __last);
844 }
845 return *this;
846 }
847
848 // concatenation
849 _LIBCPP_INLINE_VISIBILITY
850 path& operator+=(const path& __x) {
851 __pn_ += __x.__pn_;
852 return *this;
853 }
854
855 _LIBCPP_INLINE_VISIBILITY
856 path& operator+=(const string_type& __x) {
857 __pn_ += __x;
858 return *this;
859 }
860
861 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000862 path& operator+=(__string_view __x) {
863 __pn_ += __x;
864 return *this;
865 }
866
867 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000868 path& operator+=(const value_type* __x) {
869 __pn_ += __x;
870 return *this;
871 }
872
873 _LIBCPP_INLINE_VISIBILITY
874 path& operator+=(value_type __x) {
875 __pn_ += __x;
876 return *this;
877 }
878
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000879 template <class _ECharT>
880 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
881 operator+=(_ECharT __x)
882 {
883 basic_string<_ECharT> __tmp;
884 __tmp += __x;
885 _PathCVT<_ECharT>::__append_source(__pn_, __tmp);
886 return *this;
887 }
888
889 template <class _Source>
890 _EnableIfPathable<_Source>
891 operator+=(const _Source& __x) {
892 return this->concat(__x);
893 }
894
895 template <class _Source>
896 _EnableIfPathable<_Source>
897 concat(const _Source& __x) {
898 _SourceCVT<_Source>::__append_source(__pn_, __x);
899 return *this;
900 }
901
902 template <class _InputIt>
903 path& concat(_InputIt __first, _InputIt __last) {
904 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
905 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
906 return *this;
907 }
908
909 // modifiers
910 _LIBCPP_INLINE_VISIBILITY
911 void clear() _NOEXCEPT {
912 __pn_.clear();
913 }
914
915 path& make_preferred() { return *this; }
Eric Fiselier620a9a52016-10-15 22:37:42 +0000916
917 _LIBCPP_INLINE_VISIBILITY
918 path& remove_filename() {
919 if (__pn_.size() == __root_path_raw().size())
920 clear();
921 else
922 __pn_ = __parent_path();
923 return *this;
924 }
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000925
926 path& replace_filename(const path& __replacement) {
927 remove_filename();
928 return (*this /= __replacement);
929 }
930
931 path& replace_extension(const path& __replacement = path());
932
933 _LIBCPP_INLINE_VISIBILITY
934 void swap(path& __rhs) _NOEXCEPT {
935 __pn_.swap(__rhs.__pn_);
936 }
937
938 // native format observers
939 _LIBCPP_INLINE_VISIBILITY
940 const string_type& native() const _NOEXCEPT {
941 return __pn_;
942 }
943
944 _LIBCPP_INLINE_VISIBILITY
945 const value_type* c_str() const _NOEXCEPT { return __pn_.c_str(); }
946
947 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
948
949 template <class _ECharT, class _Traits = char_traits<_ECharT>,
950 class _Allocator = allocator<_ECharT> >
951 basic_string<_ECharT, _Traits, _Allocator>
952 string(const _Allocator& __a = _Allocator()) const {
953 using _CVT = __widen_from_utf8<sizeof(_ECharT)*__CHAR_BIT__>;
954 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
955 _Str __s(__a);
956 __s.reserve(__pn_.size());
957 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
958 return __s;
959 }
960
961 _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; }
962 _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const { return string<wchar_t>(); }
963 _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; }
964 _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const { return string<char16_t>(); }
965 _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const { return string<char32_t>(); }
966
967 // generic format observers
968 template <class _ECharT, class _Traits = char_traits<_ECharT>,
969 class _Allocator = allocator<_ECharT>
970 >
971 basic_string<_ECharT, _Traits, _Allocator>
972 generic_string(const _Allocator& __a = _Allocator()) const {
973 return string<_ECharT, _Traits, _Allocator>(__a);
974 }
975
976 std::string generic_string() const { return __pn_; }
977 std::wstring generic_wstring() const { return string<wchar_t>(); }
978 std::string generic_u8string() const { return __pn_; }
979 std::u16string generic_u16string() const { return string<char16_t>(); }
980 std::u32string generic_u32string() const { return string<char32_t>(); }
981
982private:
Saleem Abdulrasool52241cb2017-01-30 03:58:26 +0000983 int __compare(__string_view) const;
984 __string_view __root_name() const;
985 __string_view __root_directory() const;
986 __string_view __root_path_raw() const;
987 __string_view __relative_path() const;
988 __string_view __parent_path() const;
989 __string_view __filename() const;
990 __string_view __stem() const;
991 __string_view __extension() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000992
993public:
994 // compare
Eric Fiselier2645dbe2016-07-23 03:10:56 +0000995 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const _NOEXCEPT { return __compare(__p.__pn_);}
996 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s); }
997 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { return __compare(__s); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000998 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { return __compare(__s); }
999
1000 // decomposition
Eric Fiselier2645dbe2016-07-23 03:10:56 +00001001 _LIBCPP_INLINE_VISIBILITY path root_name() const { return string_type(__root_name()); }
1002 _LIBCPP_INLINE_VISIBILITY path root_directory() const { return string_type(__root_directory()); }
1003 _LIBCPP_INLINE_VISIBILITY path root_path() const { return root_name().append(string_type(__root_directory())); }
1004 _LIBCPP_INLINE_VISIBILITY path relative_path() const { return string_type(__relative_path()); }
1005 _LIBCPP_INLINE_VISIBILITY path parent_path() const { return string_type(__parent_path()); }
1006 _LIBCPP_INLINE_VISIBILITY path filename() const { return string_type(__filename()); }
1007 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem());}
1008 _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001009
1010 // query
Marshall Clowbc6989b2017-11-16 05:48:32 +00001011 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1012 bool empty() const _NOEXCEPT { return __pn_.empty(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001013
1014 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); }
1015 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); }
Eric Fiselier620a9a52016-10-15 22:37:42 +00001016 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { return !__root_path_raw().empty(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001017 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { return !__relative_path().empty(); }
1018 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { return !__parent_path().empty(); }
1019 _LIBCPP_INLINE_VISIBILITY bool has_filename() const { return !__filename().empty(); }
1020 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
1021 _LIBCPP_INLINE_VISIBILITY bool has_extension() const { return !__extension().empty(); }
1022
1023 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const { return has_root_directory(); }
1024 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
1025
1026 // iterators
1027 class _LIBCPP_TYPE_VIS iterator;
1028 typedef iterator const_iterator;
1029
Saleem Abdulrasool52241cb2017-01-30 03:58:26 +00001030 iterator begin() const;
1031 iterator end() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001032
Eric Fiselier0b47a652018-02-04 03:10:53 +00001033
1034 template <class _CharT, class _Traits>
1035 _LIBCPP_INLINE_VISIBILITY
1036 friend typename enable_if<is_same<_CharT, char>::value &&
1037 is_same<_Traits, char_traits<char>>::value,
1038 basic_ostream<_CharT, _Traits>&
1039 >::type
1040 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1041 __os << std::__quoted(__p.native());
1042 return __os;
1043 }
1044
1045 template <class _CharT, class _Traits>
1046 _LIBCPP_INLINE_VISIBILITY
1047 friend typename enable_if<!is_same<_CharT, char>::value ||
1048 !is_same<_Traits, char_traits<char>>::value,
1049 basic_ostream<_CharT, _Traits>&
1050 >::type
1051 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1052 __os << std::__quoted(__p.string<_CharT, _Traits>());
1053 return __os;
1054 }
1055
1056 template <class _CharT, class _Traits>
1057 _LIBCPP_INLINE_VISIBILITY
1058 friend basic_istream<_CharT, _Traits>&
1059 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
1060 {
1061 basic_string<_CharT, _Traits> __tmp;
1062 __is >> __quoted(__tmp);
1063 __p = __tmp;
1064 return __is;
1065 }
1066
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001067private:
1068 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2645dbe2016-07-23 03:10:56 +00001069 path& __assign_view(__string_view const& __s) noexcept { __pn_ = string_type(__s); return *this; }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001070 string_type __pn_;
1071};
1072
1073inline _LIBCPP_ALWAYS_INLINE
1074void swap(path& __lhs, path& __rhs) _NOEXCEPT {
1075 __lhs.swap(__rhs);
1076}
1077
1078_LIBCPP_FUNC_VIS
1079size_t hash_value(const path& __p) _NOEXCEPT;
1080
1081inline _LIBCPP_INLINE_VISIBILITY
1082bool operator==(const path& __lhs, const path& __rhs) _NOEXCEPT
1083{ return __lhs.compare(__rhs) == 0; }
1084
1085inline _LIBCPP_INLINE_VISIBILITY
1086bool operator!=(const path& __lhs, const path& __rhs) _NOEXCEPT
1087{ return __lhs.compare(__rhs) != 0; }
1088
1089inline _LIBCPP_INLINE_VISIBILITY
1090bool operator<(const path& __lhs, const path& __rhs) _NOEXCEPT
1091{ return __lhs.compare(__rhs) < 0; }
1092
1093inline _LIBCPP_INLINE_VISIBILITY
1094bool operator<=(const path& __lhs, const path& __rhs) _NOEXCEPT
1095{ return __lhs.compare(__rhs) <= 0; }
1096
1097inline _LIBCPP_INLINE_VISIBILITY
1098bool operator>(const path& __lhs, const path& __rhs) _NOEXCEPT
1099{ return __lhs.compare(__rhs) > 0; }
1100
1101inline _LIBCPP_INLINE_VISIBILITY
1102bool operator>=(const path& __lhs, const path& __rhs) _NOEXCEPT
1103{ return __lhs.compare(__rhs) >= 0; }
1104
1105inline _LIBCPP_INLINE_VISIBILITY
1106path operator/(const path& __lhs, const path& __rhs) {
1107 return path(__lhs) /= __rhs;
1108}
1109
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001110template <class _Source>
1111_LIBCPP_INLINE_VISIBILITY
1112typename enable_if<__is_pathable<_Source>::value, path>::type
1113u8path(const _Source& __s){
1114 static_assert(is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1115 "u8path(Source const&) requires Source have a character type of type 'char'");
1116 return path(__s);
1117}
1118
1119template <class _InputIt>
1120_LIBCPP_INLINE_VISIBILITY
1121typename enable_if<__is_pathable<_InputIt>::value, path>::type
1122u8path(_InputIt __f, _InputIt __l) {
1123 static_assert(is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1124 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
1125 return path(__f, __l);
1126}
1127
1128class _LIBCPP_TYPE_VIS path::iterator
1129{
1130public:
1131 typedef bidirectional_iterator_tag iterator_category;
Eric Fiselier08673732017-04-04 01:05:59 +00001132
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001133 typedef path value_type;
1134 typedef std::ptrdiff_t difference_type;
1135 typedef const path* pointer;
1136 typedef const path& reference;
Eric Fiselier706e2c72017-04-13 02:54:13 +00001137
1138 typedef void __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001139public:
1140 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier271a19e2016-10-30 23:30:38 +00001141 iterator() : __stashed_elem_(), __path_ptr_(nullptr),
1142 __entry_(), __state_(__singular) {}
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001143
1144 iterator(const iterator&) = default;
1145 ~iterator() = default;
1146
1147 iterator& operator=(const iterator&) = default;
1148
1149 _LIBCPP_INLINE_VISIBILITY
1150 reference operator*() const {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001151 return __stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001152 }
1153
1154 _LIBCPP_INLINE_VISIBILITY
1155 pointer operator->() const {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001156 return &__stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001157 }
1158
1159 _LIBCPP_INLINE_VISIBILITY
1160 iterator& operator++() {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001161 _LIBCPP_ASSERT(__state_ != __singular,
1162 "attempting to increment a singular iterator");
1163 _LIBCPP_ASSERT(__state_ != __at_end,
1164 "attempting to increment the end iterator");
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001165 return __increment();
1166 }
1167
1168 _LIBCPP_INLINE_VISIBILITY
1169 iterator operator++(int) {
1170 iterator __it(*this);
1171 this->operator++();
1172 return __it;
1173 }
1174
1175 _LIBCPP_INLINE_VISIBILITY
1176 iterator& operator--() {
Eric Fiselier271a19e2016-10-30 23:30:38 +00001177 _LIBCPP_ASSERT(__state_ != __singular,
1178 "attempting to decrement a singular iterator");
1179 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
1180 "attempting to decrement the begin iterator");
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001181 return __decrement();
1182 }
1183
1184 _LIBCPP_INLINE_VISIBILITY
1185 iterator operator--(int) {
1186 iterator __it(*this);
1187 this->operator--();
1188 return __it;
1189 }
1190
1191private:
1192 friend class path;
Eric Fiselier03f7d102016-09-16 00:07:16 +00001193
Eric Fiselier271a19e2016-10-30 23:30:38 +00001194 static constexpr unsigned char __singular = 0;
1195 static constexpr unsigned char __at_end = 6;
1196
Eric Fiselier03f7d102016-09-16 00:07:16 +00001197 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001198 friend bool operator==(const iterator&, const iterator&);
1199
Saleem Abdulrasool52241cb2017-01-30 03:58:26 +00001200 iterator& __increment();
1201 iterator& __decrement();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001202
Eric Fiselier271a19e2016-10-30 23:30:38 +00001203 path __stashed_elem_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001204 const path* __path_ptr_;
Eric Fiselier271a19e2016-10-30 23:30:38 +00001205 path::__string_view __entry_;
1206 unsigned char __state_;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001207};
1208
1209inline _LIBCPP_INLINE_VISIBILITY
1210bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) {
1211 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
Eric Fiselier271a19e2016-10-30 23:30:38 +00001212 __lhs.__entry_.data() == __rhs.__entry_.data();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001213}
1214
1215inline _LIBCPP_INLINE_VISIBILITY
1216bool operator!=(const path::iterator& __lhs, const path::iterator& __rhs) {
1217 return !(__lhs == __rhs);
1218}
1219
1220class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error
1221{
1222public:
1223 _LIBCPP_INLINE_VISIBILITY
1224 filesystem_error(const string& __what, error_code __ec)
1225 : system_error(__ec, __what),
1226 __paths_(make_shared<_Storage>(path(), path()))
1227 {}
1228
1229 _LIBCPP_INLINE_VISIBILITY
1230 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1231 : system_error(__ec, __what),
1232 __paths_(make_shared<_Storage>(__p1, path()))
1233 {}
1234
1235 _LIBCPP_INLINE_VISIBILITY
1236 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1237 error_code __ec)
1238 : system_error(__ec, __what),
1239 __paths_(make_shared<_Storage>(__p1, __p2))
1240 {}
1241
1242 _LIBCPP_INLINE_VISIBILITY
1243 const path& path1() const _NOEXCEPT {
1244 return __paths_->first;
1245 }
1246
1247 _LIBCPP_INLINE_VISIBILITY
1248 const path& path2() const _NOEXCEPT {
1249 return __paths_->second;
1250 }
1251
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001252 ~filesystem_error() override; // key function
1253
1254 // TODO(ericwf): Create a custom error message.
1255 //const char* what() const _NOEXCEPT;
1256
1257private:
1258 typedef pair<path, path> _Storage;
1259 shared_ptr<_Storage> __paths_;
1260};
1261
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001262template <class... _Args>
1263_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00001264#ifndef _LIBCPP_NO_EXCEPTIONS
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001265void __throw_filesystem_error(_Args && ...__args)
1266{
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001267 throw filesystem_error(std::forward<_Args>(__args)...);
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001268}
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00001269#else
1270void __throw_filesystem_error(_Args&&...)
1271{
1272 _VSTD::abort();
1273}
1274#endif
1275
Marshall Clowe7acb0e2016-08-25 17:47:09 +00001276
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001277// operational functions
1278
1279_LIBCPP_FUNC_VIS
1280path __canonical(const path&, const path&, error_code *__ec=nullptr);
1281_LIBCPP_FUNC_VIS
1282void __copy(const path& __from, const path& __to, copy_options __opt,
1283 error_code *__ec=nullptr);
1284_LIBCPP_FUNC_VIS
1285bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1286 error_code *__ec=nullptr);
1287_LIBCPP_FUNC_VIS
1288void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1289 error_code *__ec=nullptr);
1290_LIBCPP_FUNC_VIS
1291bool __create_directories(const path& p, error_code *ec=nullptr);
1292_LIBCPP_FUNC_VIS
1293bool __create_directory(const path& p, error_code *ec=nullptr);
1294_LIBCPP_FUNC_VIS
1295bool __create_directory(const path& p, const path & attributes,
1296 error_code *ec=nullptr);
1297_LIBCPP_FUNC_VIS
1298void __create_directory_symlink(const path& __to, const path& __new_symlink,
1299 error_code *__ec=nullptr);
1300_LIBCPP_FUNC_VIS
1301void __create_hard_link(const path& __to, const path& __new_hard_link,
1302 error_code *__ec=nullptr);
1303_LIBCPP_FUNC_VIS
1304void __create_symlink(const path& __to, const path& __new_symlink,
1305 error_code *__ec=nullptr);
1306_LIBCPP_FUNC_VIS
1307path __current_path(error_code *__ec=nullptr);
1308_LIBCPP_FUNC_VIS
1309void __current_path(const path&, error_code *__ec=nullptr);
1310_LIBCPP_FUNC_VIS
1311bool __equivalent(const path&, const path&, error_code *__ec=nullptr);
1312_LIBCPP_FUNC_VIS
1313uintmax_t __file_size(const path&, error_code *__ec=nullptr);
1314_LIBCPP_FUNC_VIS
1315uintmax_t __hard_link_count(const path&, error_code *__ec=nullptr);
1316_LIBCPP_FUNC_VIS
1317bool __fs_is_empty(const path& p, error_code *ec=nullptr);
1318_LIBCPP_FUNC_VIS
1319file_time_type __last_write_time(const path& p, error_code *ec=nullptr);
1320_LIBCPP_FUNC_VIS
1321void __last_write_time(const path& p, file_time_type new_time,
1322 error_code *ec=nullptr);
1323_LIBCPP_FUNC_VIS
Eric Fiselierf2c93732018-03-26 06:23:55 +00001324void __permissions(const path&, perms, perm_options, error_code* = nullptr);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001325_LIBCPP_FUNC_VIS
1326path __read_symlink(const path& p, error_code *ec=nullptr);
1327_LIBCPP_FUNC_VIS
1328bool __remove(const path& p, error_code *ec=nullptr);
1329_LIBCPP_FUNC_VIS
1330uintmax_t __remove_all(const path& p, error_code *ec=nullptr);
1331_LIBCPP_FUNC_VIS
1332void __rename(const path& from, const path& to, error_code *ec=nullptr);
1333_LIBCPP_FUNC_VIS
1334void __resize_file(const path& p, uintmax_t size, error_code *ec=nullptr);
1335_LIBCPP_FUNC_VIS
1336space_info __space(const path&, error_code *__ec=nullptr);
1337_LIBCPP_FUNC_VIS
1338file_status __status(const path&, error_code *__ec=nullptr);
1339_LIBCPP_FUNC_VIS
1340file_status __symlink_status(const path&, error_code *__ec=nullptr);
1341_LIBCPP_FUNC_VIS
1342path __system_complete(const path&, error_code *__ec=nullptr);
1343_LIBCPP_FUNC_VIS
1344path __temp_directory_path(error_code *__ec=nullptr);
1345
1346inline _LIBCPP_INLINE_VISIBILITY
1347path current_path() {
1348 return __current_path();
1349}
1350
1351inline _LIBCPP_INLINE_VISIBILITY
1352path current_path(error_code& __ec) {
1353 return __current_path(&__ec);
1354}
1355
1356inline _LIBCPP_INLINE_VISIBILITY
1357void current_path(const path& __p) {
1358 __current_path(__p);
1359}
1360
1361inline _LIBCPP_INLINE_VISIBILITY
1362void current_path(const path& __p, error_code& __ec) _NOEXCEPT {
1363 __current_path(__p, &__ec);
1364}
1365
1366_LIBCPP_FUNC_VIS
1367path absolute(const path&, const path& __p2 = current_path());
1368
1369inline _LIBCPP_INLINE_VISIBILITY
1370path canonical(const path& __p, const path& __base = current_path()) {
1371 return __canonical(__p, __base);
1372}
1373
1374inline _LIBCPP_INLINE_VISIBILITY
1375path canonical(const path& __p, error_code& __ec) {
1376 path __base = __current_path(&__ec);
1377 if (__ec) return {};
1378 return __canonical(__p, __base, &__ec);
1379}
1380
1381inline _LIBCPP_INLINE_VISIBILITY
1382path canonical(const path& __p, const path& __base, error_code& __ec) {
1383 return __canonical(__p, __base, &__ec);
1384}
1385
1386inline _LIBCPP_INLINE_VISIBILITY
1387void copy(const path& __from, const path& __to) {
1388 __copy(__from, __to, copy_options::none);
1389}
1390
1391inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001392void copy(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001393 __copy(__from, __to, copy_options::none, &__ec);
1394}
1395
1396inline _LIBCPP_INLINE_VISIBILITY
1397void copy(const path& __from, const path& __to, copy_options __opt) {
1398 __copy(__from, __to, __opt);
1399}
1400
1401inline _LIBCPP_INLINE_VISIBILITY
1402void copy(const path& __from, const path& __to,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001403 copy_options __opt, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001404 __copy(__from, __to, __opt, &__ec);
1405}
1406
1407inline _LIBCPP_INLINE_VISIBILITY
1408bool copy_file(const path& __from, const path& __to) {
1409 return __copy_file(__from, __to, copy_options::none);
1410}
1411
1412inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001413bool copy_file(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001414 return __copy_file(__from, __to, copy_options::none, &__ec);
1415}
1416
1417inline _LIBCPP_INLINE_VISIBILITY
1418bool copy_file(const path& __from, const path& __to, copy_options __opt) {
1419 return __copy_file(__from, __to, __opt);
1420}
1421
1422inline _LIBCPP_INLINE_VISIBILITY
1423bool copy_file(const path& __from, const path& __to,
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001424 copy_options __opt, error_code& __ec){
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001425 return __copy_file(__from, __to, __opt, &__ec);
1426}
1427
1428inline _LIBCPP_INLINE_VISIBILITY
1429void copy_symlink(const path& __existing, const path& __new) {
1430 __copy_symlink(__existing, __new);
1431}
1432
1433inline _LIBCPP_INLINE_VISIBILITY
1434void copy_symlink(const path& __ext, const path& __new, error_code& __ec) _NOEXCEPT {
1435 __copy_symlink(__ext, __new, &__ec);
1436}
1437
1438inline _LIBCPP_INLINE_VISIBILITY
1439bool create_directories(const path& __p) {
1440 return __create_directories(__p);
1441}
1442
1443inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001444bool create_directories(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001445 return __create_directories(__p, &__ec);
1446}
1447
1448inline _LIBCPP_INLINE_VISIBILITY
1449bool create_directory(const path& __p) {
1450 return __create_directory(__p);
1451}
1452
1453inline _LIBCPP_INLINE_VISIBILITY
1454bool create_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1455 return __create_directory(__p, &__ec);
1456}
1457
1458inline _LIBCPP_INLINE_VISIBILITY
1459bool create_directory(const path& __p, const path& __attrs) {
1460 return __create_directory(__p, __attrs);
1461}
1462
1463inline _LIBCPP_INLINE_VISIBILITY
1464bool create_directory(const path& __p, const path& __attrs, error_code& __ec) _NOEXCEPT {
1465 return __create_directory(__p, __attrs, &__ec);
1466}
1467
1468inline _LIBCPP_INLINE_VISIBILITY
1469void create_directory_symlink(const path& __to, const path& __new) {
1470 __create_directory_symlink(__to, __new);
1471}
1472
1473inline _LIBCPP_INLINE_VISIBILITY
1474void create_directory_symlink(const path& __to, const path& __new,
1475 error_code& __ec) _NOEXCEPT {
1476 __create_directory_symlink(__to, __new, &__ec);
1477}
1478
1479inline _LIBCPP_INLINE_VISIBILITY
1480void create_hard_link(const path& __to, const path& __new) {
1481 __create_hard_link(__to, __new);
1482}
1483
1484inline _LIBCPP_INLINE_VISIBILITY
1485void create_hard_link(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT {
1486 __create_hard_link(__to, __new, &__ec);
1487}
1488
1489inline _LIBCPP_INLINE_VISIBILITY
1490void create_symlink(const path& __to, const path& __new) {
1491 __create_symlink(__to, __new);
1492}
1493
1494inline _LIBCPP_INLINE_VISIBILITY
1495void create_symlink(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT {
1496 return __create_symlink(__to, __new, &__ec);
1497}
1498
1499inline _LIBCPP_INLINE_VISIBILITY
1500bool status_known(file_status __s) _NOEXCEPT {
1501 return __s.type() != file_type::none;
1502}
1503
1504inline _LIBCPP_INLINE_VISIBILITY
1505bool exists(file_status __s) _NOEXCEPT {
1506 return status_known(__s) && __s.type() != file_type::not_found;
1507}
1508
1509inline _LIBCPP_INLINE_VISIBILITY
1510bool exists(const path& __p) {
1511 return exists(__status(__p));
1512}
1513
1514inline _LIBCPP_INLINE_VISIBILITY
1515bool exists(const path& __p, error_code& __ec) _NOEXCEPT {
Eric Fiselier756a6bd2016-06-21 22:11:16 +00001516 auto __s = __status(__p, &__ec);
1517 if (status_known(__s)) __ec.clear();
1518 return exists(__s);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001519}
1520
1521inline _LIBCPP_INLINE_VISIBILITY
1522bool equivalent(const path& __p1, const path& __p2) {
1523 return __equivalent(__p1, __p2);
1524}
1525
1526inline _LIBCPP_INLINE_VISIBILITY
1527bool equivalent(const path& __p1, const path& __p2, error_code& __ec) _NOEXCEPT {
1528 return __equivalent(__p1, __p2, &__ec);
1529}
1530
1531inline _LIBCPP_INLINE_VISIBILITY
1532uintmax_t file_size(const path& __p) {
1533 return __file_size(__p);
1534}
1535
1536inline _LIBCPP_INLINE_VISIBILITY
1537uintmax_t file_size(const path& __p, error_code& __ec) _NOEXCEPT {
1538 return __file_size(__p, &__ec);
1539}
1540
1541inline _LIBCPP_INLINE_VISIBILITY
1542uintmax_t hard_link_count(const path& __p) {
1543 return __hard_link_count(__p);
1544}
1545
1546inline _LIBCPP_INLINE_VISIBILITY
1547uintmax_t hard_link_count(const path& __p, error_code& __ec) _NOEXCEPT {
1548 return __hard_link_count(__p, &__ec);
1549}
1550
1551inline _LIBCPP_INLINE_VISIBILITY
1552bool is_block_file(file_status __s) _NOEXCEPT {
1553 return __s.type() == file_type::block;
1554}
1555
1556inline _LIBCPP_INLINE_VISIBILITY
1557bool is_block_file(const path& __p) {
1558 return is_block_file(__status(__p));
1559}
1560
1561inline _LIBCPP_INLINE_VISIBILITY
1562bool is_block_file(const path& __p, error_code& __ec) _NOEXCEPT {
1563 return is_block_file(__status(__p, &__ec));
1564}
1565
1566inline _LIBCPP_INLINE_VISIBILITY
1567bool is_character_file(file_status __s) _NOEXCEPT {
1568 return __s.type() == file_type::character;
1569}
1570
1571inline _LIBCPP_INLINE_VISIBILITY
1572bool is_character_file(const path& __p) {
1573 return is_character_file(__status(__p));
1574}
1575
1576inline _LIBCPP_INLINE_VISIBILITY
1577bool is_character_file(const path& __p, error_code& __ec) _NOEXCEPT {
1578 return is_character_file(__status(__p, &__ec));
1579}
1580
1581inline _LIBCPP_INLINE_VISIBILITY
1582bool is_directory(file_status __s) _NOEXCEPT {
1583 return __s.type() == file_type::directory;
1584}
1585
1586inline _LIBCPP_INLINE_VISIBILITY
1587bool is_directory(const path& __p) {
1588 return is_directory(__status(__p));
1589}
1590
1591inline _LIBCPP_INLINE_VISIBILITY
1592bool is_directory(const path& __p, error_code& __ec) _NOEXCEPT {
1593 return is_directory(__status(__p, &__ec));
1594}
1595
1596inline _LIBCPP_INLINE_VISIBILITY
1597bool is_empty(const path& __p) {
1598 return __fs_is_empty(__p);
1599}
1600
1601inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001602bool is_empty(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001603 return __fs_is_empty(__p, &__ec);
1604}
1605
1606inline _LIBCPP_INLINE_VISIBILITY
1607bool is_fifo(file_status __s) _NOEXCEPT {
1608 return __s.type() == file_type::fifo;
1609}
1610inline _LIBCPP_INLINE_VISIBILITY
1611bool is_fifo(const path& __p) {
1612 return is_fifo(__status(__p));
1613}
1614
1615inline _LIBCPP_INLINE_VISIBILITY
1616bool is_fifo(const path& __p, error_code& __ec) _NOEXCEPT {
1617 return is_fifo(__status(__p, &__ec));
1618}
1619
1620inline _LIBCPP_INLINE_VISIBILITY
1621bool is_regular_file(file_status __s) _NOEXCEPT {
1622 return __s.type() == file_type::regular;
1623}
1624
1625inline _LIBCPP_INLINE_VISIBILITY
1626bool is_regular_file(const path& __p) {
1627 return is_regular_file(__status(__p));
1628}
1629
1630inline _LIBCPP_INLINE_VISIBILITY
1631bool is_regular_file(const path& __p, error_code& __ec) _NOEXCEPT {
1632 return is_regular_file(__status(__p, &__ec));
1633}
1634
1635inline _LIBCPP_INLINE_VISIBILITY
1636bool is_socket(file_status __s) _NOEXCEPT {
1637 return __s.type() == file_type::socket;
1638}
1639
1640inline _LIBCPP_INLINE_VISIBILITY
1641bool is_socket(const path& __p) {
1642 return is_socket(__status(__p));
1643}
1644
1645inline _LIBCPP_INLINE_VISIBILITY
1646bool is_socket(const path& __p, error_code& __ec) _NOEXCEPT {
1647 return is_socket(__status(__p, &__ec));
1648}
1649
1650inline _LIBCPP_INLINE_VISIBILITY
1651bool is_symlink(file_status __s) _NOEXCEPT {
1652 return __s.type() == file_type::symlink;
1653}
1654
1655inline _LIBCPP_INLINE_VISIBILITY
1656bool is_symlink(const path& __p) {
1657 return is_symlink(__symlink_status(__p));
1658}
1659
1660inline _LIBCPP_INLINE_VISIBILITY
1661bool is_symlink(const path& __p, error_code& __ec) _NOEXCEPT {
1662 return is_symlink(__symlink_status(__p, &__ec));
1663}
1664
1665inline _LIBCPP_INLINE_VISIBILITY
1666bool is_other(file_status __s) _NOEXCEPT {
1667 return exists(__s)
1668 && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s);
1669}
1670
1671inline _LIBCPP_INLINE_VISIBILITY
1672bool is_other(const path& __p) {
1673 return is_other(__status(__p));
1674}
1675
1676inline _LIBCPP_INLINE_VISIBILITY
1677bool is_other(const path& __p, error_code& __ec) _NOEXCEPT {
1678 return is_other(__status(__p, &__ec));
1679}
1680
1681inline _LIBCPP_INLINE_VISIBILITY
1682file_time_type last_write_time(const path& __p) {
1683 return __last_write_time(__p);
1684}
1685
1686inline _LIBCPP_INLINE_VISIBILITY
1687file_time_type last_write_time(const path& __p, error_code& __ec) _NOEXCEPT {
1688 return __last_write_time(__p, &__ec);
1689}
1690
1691inline _LIBCPP_INLINE_VISIBILITY
1692void last_write_time(const path& __p, file_time_type __t) {
1693 __last_write_time(__p, __t);
1694}
1695
1696inline _LIBCPP_INLINE_VISIBILITY
1697void last_write_time(const path& __p, file_time_type __t, error_code& __ec) _NOEXCEPT {
1698 __last_write_time(__p, __t, &__ec);
1699}
1700
1701inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf2c93732018-03-26 06:23:55 +00001702void permissions(const path& __p, perms __prms,
1703 perm_options __opts = perm_options::replace) {
1704 __permissions(__p, __prms, __opts);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001705}
1706
1707inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf2c93732018-03-26 06:23:55 +00001708void permissions(const path& __p, perms __prms, error_code& __ec) _NOEXCEPT {
1709 __permissions(__p, __prms, perm_options::replace, &__ec);
1710}
1711
1712inline _LIBCPP_INLINE_VISIBILITY
1713void permissions(const path& __p, perms __prms, perm_options __opts,
1714 error_code& __ec) {
1715 __permissions(__p, __prms, __opts, &__ec);
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001716}
1717
1718inline _LIBCPP_INLINE_VISIBILITY
1719path read_symlink(const path& __p) {
1720 return __read_symlink(__p);
1721}
1722
1723inline _LIBCPP_INLINE_VISIBILITY
1724path read_symlink(const path& __p, error_code& __ec) {
1725 return __read_symlink(__p, &__ec);
1726}
1727
1728inline _LIBCPP_INLINE_VISIBILITY
1729bool remove(const path& __p) {
1730 return __remove(__p);
1731}
1732
1733inline _LIBCPP_INLINE_VISIBILITY
1734bool remove(const path& __p, error_code& __ec) _NOEXCEPT {
1735 return __remove(__p, &__ec);
1736}
1737
1738inline _LIBCPP_INLINE_VISIBILITY
1739uintmax_t remove_all(const path& __p) {
1740 return __remove_all(__p);
1741}
1742
1743inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4d0f4282018-02-04 07:35:36 +00001744uintmax_t remove_all(const path& __p, error_code& __ec) {
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001745 return __remove_all(__p, &__ec);
1746}
1747
1748inline _LIBCPP_INLINE_VISIBILITY
1749void rename(const path& __from, const path& __to) {
1750 return __rename(__from, __to);
1751}
1752
1753inline _LIBCPP_INLINE_VISIBILITY
1754void rename(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT {
1755 return __rename(__from, __to, &__ec);
1756}
1757
1758inline _LIBCPP_INLINE_VISIBILITY
1759void resize_file(const path& __p, uintmax_t __ns) {
1760 return __resize_file(__p, __ns);
1761}
1762
1763inline _LIBCPP_INLINE_VISIBILITY
1764void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) _NOEXCEPT {
1765 return __resize_file(__p, __ns, &__ec);
1766}
1767
1768inline _LIBCPP_INLINE_VISIBILITY
1769space_info space(const path& __p) {
1770 return __space(__p);
1771}
1772
1773inline _LIBCPP_INLINE_VISIBILITY
1774space_info space(const path& __p, error_code& __ec) _NOEXCEPT {
1775 return __space(__p, &__ec);
1776}
1777
1778inline _LIBCPP_INLINE_VISIBILITY
1779file_status status(const path& __p) {
1780 return __status(__p);
1781}
1782
1783inline _LIBCPP_INLINE_VISIBILITY
1784file_status status(const path& __p, error_code& __ec) _NOEXCEPT {
1785 return __status(__p, &__ec);
1786}
1787
1788inline _LIBCPP_INLINE_VISIBILITY
1789file_status symlink_status(const path& __p) {
1790 return __symlink_status(__p);
1791}
1792
1793inline _LIBCPP_INLINE_VISIBILITY
1794file_status symlink_status(const path& __p, error_code& __ec) _NOEXCEPT {
1795 return __symlink_status(__p, &__ec);
1796}
1797
1798inline _LIBCPP_INLINE_VISIBILITY
1799path system_complete(const path& __p) {
1800 return __system_complete(__p);
1801}
1802
1803inline _LIBCPP_INLINE_VISIBILITY
1804path system_complete(const path& __p, error_code& __ec) {
1805 return __system_complete(__p, &__ec);
1806}
1807
1808inline _LIBCPP_INLINE_VISIBILITY
1809path temp_directory_path() {
1810 return __temp_directory_path();
1811}
1812
1813inline _LIBCPP_INLINE_VISIBILITY
1814path temp_directory_path(error_code& __ec) {
1815 return __temp_directory_path(&__ec);
1816}
1817
1818
1819class directory_entry
1820{
1821 typedef _VSTD_FS::path _Path;
1822
1823public:
1824 // constructors and destructors
1825 directory_entry() _NOEXCEPT = default;
1826 directory_entry(directory_entry const&) = default;
1827 directory_entry(directory_entry&&) _NOEXCEPT = default;
1828
1829 _LIBCPP_INLINE_VISIBILITY
1830 explicit directory_entry(_Path const& __p) : __p_(__p) {}
1831
1832 ~directory_entry() {}
1833
1834 directory_entry& operator=(directory_entry const&) = default;
1835 directory_entry& operator=(directory_entry&&) _NOEXCEPT = default;
1836
1837 _LIBCPP_INLINE_VISIBILITY
1838 void assign(_Path const& __p) {
1839 __p_ = __p;
1840 }
1841
1842 _LIBCPP_INLINE_VISIBILITY
1843 void replace_filename(_Path const& __p) {
1844 __p_ = __p_.parent_path() / __p;
1845 }
1846
1847 _LIBCPP_INLINE_VISIBILITY
1848 _Path const& path() const _NOEXCEPT {
1849 return __p_;
1850 }
1851
1852 _LIBCPP_INLINE_VISIBILITY
1853 operator const _Path&() const _NOEXCEPT {
1854 return __p_;
1855 }
1856
1857 _LIBCPP_INLINE_VISIBILITY
1858 file_status status() const {
1859 return _VSTD_FS::status(__p_);
1860 }
1861
1862 _LIBCPP_INLINE_VISIBILITY
1863 file_status status(error_code& __ec) const _NOEXCEPT {
1864 return _VSTD_FS::status(__p_, __ec);
1865 }
1866
1867 _LIBCPP_INLINE_VISIBILITY
1868 file_status symlink_status() const {
1869 return _VSTD_FS::symlink_status(__p_);
1870 }
1871
1872 _LIBCPP_INLINE_VISIBILITY
1873 file_status symlink_status(error_code& __ec) const _NOEXCEPT {
1874 return _VSTD_FS::symlink_status(__p_, __ec);
1875 }
1876
1877 _LIBCPP_INLINE_VISIBILITY
1878 bool operator< (directory_entry const& __rhs) const _NOEXCEPT {
1879 return __p_ < __rhs.__p_;
1880 }
1881
1882 _LIBCPP_INLINE_VISIBILITY
1883 bool operator==(directory_entry const& __rhs) const _NOEXCEPT {
1884 return __p_ == __rhs.__p_;
1885 }
1886
1887 _LIBCPP_INLINE_VISIBILITY
1888 bool operator!=(directory_entry const& __rhs) const _NOEXCEPT {
1889 return __p_ != __rhs.__p_;
1890 }
1891
1892 _LIBCPP_INLINE_VISIBILITY
1893 bool operator<=(directory_entry const& __rhs) const _NOEXCEPT {
1894 return __p_ <= __rhs.__p_;
1895 }
1896
1897 _LIBCPP_INLINE_VISIBILITY
1898 bool operator> (directory_entry const& __rhs) const _NOEXCEPT {
1899 return __p_ > __rhs.__p_;
1900 }
1901
1902 _LIBCPP_INLINE_VISIBILITY
1903 bool operator>=(directory_entry const& __rhs) const _NOEXCEPT {
1904 return __p_ >= __rhs.__p_;
1905 }
1906private:
1907 _Path __p_;
1908};
1909
1910
1911class directory_iterator;
1912class recursive_directory_iterator;
1913class __dir_stream;
1914
1915class __dir_element_proxy {
1916public:
1917
1918 inline _LIBCPP_INLINE_VISIBILITY
1919 directory_entry operator*() { return _VSTD::move(__elem_); }
1920
1921private:
1922 friend class directory_iterator;
1923 friend class recursive_directory_iterator;
1924 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
1925 __dir_element_proxy(__dir_element_proxy&& __o) : __elem_(_VSTD::move(__o.__elem_)) {}
1926 directory_entry __elem_;
1927};
1928
1929class directory_iterator
1930{
1931public:
1932 typedef directory_entry value_type;
1933 typedef ptrdiff_t difference_type;
1934 typedef value_type const* pointer;
1935 typedef value_type const& reference;
1936 typedef input_iterator_tag iterator_category;
1937
1938public:
1939 //ctor & dtor
1940 directory_iterator() _NOEXCEPT
1941 { }
1942
1943 explicit directory_iterator(const path& __p)
1944 : directory_iterator(__p, nullptr)
1945 { }
1946
1947 directory_iterator(const path& __p, directory_options __opts)
1948 : directory_iterator(__p, nullptr, __opts)
1949 { }
1950
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001951 directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001952 : directory_iterator(__p, &__ec)
1953 { }
1954
1955 directory_iterator(const path& __p, directory_options __opts,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001956 error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001957 : directory_iterator(__p, &__ec, __opts)
1958 { }
1959
1960 directory_iterator(const directory_iterator&) = default;
1961 directory_iterator(directory_iterator&&) = default;
1962 directory_iterator& operator=(const directory_iterator&) = default;
1963
1964 directory_iterator& operator=(directory_iterator&& __o) _NOEXCEPT {
1965 // non-default implementation provided to support self-move assign.
1966 if (this != &__o) {
1967 __imp_ = _VSTD::move(__o.__imp_);
1968 }
1969 return *this;
1970 }
1971
1972 ~directory_iterator() = default;
1973
1974 const directory_entry& operator*() const {
1975 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00001976 return __dereference();
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001977 }
1978
1979 const directory_entry* operator->() const
1980 { return &**this; }
1981
1982 directory_iterator& operator++()
1983 { return __increment(); }
1984
1985 __dir_element_proxy operator++(int) {
1986 __dir_element_proxy __p(**this);
1987 __increment();
1988 return __p;
1989 }
1990
Eric Fiseliera4c272d2017-10-30 18:59:59 +00001991 directory_iterator& increment(error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001992 { return __increment(&__ec); }
1993
1994private:
Eric Fiselier03f7d102016-09-16 00:07:16 +00001995 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00001996 friend bool operator==(const directory_iterator& __lhs,
1997 const directory_iterator& __rhs) _NOEXCEPT;
1998
1999 // construct the dir_stream
2000 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002001 directory_iterator(const path&, error_code *,
2002 directory_options = directory_options::none);
2003
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002004 _LIBCPP_FUNC_VIS
2005 directory_iterator& __increment(error_code * __ec = nullptr);
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002006
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002007 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002008 const directory_entry& __dereference() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002009
2010private:
2011 shared_ptr<__dir_stream> __imp_;
2012};
2013
2014
2015inline _LIBCPP_INLINE_VISIBILITY
2016bool operator==(const directory_iterator& __lhs,
2017 const directory_iterator& __rhs) _NOEXCEPT {
2018 return __lhs.__imp_ == __rhs.__imp_;
2019}
2020
2021inline _LIBCPP_INLINE_VISIBILITY
2022bool operator!=(const directory_iterator& __lhs,
2023 const directory_iterator& __rhs) _NOEXCEPT {
2024 return !(__lhs == __rhs);
2025}
2026
2027// enable directory_iterator range-based for statements
2028inline _LIBCPP_INLINE_VISIBILITY
2029directory_iterator begin(directory_iterator __iter) _NOEXCEPT {
2030 return __iter;
2031}
2032
2033inline _LIBCPP_INLINE_VISIBILITY
2034directory_iterator end(const directory_iterator&) _NOEXCEPT {
2035 return directory_iterator();
2036}
2037
2038class recursive_directory_iterator {
2039public:
2040 using value_type = directory_entry;
2041 using difference_type = std::ptrdiff_t;
2042 using pointer = directory_entry const *;
2043 using reference = directory_entry const &;
2044 using iterator_category = std::input_iterator_tag;
2045
2046public:
2047 // constructors and destructor
2048 _LIBCPP_INLINE_VISIBILITY
2049 recursive_directory_iterator() _NOEXCEPT
2050 : __rec_(false)
2051 {}
2052
2053 _LIBCPP_INLINE_VISIBILITY
2054 explicit recursive_directory_iterator(const path& __p,
2055 directory_options __xoptions = directory_options::none)
2056 : recursive_directory_iterator(__p, __xoptions, nullptr)
2057 { }
2058
2059 _LIBCPP_INLINE_VISIBILITY
2060 recursive_directory_iterator(const path& __p,
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002061 directory_options __xoptions, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002062 : recursive_directory_iterator(__p, __xoptions, &__ec)
2063 { }
2064
2065 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002066 recursive_directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002067 : recursive_directory_iterator(__p, directory_options::none, &__ec)
2068 { }
2069
2070 recursive_directory_iterator(const recursive_directory_iterator&) = default;
2071 recursive_directory_iterator(recursive_directory_iterator&&) = default;
2072
2073 recursive_directory_iterator &
2074 operator=(const recursive_directory_iterator&) = default;
2075
2076 _LIBCPP_INLINE_VISIBILITY
2077 recursive_directory_iterator &
2078 operator=(recursive_directory_iterator&& __o) noexcept {
2079 // non-default implementation provided to support self-move assign.
2080 if (this != &__o) {
2081 __imp_ = _VSTD::move(__o.__imp_);
2082 __rec_ = __o.__rec_;
2083 }
2084 return *this;
2085 }
2086
2087 ~recursive_directory_iterator() = default;
2088
2089 _LIBCPP_INLINE_VISIBILITY
2090 const directory_entry& operator*() const
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002091 { return __dereference(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002092
2093 _LIBCPP_INLINE_VISIBILITY
2094 const directory_entry* operator->() const
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002095 { return &__dereference(); }
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002096
2097 recursive_directory_iterator& operator++()
2098 { return __increment(); }
2099
2100 _LIBCPP_INLINE_VISIBILITY
2101 __dir_element_proxy operator++(int) {
2102 __dir_element_proxy __p(**this);
2103 __increment();
2104 return __p;
2105 }
2106
2107 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera4c272d2017-10-30 18:59:59 +00002108 recursive_directory_iterator& increment(error_code& __ec)
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002109 { return __increment(&__ec); }
2110
2111 _LIBCPP_FUNC_VIS directory_options options() const;
2112 _LIBCPP_FUNC_VIS int depth() const;
2113
2114 _LIBCPP_INLINE_VISIBILITY
2115 void pop() { __pop(); }
2116
2117 _LIBCPP_INLINE_VISIBILITY
2118 void pop(error_code& __ec)
2119 { __pop(&__ec); }
2120
2121 _LIBCPP_INLINE_VISIBILITY
2122 bool recursion_pending() const
2123 { return __rec_; }
2124
2125 _LIBCPP_INLINE_VISIBILITY
2126 void disable_recursion_pending()
2127 { __rec_ = false; }
2128
2129private:
2130 recursive_directory_iterator(const path& __p, directory_options __opt,
2131 error_code *__ec);
2132
2133 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolb35cd982017-01-30 00:15:47 +00002134 const directory_entry& __dereference() const;
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002135
2136 _LIBCPP_FUNC_VIS
2137 bool __try_recursion(error_code* __ec);
2138
2139 _LIBCPP_FUNC_VIS
2140 void __advance(error_code* __ec=nullptr);
2141
2142 _LIBCPP_FUNC_VIS
2143 recursive_directory_iterator& __increment(error_code *__ec=nullptr);
2144
2145 _LIBCPP_FUNC_VIS
2146 void __pop(error_code* __ec=nullptr);
2147
Eric Fiselier03f7d102016-09-16 00:07:16 +00002148 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002149 friend bool operator==(const recursive_directory_iterator&,
2150 const recursive_directory_iterator&) _NOEXCEPT;
2151
2152 struct __shared_imp;
2153 shared_ptr<__shared_imp> __imp_;
2154 bool __rec_;
2155}; // class recursive_directory_iterator
2156
2157
Eric Fiselier03f7d102016-09-16 00:07:16 +00002158inline _LIBCPP_INLINE_VISIBILITY
2159bool operator==(const recursive_directory_iterator& __lhs,
2160 const recursive_directory_iterator& __rhs) _NOEXCEPT
Eric Fiselier6e9a6942016-06-17 19:46:40 +00002161{
2162 return __lhs.__imp_ == __rhs.__imp_;
2163}
2164
2165_LIBCPP_INLINE_VISIBILITY
2166inline bool operator!=(const recursive_directory_iterator& __lhs,
2167 const recursive_directory_iterator& __rhs) _NOEXCEPT
2168{
2169 return !(__lhs == __rhs);
2170}
2171// enable recursive_directory_iterator range-based for statements
2172inline _LIBCPP_INLINE_VISIBILITY
2173recursive_directory_iterator begin(recursive_directory_iterator __iter) _NOEXCEPT {
2174 return __iter;
2175}
2176
2177inline _LIBCPP_INLINE_VISIBILITY
2178recursive_directory_iterator end(const recursive_directory_iterator&) _NOEXCEPT {
2179 return recursive_directory_iterator();
2180}
2181
2182_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM
2183
2184#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM