blob: 060c7e0335b2fb68fb7360e627c71f2c35e84d40 [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
Eric Fiselierd7c4ec82018-07-25 03:41:31 +000019 void swap(path& lhs, path& rhs) noexcept;
20 size_t hash_value(const path& p) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +000021
Eric Fiselierd7c4ec82018-07-25 03:41:31 +000022 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;
Eric Fiselier435db152016-06-17 19:46:40 +000028
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,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +000099 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000100
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);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000105 bool create_directory(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000106
107 bool create_directory(const path& p, const path& attributes);
108 bool create_directory(const path& p, const path& attributes,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000109 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000110
111 void create_directory_symlink(const path& to, const path& new_symlink);
112 void create_directory_symlink(const path& to, const path& new_symlink,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000113 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000114
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,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000117 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000118
119 void create_symlink(const path& to, const path& new_symlink);
120 void create_symlink(const path& to, const path& new_symlink,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000121 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000122
123 path current_path();
124 path current_path(error_code& ec);
125 void current_path(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000126 void current_path(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000127
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000128 bool exists(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000129 bool exists(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000130 bool exists(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000131
132 bool equivalent(const path& p1, const path& p2);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000133 bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000134
135 uintmax_t file_size(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000136 uintmax_t file_size(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000137
138 uintmax_t hard_link_count(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000139 uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000140
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000141 bool is_block_file(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000142 bool is_block_file(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000143 bool is_block_file(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000144
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000145 bool is_character_file(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000146 bool is_character_file(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000147 bool is_character_file(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000148
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000149 bool is_directory(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000150 bool is_directory(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000151 bool is_directory(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000152
153 bool is_empty(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000154 bool is_empty(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000155
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000156 bool is_fifo(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000157 bool is_fifo(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000158 bool is_fifo(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000159
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000160 bool is_other(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000161 bool is_other(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000162 bool is_other(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000163
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000164 bool is_regular_file(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000165 bool is_regular_file(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000166 bool is_regular_file(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000167
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000168 bool is_socket(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000169 bool is_socket(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000170 bool is_socket(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000171
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000172 bool is_symlink(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000173 bool is_symlink(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000174 bool is_symlink(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000175
176 file_time_type last_write_time(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000177 file_time_type last_write_time(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000178 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,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000180 error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000181
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);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000200 bool remove(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000201
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);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000206 void rename(const path& from, const path& to, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000207
208 void resize_file(const path& p, uintmax_t size);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000209 void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000210
211 space_info space(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000212 space_info space(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000213
214 file_status status(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000215 file_status status(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000216
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000217 bool status_known(file_status s) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000218
219 file_status symlink_status(const path& p);
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000220 file_status symlink_status(const path& p, error_code& ec) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +0000221
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>
Eric Fiselierb3b129c2018-07-20 01:44:33 +0000235#include <cstdlib>
Eric Fiselier435db152016-06-17 19:46:40 +0000236#include <chrono>
237#include <iterator>
238#include <iosfwd>
239#include <locale>
240#include <memory>
241#include <stack>
242#include <string>
243#include <system_error>
244#include <utility>
245#include <iomanip> // for quoted
Eric Fiselierb05e1b02016-07-23 03:10:56 +0000246#include <string_view>
Eric Fiselier435db152016-06-17 19:46:40 +0000247
248#include <__debug>
249
250#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
251#pragma GCC system_header
252#endif
253
Eric Fiselier3ad58be2018-07-20 01:51:48 +0000254_LIBCPP_PUSH_MACROS
255#include <__undef_macros>
256
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000257#ifndef _LIBCPP_CXX03_LANG
258
Eric Fiselier435db152016-06-17 19:46:40 +0000259#define __cpp_lib_experimental_filesystem 201406
260
261_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM
262
263typedef chrono::time_point<std::chrono::system_clock> file_time_type;
264
265struct _LIBCPP_TYPE_VIS space_info
266{
267 uintmax_t capacity;
268 uintmax_t free;
269 uintmax_t available;
270};
271
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000272enum class _LIBCPP_ENUM_VIS file_type : signed char
Eric Fiselier435db152016-06-17 19:46:40 +0000273{
274 none = 0,
275 not_found = -1,
276 regular = 1,
277 directory = 2,
278 symlink = 3,
279 block = 4,
280 character = 5,
281 fifo = 6,
282 socket = 7,
283 unknown = 8
284};
285
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000286enum class _LIBCPP_ENUM_VIS perms : unsigned
Eric Fiselier435db152016-06-17 19:46:40 +0000287{
288 none = 0,
289
290 owner_read = 0400,
291 owner_write = 0200,
292 owner_exec = 0100,
293 owner_all = 0700,
294
295 group_read = 040,
296 group_write = 020,
297 group_exec = 010,
298 group_all = 070,
299
300 others_read = 04,
301 others_write = 02,
302 others_exec = 01,
303 others_all = 07,
304
305 all = 0777,
306
307 set_uid = 04000,
308 set_gid = 02000,
309 sticky_bit = 01000,
310 mask = 07777,
311 unknown = 0xFFFF,
Eric Fiselier435db152016-06-17 19:46:40 +0000312};
313
314_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000315inline constexpr perms operator&(perms _LHS, perms _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000316{ return static_cast<perms>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); }
317
318_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000319inline constexpr perms operator|(perms _LHS, perms _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000320{ return static_cast<perms>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); }
321
322_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000323inline constexpr perms operator^(perms _LHS, perms _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000324{ return static_cast<perms>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); }
325
326_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000327inline constexpr perms operator~(perms _LHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000328{ return static_cast<perms>(~static_cast<unsigned>(_LHS)); }
329
330_LIBCPP_INLINE_VISIBILITY
331inline perms& operator&=(perms& _LHS, perms _RHS)
332{ return _LHS = _LHS & _RHS; }
333
334_LIBCPP_INLINE_VISIBILITY
335inline perms& operator|=(perms& _LHS, perms _RHS)
336{ return _LHS = _LHS | _RHS; }
337
338_LIBCPP_INLINE_VISIBILITY
339inline perms& operator^=(perms& _LHS, perms _RHS)
340{ return _LHS = _LHS ^ _RHS; }
341
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000342enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
343 replace = 1,
344 add = 2,
345 remove = 4,
346 nofollow = 8
347};
348
349_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000350inline constexpr perm_options operator&(perm_options _LHS, perm_options _RHS)
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000351{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); }
352
353_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000354inline constexpr perm_options operator|(perm_options _LHS, perm_options _RHS)
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000355{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); }
356
357_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000358inline constexpr perm_options operator^(perm_options _LHS, perm_options _RHS)
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000359{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); }
360
361_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000362inline constexpr perm_options operator~(perm_options _LHS)
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +0000363{ return static_cast<perm_options>(~static_cast<unsigned>(_LHS)); }
364
365_LIBCPP_INLINE_VISIBILITY
366inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS)
367{ return _LHS = _LHS & _RHS; }
368
369_LIBCPP_INLINE_VISIBILITY
370inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS)
371{ return _LHS = _LHS | _RHS; }
372
373_LIBCPP_INLINE_VISIBILITY
374inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS)
375{ return _LHS = _LHS ^ _RHS; }
376
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000377enum class _LIBCPP_ENUM_VIS copy_options : unsigned short
Eric Fiselier435db152016-06-17 19:46:40 +0000378{
379 none = 0,
380 skip_existing = 1,
381 overwrite_existing = 2,
382 update_existing = 4,
383 recursive = 8,
384 copy_symlinks = 16,
385 skip_symlinks = 32,
386 directories_only = 64,
387 create_symlinks = 128,
388 create_hard_links = 256,
389 __in_recursive_copy = 512,
390};
391
392_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000393inline constexpr copy_options operator&(copy_options _LHS, copy_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000394{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) & static_cast<unsigned short>(_RHS)); }
395
396_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000397inline constexpr copy_options operator|(copy_options _LHS, copy_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000398{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) | static_cast<unsigned short>(_RHS)); }
399
400_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000401inline constexpr copy_options operator^(copy_options _LHS, copy_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000402{ return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^ static_cast<unsigned short>(_RHS)); }
403
404_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000405inline constexpr copy_options operator~(copy_options _LHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000406{ return static_cast<copy_options>(~static_cast<unsigned short>(_LHS)); }
407
408_LIBCPP_INLINE_VISIBILITY
409inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS)
410{ return _LHS = _LHS & _RHS; }
411
412_LIBCPP_INLINE_VISIBILITY
413inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS)
414{ return _LHS = _LHS | _RHS; }
415
416_LIBCPP_INLINE_VISIBILITY
417inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS)
418{ return _LHS = _LHS ^ _RHS; }
419
420
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000421enum class _LIBCPP_ENUM_VIS directory_options : unsigned char
Eric Fiselier435db152016-06-17 19:46:40 +0000422{
423 none = 0,
424 follow_directory_symlink = 1,
425 skip_permission_denied = 2
426};
427
428_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000429inline constexpr directory_options operator&(directory_options _LHS, directory_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000430{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) & static_cast<unsigned char>(_RHS)); }
431
432_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000433inline constexpr directory_options operator|(directory_options _LHS, directory_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000434{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) | static_cast<unsigned char>(_RHS)); }
435
436_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000437inline constexpr directory_options operator^(directory_options _LHS, directory_options _RHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000438{ return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^ static_cast<unsigned char>(_RHS)); }
439
440_LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000441inline constexpr directory_options operator~(directory_options _LHS)
Eric Fiselier435db152016-06-17 19:46:40 +0000442{ return static_cast<directory_options>(~static_cast<unsigned char>(_LHS)); }
443
444_LIBCPP_INLINE_VISIBILITY
445inline directory_options& operator&=(directory_options& _LHS, directory_options _RHS)
446{ return _LHS = _LHS & _RHS; }
447
448_LIBCPP_INLINE_VISIBILITY
449inline directory_options& operator|=(directory_options& _LHS, directory_options _RHS)
450{ return _LHS = _LHS | _RHS; }
451
452_LIBCPP_INLINE_VISIBILITY
453inline directory_options& operator^=(directory_options& _LHS, directory_options _RHS)
454{ return _LHS = _LHS ^ _RHS; }
455
456
457class _LIBCPP_TYPE_VIS file_status
458{
459public:
460 // constructors
461 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000462 file_status() noexcept : file_status(file_type::none) {}
Eric Fiselier6afd7e82017-03-06 21:02:06 +0000463 _LIBCPP_INLINE_VISIBILITY
464 explicit file_status(file_type __ft,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000465 perms __prms = perms::unknown) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +0000466 : __ft_(__ft), __prms_(__prms)
467 {}
468
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000469 file_status(const file_status&) noexcept = default;
470 file_status(file_status&&) noexcept = default;
Eric Fiselier435db152016-06-17 19:46:40 +0000471
472 _LIBCPP_INLINE_VISIBILITY
473 ~file_status() {}
474
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000475 file_status& operator=(const file_status&) noexcept = default;
476 file_status& operator=(file_status&&) noexcept = default;
Eric Fiselier435db152016-06-17 19:46:40 +0000477
478 // observers
Louis Dionne16fe2952018-07-11 23:14:33 +0000479 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000480 file_type type() const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000481 return __ft_;
482 }
483
Louis Dionne16fe2952018-07-11 23:14:33 +0000484 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000485 perms permissions() const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000486 return __prms_;
487 }
488
489 // modifiers
Louis Dionne16fe2952018-07-11 23:14:33 +0000490 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000491 void type(file_type __ft) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000492 __ft_ = __ft;
493 }
494
Louis Dionne16fe2952018-07-11 23:14:33 +0000495 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000496 void permissions(perms __p) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000497 __prms_ = __p;
498 }
499private:
500 file_type __ft_;
501 perms __prms_;
502};
503
504class _LIBCPP_TYPE_VIS directory_entry;
505
506template <class _Tp> struct __can_convert_char {
507 static const bool value = false;
508};
Eric Fiselierc355aa32016-08-28 21:26:01 +0000509template <class _Tp> struct __can_convert_char<const _Tp>
510 : public __can_convert_char<_Tp> {
511};
Eric Fiselier435db152016-06-17 19:46:40 +0000512template <> struct __can_convert_char<char> {
513 static const bool value = true;
514 using __char_type = char;
515};
516template <> struct __can_convert_char<wchar_t> {
517 static const bool value = true;
518 using __char_type = wchar_t;
519};
520template <> struct __can_convert_char<char16_t> {
521 static const bool value = true;
522 using __char_type = char16_t;
523};
524template <> struct __can_convert_char<char32_t> {
525 static const bool value = true;
526 using __char_type = char32_t;
527};
528
529template <class _ECharT>
530typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
531__is_separator(_ECharT __e) {
532 return __e == _ECharT('/');
533};
534
535struct _NullSentinal {};
536
537template <class _Tp>
538using _Void = void;
539
540template <class _Tp, class = void>
541struct __is_pathable_string : public false_type {};
542
543template <class _ECharT, class _Traits, class _Alloc>
544struct __is_pathable_string<basic_string<_ECharT, _Traits, _Alloc>,
545 _Void<typename __can_convert_char<_ECharT>::__char_type>>
546: public __can_convert_char<_ECharT>
547{
548 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
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 Fiselierb05e1b02016-07-23 03:10:56 +0000557
558template <class _ECharT, class _Traits>
559struct __is_pathable_string<basic_string_view<_ECharT, _Traits>,
560 _Void<typename __can_convert_char<_ECharT>::__char_type>>
561: public __can_convert_char<_ECharT>
562{
563 using _Str = basic_string_view<_ECharT, _Traits>;
564 using _Base = __can_convert_char<_ECharT>;
565 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
566 static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); }
567 static _ECharT __first_or_null(_Str const& __s) {
568 return __s.empty() ? _ECharT{} : __s[0];
569 }
570};
571
Eric Fiselier435db152016-06-17 19:46:40 +0000572template <class _Source,
573 class _DS = typename decay<_Source>::type,
574 class _UnqualPtrType = typename remove_const<
575 typename remove_pointer<_DS>::type>::type,
576 bool _IsCharPtr = is_pointer<_DS>::value &&
577 __can_convert_char<_UnqualPtrType>::value
578 >
579struct __is_pathable_char_array : false_type {};
580
581template <class _Source, class _ECharT, class _UPtr>
582struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
583 : __can_convert_char<typename remove_const<_ECharT>::type>
584{
585 using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
586
587 static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
588 static _ECharT const* __range_end(const _ECharT* __b)
589 {
590 using _Iter = const _ECharT*;
591 const _ECharT __sentinal = _ECharT{};
592 _Iter __e = __b;
593 for (; *__e != __sentinal; ++__e)
594 ;
595 return __e;
596 }
597
598 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
599};
600
601template <class _Iter, bool _IsIt = __is_input_iterator<_Iter>::value, class = void>
602struct __is_pathable_iter : false_type {};
603
604template <class _Iter>
605struct __is_pathable_iter<_Iter, true,
606 _Void<typename __can_convert_char<typename iterator_traits<_Iter>::value_type>::__char_type>>
607 : __can_convert_char<typename iterator_traits<_Iter>::value_type>
608{
609 using _ECharT = typename iterator_traits<_Iter>::value_type;
610 using _Base = __can_convert_char<_ECharT>;
611
612 static _Iter __range_begin(_Iter __b) { return __b; }
613 static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; }
614
615 static _ECharT __first_or_null(_Iter __b) { return *__b; }
616};
617
618template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
619 bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
620 bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value
621 >
622struct __is_pathable : false_type {
623 static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
624};
625
626template <class _Tp>
627struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
628
629
630template <class _Tp>
631struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {};
632
633
634template <class _Tp>
635struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
636
637
638template <class _ECharT>
639struct _PathCVT {
640 static_assert(__can_convert_char<_ECharT>::value, "Char type not convertible");
641
642 typedef __narrow_to_utf8<sizeof(_ECharT)*__CHAR_BIT__> _Narrower;
643
644 static void __append_range(string& __dest, _ECharT const* __b, _ECharT const* __e) {
645 _Narrower()(back_inserter(__dest), __b, __e);
646 }
647
648 template <class _Iter>
649 static void __append_range(string& __dest, _Iter __b, _Iter __e) {
650 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
651 if (__b == __e) return;
652 basic_string<_ECharT> __tmp(__b, __e);
653 _Narrower()(back_inserter(__dest), __tmp.data(),
654 __tmp.data() + __tmp.length());
655 }
656
657 template <class _Iter>
658 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
659 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
660 const _ECharT __sentinal = _ECharT{};
661 if (*__b == __sentinal) return;
662 basic_string<_ECharT> __tmp;
663 for (; *__b != __sentinal; ++__b)
664 __tmp.push_back(*__b);
665 _Narrower()(back_inserter(__dest), __tmp.data(),
666 __tmp.data() + __tmp.length());
667 }
668
669 template <class _Source>
670 static void __append_source(string& __dest, _Source const& __s)
671 {
672 using _Traits = __is_pathable<_Source>;
673 __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s));
674 }
675};
676
677template <>
678struct _PathCVT<char> {
Eric Fiselier70027d62016-10-30 23:53:50 +0000679
Eric Fiselier435db152016-06-17 19:46:40 +0000680 template <class _Iter>
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +0000681 static typename enable_if<
682 __is_exactly_input_iterator<_Iter>::value
683 >::type __append_range(string& __dest, _Iter __b, _Iter __e) {
684 for (; __b != __e; ++__b)
685 __dest.push_back(*__b);
686 }
687
688 template <class _Iter>
689 static typename enable_if<
690 __is_forward_iterator<_Iter>::value
691 >::type __append_range(string& __dest, _Iter __b, _Iter __e) {
692 __dest.__append_forward_unsafe(__b, __e);
Eric Fiselier435db152016-06-17 19:46:40 +0000693 }
694
695 template <class _Iter>
696 static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
697 const char __sentinal = char{};
698 for (; *__b != __sentinal; ++__b)
699 __dest.push_back(*__b);
700 }
701
702 template <class _Source>
703 static void __append_source(string& __dest, _Source const& __s)
704 {
705 using _Traits = __is_pathable<_Source>;
Eric Fiselier70027d62016-10-30 23:53:50 +0000706 __append_range(__dest, _Traits::__range_begin(__s),
707 _Traits::__range_end(__s));
Eric Fiselier435db152016-06-17 19:46:40 +0000708 }
709};
710
711
712class _LIBCPP_TYPE_VIS path
713{
714 template <class _SourceOrIter, class _Tp = path&>
715 using _EnableIfPathable = typename
716 enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
717
718 template <class _Tp>
719 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
720
721 template <class _Tp>
722 using _SourceCVT = _PathCVT<_SourceChar<_Tp>>;
723
724public:
725 typedef char value_type;
726 typedef basic_string<value_type> string_type;
Eric Fiselierb05e1b02016-07-23 03:10:56 +0000727 typedef _VSTD::string_view __string_view;
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000728 static constexpr value_type preferred_separator = '/';
Eric Fiselier435db152016-06-17 19:46:40 +0000729
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000730 enum class _LIBCPP_ENUM_VIS format : unsigned char {
731 auto_format,
732 native_format,
733 generic_format
734 };
735
Eric Fiselier435db152016-06-17 19:46:40 +0000736 // constructors and destructor
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000737 _LIBCPP_INLINE_VISIBILITY path() noexcept {}
Eric Fiselier435db152016-06-17 19:46:40 +0000738 _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000739 _LIBCPP_INLINE_VISIBILITY path(path&& __p) noexcept : __pn_(_VSTD::move(__p.__pn_)) {}
Eric Fiselier435db152016-06-17 19:46:40 +0000740
741 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000742 path(string_type&& __s, format = format::auto_format) noexcept
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000743 : __pn_(_VSTD::move(__s)) {}
Eric Fiselier435db152016-06-17 19:46:40 +0000744
745 template <
746 class _Source,
747 class = _EnableIfPathable<_Source, void>
748 >
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000749 path(const _Source& __src, format = format::auto_format) {
Eric Fiselier435db152016-06-17 19:46:40 +0000750 _SourceCVT<_Source>::__append_source(__pn_, __src);
751 }
752
753 template <class _InputIt>
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000754 path(_InputIt __first, _InputIt __last, format = format::auto_format) {
Eric Fiselier435db152016-06-17 19:46:40 +0000755 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
756 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
757 }
758
759 // TODO Implement locale conversions.
760 template <class _Source,
761 class = _EnableIfPathable<_Source, void>
762 >
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000763 path(const _Source& __src, const locale& __loc,
764 format = format::auto_format);
Eric Fiselier435db152016-06-17 19:46:40 +0000765 template <class _InputIt>
Eric Fiselierb5b088c2018-04-02 23:35:24 +0000766 path(_InputIt __first, _InputIt _last, const locale& __loc,
767 format = format::auto_format);
Eric Fiselier435db152016-06-17 19:46:40 +0000768
769 _LIBCPP_INLINE_VISIBILITY
770 ~path() = default;
771
772 // assignments
773 _LIBCPP_INLINE_VISIBILITY
774 path& operator=(const path& __p) {
775 __pn_ = __p.__pn_;
776 return *this;
777 }
778
779 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000780 path& operator=(path&& __p) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000781 __pn_ = _VSTD::move(__p.__pn_);
782 return *this;
783 }
784
Eric Fiselier8beffc82017-01-18 05:48:55 +0000785 template <class = void>
Eric Fiselier435db152016-06-17 19:46:40 +0000786 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000787 path& operator=(string_type&& __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000788 __pn_ = _VSTD::move(__s);
789 return *this;
790 }
791
792 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000793 path& assign(string_type&& __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000794 __pn_ = _VSTD::move(__s);
795 return *this;
796 }
797
798 template <class _Source>
799 _LIBCPP_INLINE_VISIBILITY
800 _EnableIfPathable<_Source>
801 operator=(const _Source& __src)
802 { return this->assign(__src); }
803
804
805 template <class _Source>
806 _EnableIfPathable<_Source>
807 assign(const _Source& __src) {
808 __pn_.clear();
809 _SourceCVT<_Source>::__append_source(__pn_, __src);
810 return *this;
811 }
812
813 template <class _InputIt>
814 path& assign(_InputIt __first, _InputIt __last) {
815 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
816 __pn_.clear();
817 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
818 return *this;
819 }
820
821private:
822 template <class _ECharT>
Eric Fiselier91a182b2018-04-02 23:03:41 +0000823 static bool __source_is_absolute(_ECharT __first_or_null) {
824 return __is_separator(__first_or_null);
Eric Fiselier435db152016-06-17 19:46:40 +0000825 }
826
827public:
828 // appends
829 path& operator/=(const path& __p) {
Eric Fiselier91a182b2018-04-02 23:03:41 +0000830 if (__p.is_absolute()) {
831 __pn_ = __p.__pn_;
832 return *this;
833 }
834 if (has_filename())
835 __pn_ += preferred_separator;
Eric Fiselier435db152016-06-17 19:46:40 +0000836 __pn_ += __p.native();
837 return *this;
838 }
839
Eric Fiselier91a182b2018-04-02 23:03:41 +0000840 // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
841 // is known at compile time to be "/' since the user almost certainly intended
842 // to append a separator instead of overwriting the path with "/"
Eric Fiselier435db152016-06-17 19:46:40 +0000843 template <class _Source>
844 _LIBCPP_INLINE_VISIBILITY
845 _EnableIfPathable<_Source>
846 operator/=(const _Source& __src) {
847 return this->append(__src);
848 }
849
850 template <class _Source>
851 _EnableIfPathable<_Source>
852 append(const _Source& __src) {
853 using _Traits = __is_pathable<_Source>;
854 using _CVT = _PathCVT<_SourceChar<_Source>>;
Eric Fiselier91a182b2018-04-02 23:03:41 +0000855 if (__source_is_absolute(_Traits::__first_or_null(__src)))
856 __pn_.clear();
857 else if (has_filename())
858 __pn_ += preferred_separator;
Eric Fiselier435db152016-06-17 19:46:40 +0000859 _CVT::__append_source(__pn_, __src);
860 return *this;
861 }
862
863 template <class _InputIt>
864 path& append(_InputIt __first, _InputIt __last) {
865 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
866 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
867 using _CVT = _PathCVT<_ItVal>;
Eric Fiselier91a182b2018-04-02 23:03:41 +0000868 if (__first != __last && __source_is_absolute(*__first))
869 __pn_.clear();
870 else if (has_filename())
871 __pn_ += preferred_separator;
872 _CVT::__append_range(__pn_, __first, __last);
Eric Fiselier435db152016-06-17 19:46:40 +0000873 return *this;
874 }
875
876 // concatenation
877 _LIBCPP_INLINE_VISIBILITY
878 path& operator+=(const path& __x) {
879 __pn_ += __x.__pn_;
880 return *this;
881 }
882
883 _LIBCPP_INLINE_VISIBILITY
884 path& operator+=(const string_type& __x) {
885 __pn_ += __x;
886 return *this;
887 }
888
889 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb05e1b02016-07-23 03:10:56 +0000890 path& operator+=(__string_view __x) {
891 __pn_ += __x;
892 return *this;
893 }
894
895 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +0000896 path& operator+=(const value_type* __x) {
897 __pn_ += __x;
898 return *this;
899 }
900
901 _LIBCPP_INLINE_VISIBILITY
902 path& operator+=(value_type __x) {
903 __pn_ += __x;
904 return *this;
905 }
906
Eric Fiselier435db152016-06-17 19:46:40 +0000907 template <class _ECharT>
908 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
909 operator+=(_ECharT __x)
910 {
911 basic_string<_ECharT> __tmp;
912 __tmp += __x;
913 _PathCVT<_ECharT>::__append_source(__pn_, __tmp);
914 return *this;
915 }
916
917 template <class _Source>
918 _EnableIfPathable<_Source>
919 operator+=(const _Source& __x) {
920 return this->concat(__x);
921 }
922
923 template <class _Source>
924 _EnableIfPathable<_Source>
925 concat(const _Source& __x) {
926 _SourceCVT<_Source>::__append_source(__pn_, __x);
927 return *this;
928 }
929
930 template <class _InputIt>
931 path& concat(_InputIt __first, _InputIt __last) {
932 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
933 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
934 return *this;
935 }
936
937 // modifiers
938 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000939 void clear() noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000940 __pn_.clear();
941 }
942
943 path& make_preferred() { return *this; }
Eric Fiselierf08063a2016-10-15 22:37:42 +0000944
945 _LIBCPP_INLINE_VISIBILITY
946 path& remove_filename() {
Eric Fiselier91a182b2018-04-02 23:03:41 +0000947 auto __fname = __filename();
948 if (!__fname.empty())
949 __pn_.erase(__fname.data() - __pn_.data());
Eric Fiselierf08063a2016-10-15 22:37:42 +0000950 return *this;
951 }
Eric Fiselier435db152016-06-17 19:46:40 +0000952
953 path& replace_filename(const path& __replacement) {
954 remove_filename();
955 return (*this /= __replacement);
956 }
957
958 path& replace_extension(const path& __replacement = path());
959
960 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000961 void swap(path& __rhs) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000962 __pn_.swap(__rhs.__pn_);
963 }
964
Eric Fiselier91a182b2018-04-02 23:03:41 +0000965 // private helper to allow reserving memory in the path
966 _LIBCPP_INLINE_VISIBILITY
967 void __reserve(size_t __s) { __pn_.reserve(__s); }
968
Eric Fiselier435db152016-06-17 19:46:40 +0000969 // native format observers
970 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000971 const string_type& native() const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +0000972 return __pn_;
973 }
974
975 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +0000976 const value_type* c_str() const noexcept { return __pn_.c_str(); }
Eric Fiselier435db152016-06-17 19:46:40 +0000977
978 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
979
980 template <class _ECharT, class _Traits = char_traits<_ECharT>,
981 class _Allocator = allocator<_ECharT> >
982 basic_string<_ECharT, _Traits, _Allocator>
983 string(const _Allocator& __a = _Allocator()) const {
984 using _CVT = __widen_from_utf8<sizeof(_ECharT)*__CHAR_BIT__>;
985 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
986 _Str __s(__a);
987 __s.reserve(__pn_.size());
988 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
989 return __s;
990 }
991
992 _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; }
993 _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const { return string<wchar_t>(); }
994 _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; }
995 _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const { return string<char16_t>(); }
996 _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const { return string<char32_t>(); }
997
998 // generic format observers
999 template <class _ECharT, class _Traits = char_traits<_ECharT>,
1000 class _Allocator = allocator<_ECharT>
1001 >
1002 basic_string<_ECharT, _Traits, _Allocator>
1003 generic_string(const _Allocator& __a = _Allocator()) const {
1004 return string<_ECharT, _Traits, _Allocator>(__a);
1005 }
1006
1007 std::string generic_string() const { return __pn_; }
1008 std::wstring generic_wstring() const { return string<wchar_t>(); }
1009 std::string generic_u8string() const { return __pn_; }
1010 std::u16string generic_u16string() const { return string<char16_t>(); }
1011 std::u32string generic_u32string() const { return string<char32_t>(); }
1012
1013private:
Saleem Abdulrasool53a32382017-01-30 03:58:26 +00001014 int __compare(__string_view) const;
1015 __string_view __root_name() const;
1016 __string_view __root_directory() const;
1017 __string_view __root_path_raw() const;
1018 __string_view __relative_path() const;
1019 __string_view __parent_path() const;
1020 __string_view __filename() const;
1021 __string_view __stem() const;
1022 __string_view __extension() const;
Eric Fiselier435db152016-06-17 19:46:40 +00001023
1024public:
1025 // compare
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001026 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept { return __compare(__p.__pn_);}
Eric Fiselierb05e1b02016-07-23 03:10:56 +00001027 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s); }
1028 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { return __compare(__s); }
Eric Fiselier435db152016-06-17 19:46:40 +00001029 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { return __compare(__s); }
1030
1031 // decomposition
Eric Fiselierb05e1b02016-07-23 03:10:56 +00001032 _LIBCPP_INLINE_VISIBILITY path root_name() const { return string_type(__root_name()); }
1033 _LIBCPP_INLINE_VISIBILITY path root_directory() const { return string_type(__root_directory()); }
1034 _LIBCPP_INLINE_VISIBILITY path root_path() const { return root_name().append(string_type(__root_directory())); }
1035 _LIBCPP_INLINE_VISIBILITY path relative_path() const { return string_type(__relative_path()); }
1036 _LIBCPP_INLINE_VISIBILITY path parent_path() const { return string_type(__parent_path()); }
1037 _LIBCPP_INLINE_VISIBILITY path filename() const { return string_type(__filename()); }
1038 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem());}
1039 _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); }
Eric Fiselier435db152016-06-17 19:46:40 +00001040
1041 // query
Eric Fiselier23a120c2018-07-25 03:31:48 +00001042 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001043 bool empty() const noexcept { return __pn_.empty(); }
Eric Fiselier435db152016-06-17 19:46:40 +00001044
1045 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); }
1046 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); }
Eric Fiselierf08063a2016-10-15 22:37:42 +00001047 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { return !__root_path_raw().empty(); }
Eric Fiselier435db152016-06-17 19:46:40 +00001048 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { return !__relative_path().empty(); }
1049 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { return !__parent_path().empty(); }
1050 _LIBCPP_INLINE_VISIBILITY bool has_filename() const { return !__filename().empty(); }
1051 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
1052 _LIBCPP_INLINE_VISIBILITY bool has_extension() const { return !__extension().empty(); }
1053
1054 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const { return has_root_directory(); }
1055 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
1056
Eric Fiselier91a182b2018-04-02 23:03:41 +00001057 // relative paths
1058 path lexically_normal() const;
1059 path lexically_relative(const path& __base) const;
1060
1061 _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
1062 path __result = this->lexically_relative(__base);
1063 if (__result.native().empty())
1064 return *this;
1065 return __result;
1066 }
1067
Eric Fiselier435db152016-06-17 19:46:40 +00001068 // iterators
1069 class _LIBCPP_TYPE_VIS iterator;
1070 typedef iterator const_iterator;
1071
Saleem Abdulrasool53a32382017-01-30 03:58:26 +00001072 iterator begin() const;
1073 iterator end() const;
Eric Fiselier435db152016-06-17 19:46:40 +00001074
Eric Fiselier2cd75272018-02-04 03:10:53 +00001075
1076 template <class _CharT, class _Traits>
1077 _LIBCPP_INLINE_VISIBILITY
1078 friend typename enable_if<is_same<_CharT, char>::value &&
1079 is_same<_Traits, char_traits<char>>::value,
1080 basic_ostream<_CharT, _Traits>&
1081 >::type
1082 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1083 __os << std::__quoted(__p.native());
1084 return __os;
1085 }
1086
1087 template <class _CharT, class _Traits>
1088 _LIBCPP_INLINE_VISIBILITY
1089 friend typename enable_if<!is_same<_CharT, char>::value ||
1090 !is_same<_Traits, char_traits<char>>::value,
1091 basic_ostream<_CharT, _Traits>&
1092 >::type
1093 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1094 __os << std::__quoted(__p.string<_CharT, _Traits>());
1095 return __os;
1096 }
1097
1098 template <class _CharT, class _Traits>
1099 _LIBCPP_INLINE_VISIBILITY
1100 friend basic_istream<_CharT, _Traits>&
1101 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
1102 {
1103 basic_string<_CharT, _Traits> __tmp;
1104 __is >> __quoted(__tmp);
1105 __p = __tmp;
1106 return __is;
1107 }
1108
Eric Fiselier435db152016-06-17 19:46:40 +00001109private:
1110 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb05e1b02016-07-23 03:10:56 +00001111 path& __assign_view(__string_view const& __s) noexcept { __pn_ = string_type(__s); return *this; }
Eric Fiselier435db152016-06-17 19:46:40 +00001112 string_type __pn_;
1113};
1114
Louis Dionne16fe2952018-07-11 23:14:33 +00001115inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001116void swap(path& __lhs, path& __rhs) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001117 __lhs.swap(__rhs);
1118}
1119
1120_LIBCPP_FUNC_VIS
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001121size_t hash_value(const path& __p) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +00001122
1123inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001124bool operator==(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001125{ return __lhs.compare(__rhs) == 0; }
1126
1127inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001128bool operator!=(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001129{ return __lhs.compare(__rhs) != 0; }
1130
1131inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001132bool operator<(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001133{ return __lhs.compare(__rhs) < 0; }
1134
1135inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001136bool operator<=(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001137{ return __lhs.compare(__rhs) <= 0; }
1138
1139inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001140bool operator>(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001141{ return __lhs.compare(__rhs) > 0; }
1142
1143inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001144bool operator>=(const path& __lhs, const path& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00001145{ return __lhs.compare(__rhs) >= 0; }
1146
1147inline _LIBCPP_INLINE_VISIBILITY
1148path operator/(const path& __lhs, const path& __rhs) {
David Bolvansky38b37ef2018-05-09 18:57:17 +00001149 path __result(__lhs);
1150 __result /= __rhs;
1151 return __result;
Eric Fiselier435db152016-06-17 19:46:40 +00001152}
1153
Eric Fiselier435db152016-06-17 19:46:40 +00001154template <class _Source>
1155_LIBCPP_INLINE_VISIBILITY
1156typename enable_if<__is_pathable<_Source>::value, path>::type
1157u8path(const _Source& __s){
1158 static_assert(is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1159 "u8path(Source const&) requires Source have a character type of type 'char'");
1160 return path(__s);
1161}
1162
1163template <class _InputIt>
1164_LIBCPP_INLINE_VISIBILITY
1165typename enable_if<__is_pathable<_InputIt>::value, path>::type
1166u8path(_InputIt __f, _InputIt __l) {
1167 static_assert(is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1168 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
1169 return path(__f, __l);
1170}
1171
1172class _LIBCPP_TYPE_VIS path::iterator
1173{
1174public:
Eric Fiselier23a120c2018-07-25 03:31:48 +00001175 enum _ParserState : unsigned char {
1176 _Singular,
1177 _BeforeBegin,
1178 _InRootName,
1179 _InRootDir,
1180 _InFilenames,
1181 _InTrailingSep,
1182 _AtEnd
1183 };
1184
1185public:
Eric Fiselier435db152016-06-17 19:46:40 +00001186 typedef bidirectional_iterator_tag iterator_category;
Eric Fiselierc8dac982017-04-04 01:05:59 +00001187
Eric Fiselier435db152016-06-17 19:46:40 +00001188 typedef path value_type;
1189 typedef std::ptrdiff_t difference_type;
1190 typedef const path* pointer;
1191 typedef const path& reference;
Eric Fiselier883af112017-04-13 02:54:13 +00001192
1193 typedef void __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
Eric Fiselier23a120c2018-07-25 03:31:48 +00001194
Eric Fiselier435db152016-06-17 19:46:40 +00001195public:
1196 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfc46d252016-10-30 23:30:38 +00001197 iterator() : __stashed_elem_(), __path_ptr_(nullptr),
Eric Fiselier23a120c2018-07-25 03:31:48 +00001198 __entry_(), __state_(_Singular) {}
Eric Fiselier435db152016-06-17 19:46:40 +00001199
1200 iterator(const iterator&) = default;
1201 ~iterator() = default;
1202
1203 iterator& operator=(const iterator&) = default;
1204
1205 _LIBCPP_INLINE_VISIBILITY
1206 reference operator*() const {
Eric Fiselierfc46d252016-10-30 23:30:38 +00001207 return __stashed_elem_;
Eric Fiselier435db152016-06-17 19:46:40 +00001208 }
1209
1210 _LIBCPP_INLINE_VISIBILITY
1211 pointer operator->() const {
Eric Fiselierfc46d252016-10-30 23:30:38 +00001212 return &__stashed_elem_;
Eric Fiselier435db152016-06-17 19:46:40 +00001213 }
1214
1215 _LIBCPP_INLINE_VISIBILITY
1216 iterator& operator++() {
Eric Fiselier23a120c2018-07-25 03:31:48 +00001217 _LIBCPP_ASSERT(__state_ != _Singular,
Eric Fiselierfc46d252016-10-30 23:30:38 +00001218 "attempting to increment a singular iterator");
Eric Fiselier23a120c2018-07-25 03:31:48 +00001219 _LIBCPP_ASSERT(__state_ != _AtEnd,
Eric Fiselierfc46d252016-10-30 23:30:38 +00001220 "attempting to increment the end iterator");
Eric Fiselier435db152016-06-17 19:46:40 +00001221 return __increment();
1222 }
1223
1224 _LIBCPP_INLINE_VISIBILITY
1225 iterator operator++(int) {
1226 iterator __it(*this);
1227 this->operator++();
1228 return __it;
1229 }
1230
1231 _LIBCPP_INLINE_VISIBILITY
1232 iterator& operator--() {
Eric Fiselier23a120c2018-07-25 03:31:48 +00001233 _LIBCPP_ASSERT(__state_ != _Singular,
Eric Fiselierfc46d252016-10-30 23:30:38 +00001234 "attempting to decrement a singular iterator");
1235 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
1236 "attempting to decrement the begin iterator");
Eric Fiselier435db152016-06-17 19:46:40 +00001237 return __decrement();
1238 }
1239
1240 _LIBCPP_INLINE_VISIBILITY
1241 iterator operator--(int) {
1242 iterator __it(*this);
1243 this->operator--();
1244 return __it;
1245 }
1246
1247private:
1248 friend class path;
Eric Fiselier28175a32016-09-16 00:07:16 +00001249
1250 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00001251 friend bool operator==(const iterator&, const iterator&);
1252
Saleem Abdulrasool53a32382017-01-30 03:58:26 +00001253 iterator& __increment();
1254 iterator& __decrement();
Eric Fiselier435db152016-06-17 19:46:40 +00001255
Eric Fiselierfc46d252016-10-30 23:30:38 +00001256 path __stashed_elem_;
Eric Fiselier435db152016-06-17 19:46:40 +00001257 const path* __path_ptr_;
Eric Fiselierfc46d252016-10-30 23:30:38 +00001258 path::__string_view __entry_;
Eric Fiselier23a120c2018-07-25 03:31:48 +00001259 _ParserState __state_;
Eric Fiselier435db152016-06-17 19:46:40 +00001260};
1261
1262inline _LIBCPP_INLINE_VISIBILITY
1263bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) {
1264 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
Eric Fiselierfc46d252016-10-30 23:30:38 +00001265 __lhs.__entry_.data() == __rhs.__entry_.data();
Eric Fiselier435db152016-06-17 19:46:40 +00001266}
1267
1268inline _LIBCPP_INLINE_VISIBILITY
1269bool operator!=(const path::iterator& __lhs, const path::iterator& __rhs) {
1270 return !(__lhs == __rhs);
1271}
1272
1273class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error
1274{
1275public:
1276 _LIBCPP_INLINE_VISIBILITY
1277 filesystem_error(const string& __what, error_code __ec)
1278 : system_error(__ec, __what),
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001279 __storage_(make_shared<_Storage>(path(), path())) {
1280 __create_what(0);
1281 }
Eric Fiselier435db152016-06-17 19:46:40 +00001282
1283 _LIBCPP_INLINE_VISIBILITY
1284 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1285 : system_error(__ec, __what),
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001286 __storage_(make_shared<_Storage>(__p1, path())) {
1287 __create_what(1);
1288 }
Eric Fiselier435db152016-06-17 19:46:40 +00001289
1290 _LIBCPP_INLINE_VISIBILITY
1291 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1292 error_code __ec)
1293 : system_error(__ec, __what),
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001294 __storage_(make_shared<_Storage>(__p1, __p2)) {
1295 __create_what(2);
Eric Fiselier435db152016-06-17 19:46:40 +00001296 }
1297
1298 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001299 const path& path1() const noexcept { return __storage_->__p1_; }
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001300
1301 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001302 const path& path2() const noexcept { return __storage_->__p2_; }
Eric Fiselier435db152016-06-17 19:46:40 +00001303
Eric Fiselier435db152016-06-17 19:46:40 +00001304 ~filesystem_error() override; // key function
1305
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001306 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001307 const char* what() const noexcept override {
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001308 return __storage_->__what_.c_str();
1309 }
Eric Fiselier435db152016-06-17 19:46:40 +00001310
Eric Fiseliera75bbde2018-07-23 02:00:52 +00001311 _LIBCPP_FUNC_VIS
1312 void __create_what(int __num_paths);
1313
1314 private:
1315 struct _Storage {
1316 _LIBCPP_INLINE_VISIBILITY
1317 _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}
1318
1319 path __p1_;
1320 path __p2_;
1321 string __what_;
1322 };
1323 shared_ptr<_Storage> __storage_;
Eric Fiselier435db152016-06-17 19:46:40 +00001324};
1325
Marshall Clowed3e2292016-08-25 17:47:09 +00001326template <class... _Args>
Louis Dionne16fe2952018-07-11 23:14:33 +00001327_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001328#ifndef _LIBCPP_NO_EXCEPTIONS
Marshall Clowed3e2292016-08-25 17:47:09 +00001329void __throw_filesystem_error(_Args && ...__args)
1330{
Marshall Clowed3e2292016-08-25 17:47:09 +00001331 throw filesystem_error(std::forward<_Args>(__args)...);
Marshall Clowed3e2292016-08-25 17:47:09 +00001332}
Eric Fiselier6003c772016-12-23 23:37:52 +00001333#else
1334void __throw_filesystem_error(_Args&&...)
1335{
1336 _VSTD::abort();
1337}
1338#endif
1339
Eric Fiselier435db152016-06-17 19:46:40 +00001340// operational functions
1341
1342_LIBCPP_FUNC_VIS
Eric Fiselier91a182b2018-04-02 23:03:41 +00001343path __absolute(const path&, error_code *__ec=nullptr);
1344_LIBCPP_FUNC_VIS
1345path __canonical(const path&, error_code *__ec=nullptr);
Eric Fiselier435db152016-06-17 19:46:40 +00001346_LIBCPP_FUNC_VIS
1347void __copy(const path& __from, const path& __to, copy_options __opt,
1348 error_code *__ec=nullptr);
1349_LIBCPP_FUNC_VIS
1350bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1351 error_code *__ec=nullptr);
1352_LIBCPP_FUNC_VIS
1353void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1354 error_code *__ec=nullptr);
1355_LIBCPP_FUNC_VIS
1356bool __create_directories(const path& p, error_code *ec=nullptr);
1357_LIBCPP_FUNC_VIS
1358bool __create_directory(const path& p, error_code *ec=nullptr);
1359_LIBCPP_FUNC_VIS
1360bool __create_directory(const path& p, const path & attributes,
1361 error_code *ec=nullptr);
1362_LIBCPP_FUNC_VIS
1363void __create_directory_symlink(const path& __to, const path& __new_symlink,
1364 error_code *__ec=nullptr);
1365_LIBCPP_FUNC_VIS
1366void __create_hard_link(const path& __to, const path& __new_hard_link,
1367 error_code *__ec=nullptr);
1368_LIBCPP_FUNC_VIS
1369void __create_symlink(const path& __to, const path& __new_symlink,
1370 error_code *__ec=nullptr);
1371_LIBCPP_FUNC_VIS
1372path __current_path(error_code *__ec=nullptr);
1373_LIBCPP_FUNC_VIS
1374void __current_path(const path&, error_code *__ec=nullptr);
1375_LIBCPP_FUNC_VIS
1376bool __equivalent(const path&, const path&, error_code *__ec=nullptr);
1377_LIBCPP_FUNC_VIS
1378uintmax_t __file_size(const path&, error_code *__ec=nullptr);
1379_LIBCPP_FUNC_VIS
1380uintmax_t __hard_link_count(const path&, error_code *__ec=nullptr);
1381_LIBCPP_FUNC_VIS
1382bool __fs_is_empty(const path& p, error_code *ec=nullptr);
1383_LIBCPP_FUNC_VIS
1384file_time_type __last_write_time(const path& p, error_code *ec=nullptr);
1385_LIBCPP_FUNC_VIS
1386void __last_write_time(const path& p, file_time_type new_time,
1387 error_code *ec=nullptr);
1388_LIBCPP_FUNC_VIS
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +00001389void __permissions(const path&, perms, perm_options, error_code* = nullptr);
Eric Fiselier435db152016-06-17 19:46:40 +00001390_LIBCPP_FUNC_VIS
1391path __read_symlink(const path& p, error_code *ec=nullptr);
1392_LIBCPP_FUNC_VIS
1393bool __remove(const path& p, error_code *ec=nullptr);
1394_LIBCPP_FUNC_VIS
1395uintmax_t __remove_all(const path& p, error_code *ec=nullptr);
1396_LIBCPP_FUNC_VIS
1397void __rename(const path& from, const path& to, error_code *ec=nullptr);
1398_LIBCPP_FUNC_VIS
1399void __resize_file(const path& p, uintmax_t size, error_code *ec=nullptr);
1400_LIBCPP_FUNC_VIS
1401space_info __space(const path&, error_code *__ec=nullptr);
1402_LIBCPP_FUNC_VIS
1403file_status __status(const path&, error_code *__ec=nullptr);
1404_LIBCPP_FUNC_VIS
1405file_status __symlink_status(const path&, error_code *__ec=nullptr);
1406_LIBCPP_FUNC_VIS
1407path __system_complete(const path&, error_code *__ec=nullptr);
1408_LIBCPP_FUNC_VIS
1409path __temp_directory_path(error_code *__ec=nullptr);
Eric Fiselier91a182b2018-04-02 23:03:41 +00001410_LIBCPP_FUNC_VIS
1411path __weakly_canonical(path const& __p, error_code *__ec=nullptr);
Eric Fiselier435db152016-06-17 19:46:40 +00001412
1413inline _LIBCPP_INLINE_VISIBILITY
1414path current_path() {
1415 return __current_path();
1416}
1417
1418inline _LIBCPP_INLINE_VISIBILITY
1419path current_path(error_code& __ec) {
1420 return __current_path(&__ec);
1421}
1422
1423inline _LIBCPP_INLINE_VISIBILITY
1424void current_path(const path& __p) {
1425 __current_path(__p);
1426}
1427
1428inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001429void current_path(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001430 __current_path(__p, &__ec);
1431}
1432
Eric Fiselier91a182b2018-04-02 23:03:41 +00001433inline _LIBCPP_INLINE_VISIBILITY
1434path absolute(const path& __p) {
1435 return __absolute(__p);
1436}
Eric Fiselier435db152016-06-17 19:46:40 +00001437
1438inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier91a182b2018-04-02 23:03:41 +00001439path absolute(const path& __p, error_code &__ec) {
1440 return __absolute(__p, &__ec);
1441}
1442
1443inline _LIBCPP_INLINE_VISIBILITY
1444path canonical(const path& __p) {
1445 return __canonical(__p);
Eric Fiselier435db152016-06-17 19:46:40 +00001446}
1447
1448inline _LIBCPP_INLINE_VISIBILITY
1449path canonical(const path& __p, error_code& __ec) {
Eric Fiselier91a182b2018-04-02 23:03:41 +00001450 return __canonical(__p, &__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00001451}
1452
1453inline _LIBCPP_INLINE_VISIBILITY
1454void copy(const path& __from, const path& __to) {
1455 __copy(__from, __to, copy_options::none);
1456}
1457
1458inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd56d5322017-10-30 18:59:59 +00001459void copy(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001460 __copy(__from, __to, copy_options::none, &__ec);
1461}
1462
1463inline _LIBCPP_INLINE_VISIBILITY
1464void copy(const path& __from, const path& __to, copy_options __opt) {
1465 __copy(__from, __to, __opt);
1466}
1467
1468inline _LIBCPP_INLINE_VISIBILITY
1469void copy(const path& __from, const path& __to,
Eric Fiselierd56d5322017-10-30 18:59:59 +00001470 copy_options __opt, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001471 __copy(__from, __to, __opt, &__ec);
1472}
1473
1474inline _LIBCPP_INLINE_VISIBILITY
1475bool copy_file(const path& __from, const path& __to) {
1476 return __copy_file(__from, __to, copy_options::none);
1477}
1478
1479inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere1164812018-02-04 07:35:36 +00001480bool copy_file(const path& __from, const path& __to, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001481 return __copy_file(__from, __to, copy_options::none, &__ec);
1482}
1483
1484inline _LIBCPP_INLINE_VISIBILITY
1485bool copy_file(const path& __from, const path& __to, copy_options __opt) {
1486 return __copy_file(__from, __to, __opt);
1487}
1488
1489inline _LIBCPP_INLINE_VISIBILITY
1490bool copy_file(const path& __from, const path& __to,
Eric Fiseliere1164812018-02-04 07:35:36 +00001491 copy_options __opt, error_code& __ec){
Eric Fiselier435db152016-06-17 19:46:40 +00001492 return __copy_file(__from, __to, __opt, &__ec);
1493}
1494
1495inline _LIBCPP_INLINE_VISIBILITY
1496void copy_symlink(const path& __existing, const path& __new) {
1497 __copy_symlink(__existing, __new);
1498}
1499
1500inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001501void copy_symlink(const path& __ext, const path& __new, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001502 __copy_symlink(__ext, __new, &__ec);
1503}
1504
1505inline _LIBCPP_INLINE_VISIBILITY
1506bool create_directories(const path& __p) {
1507 return __create_directories(__p);
1508}
1509
1510inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere1164812018-02-04 07:35:36 +00001511bool create_directories(const path& __p, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001512 return __create_directories(__p, &__ec);
1513}
1514
1515inline _LIBCPP_INLINE_VISIBILITY
1516bool create_directory(const path& __p) {
1517 return __create_directory(__p);
1518}
1519
1520inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001521bool create_directory(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001522 return __create_directory(__p, &__ec);
1523}
1524
1525inline _LIBCPP_INLINE_VISIBILITY
1526bool create_directory(const path& __p, const path& __attrs) {
1527 return __create_directory(__p, __attrs);
1528}
1529
1530inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001531bool create_directory(const path& __p, const path& __attrs, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001532 return __create_directory(__p, __attrs, &__ec);
1533}
1534
1535inline _LIBCPP_INLINE_VISIBILITY
1536void create_directory_symlink(const path& __to, const path& __new) {
1537 __create_directory_symlink(__to, __new);
1538}
1539
1540inline _LIBCPP_INLINE_VISIBILITY
1541void create_directory_symlink(const path& __to, const path& __new,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001542 error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001543 __create_directory_symlink(__to, __new, &__ec);
1544}
1545
1546inline _LIBCPP_INLINE_VISIBILITY
1547void create_hard_link(const path& __to, const path& __new) {
1548 __create_hard_link(__to, __new);
1549}
1550
1551inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001552void create_hard_link(const path& __to, const path& __new, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001553 __create_hard_link(__to, __new, &__ec);
1554}
1555
1556inline _LIBCPP_INLINE_VISIBILITY
1557void create_symlink(const path& __to, const path& __new) {
1558 __create_symlink(__to, __new);
1559}
1560
1561inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier91a182b2018-04-02 23:03:41 +00001562void create_symlink(const path& __to, const path& __new,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001563 error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001564 return __create_symlink(__to, __new, &__ec);
1565}
1566
1567inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001568bool status_known(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001569 return __s.type() != file_type::none;
1570}
1571
1572inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001573bool exists(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001574 return status_known(__s) && __s.type() != file_type::not_found;
1575}
1576
1577inline _LIBCPP_INLINE_VISIBILITY
1578bool exists(const path& __p) {
1579 return exists(__status(__p));
1580}
1581
1582inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001583bool exists(const path& __p, error_code& __ec) noexcept {
Eric Fiselier0a367d22016-06-21 22:11:16 +00001584 auto __s = __status(__p, &__ec);
1585 if (status_known(__s)) __ec.clear();
1586 return exists(__s);
Eric Fiselier435db152016-06-17 19:46:40 +00001587}
1588
1589inline _LIBCPP_INLINE_VISIBILITY
1590bool equivalent(const path& __p1, const path& __p2) {
1591 return __equivalent(__p1, __p2);
1592}
1593
1594inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001595bool equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001596 return __equivalent(__p1, __p2, &__ec);
1597}
1598
1599inline _LIBCPP_INLINE_VISIBILITY
1600uintmax_t file_size(const path& __p) {
1601 return __file_size(__p);
1602}
1603
1604inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001605uintmax_t file_size(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001606 return __file_size(__p, &__ec);
1607}
1608
1609inline _LIBCPP_INLINE_VISIBILITY
1610uintmax_t hard_link_count(const path& __p) {
1611 return __hard_link_count(__p);
1612}
1613
1614inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001615uintmax_t hard_link_count(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001616 return __hard_link_count(__p, &__ec);
1617}
1618
1619inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001620bool is_block_file(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001621 return __s.type() == file_type::block;
1622}
1623
1624inline _LIBCPP_INLINE_VISIBILITY
1625bool is_block_file(const path& __p) {
1626 return is_block_file(__status(__p));
1627}
1628
1629inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001630bool is_block_file(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001631 return is_block_file(__status(__p, &__ec));
1632}
1633
1634inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001635bool is_character_file(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001636 return __s.type() == file_type::character;
1637}
1638
1639inline _LIBCPP_INLINE_VISIBILITY
1640bool is_character_file(const path& __p) {
1641 return is_character_file(__status(__p));
1642}
1643
1644inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001645bool is_character_file(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001646 return is_character_file(__status(__p, &__ec));
1647}
1648
1649inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001650bool is_directory(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001651 return __s.type() == file_type::directory;
1652}
1653
1654inline _LIBCPP_INLINE_VISIBILITY
1655bool is_directory(const path& __p) {
1656 return is_directory(__status(__p));
1657}
1658
1659inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001660bool is_directory(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001661 return is_directory(__status(__p, &__ec));
1662}
1663
1664inline _LIBCPP_INLINE_VISIBILITY
1665bool is_empty(const path& __p) {
1666 return __fs_is_empty(__p);
1667}
1668
1669inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd56d5322017-10-30 18:59:59 +00001670bool is_empty(const path& __p, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001671 return __fs_is_empty(__p, &__ec);
1672}
1673
1674inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001675bool is_fifo(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001676 return __s.type() == file_type::fifo;
1677}
1678inline _LIBCPP_INLINE_VISIBILITY
1679bool is_fifo(const path& __p) {
1680 return is_fifo(__status(__p));
1681}
1682
1683inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001684bool is_fifo(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001685 return is_fifo(__status(__p, &__ec));
1686}
1687
1688inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001689bool is_regular_file(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001690 return __s.type() == file_type::regular;
1691}
1692
1693inline _LIBCPP_INLINE_VISIBILITY
1694bool is_regular_file(const path& __p) {
1695 return is_regular_file(__status(__p));
1696}
1697
1698inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001699bool is_regular_file(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001700 return is_regular_file(__status(__p, &__ec));
1701}
1702
1703inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001704bool is_socket(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001705 return __s.type() == file_type::socket;
1706}
1707
1708inline _LIBCPP_INLINE_VISIBILITY
1709bool is_socket(const path& __p) {
1710 return is_socket(__status(__p));
1711}
1712
1713inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001714bool is_socket(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001715 return is_socket(__status(__p, &__ec));
1716}
1717
1718inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001719bool is_symlink(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001720 return __s.type() == file_type::symlink;
1721}
1722
1723inline _LIBCPP_INLINE_VISIBILITY
1724bool is_symlink(const path& __p) {
1725 return is_symlink(__symlink_status(__p));
1726}
1727
1728inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001729bool is_symlink(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001730 return is_symlink(__symlink_status(__p, &__ec));
1731}
1732
1733inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001734bool is_other(file_status __s) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001735 return exists(__s)
1736 && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s);
1737}
1738
1739inline _LIBCPP_INLINE_VISIBILITY
1740bool is_other(const path& __p) {
1741 return is_other(__status(__p));
1742}
1743
1744inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001745bool is_other(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001746 return is_other(__status(__p, &__ec));
1747}
1748
1749inline _LIBCPP_INLINE_VISIBILITY
1750file_time_type last_write_time(const path& __p) {
1751 return __last_write_time(__p);
1752}
1753
1754inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001755file_time_type last_write_time(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001756 return __last_write_time(__p, &__ec);
1757}
1758
1759inline _LIBCPP_INLINE_VISIBILITY
1760void last_write_time(const path& __p, file_time_type __t) {
1761 __last_write_time(__p, __t);
1762}
1763
1764inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001765void last_write_time(const path& __p, file_time_type __t, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001766 __last_write_time(__p, __t, &__ec);
1767}
1768
1769inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +00001770void permissions(const path& __p, perms __prms,
1771 perm_options __opts = perm_options::replace) {
1772 __permissions(__p, __prms, __opts);
Eric Fiselier435db152016-06-17 19:46:40 +00001773}
1774
1775inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001776void permissions(const path& __p, perms __prms, error_code& __ec) noexcept {
Eric Fiselier4f3dc0e2018-03-26 06:23:55 +00001777 __permissions(__p, __prms, perm_options::replace, &__ec);
1778}
1779
1780inline _LIBCPP_INLINE_VISIBILITY
1781void permissions(const path& __p, perms __prms, perm_options __opts,
1782 error_code& __ec) {
1783 __permissions(__p, __prms, __opts, &__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00001784}
1785
1786inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier91a182b2018-04-02 23:03:41 +00001787path proximate(const path& __p, const path& __base, error_code& __ec) {
1788 path __tmp = __weakly_canonical(__p, &__ec);
1789 if (__ec)
1790 return {};
1791 path __tmp_base = __weakly_canonical(__base, &__ec);
1792 if (__ec)
1793 return {};
1794 return __tmp.lexically_proximate(__tmp_base);
1795}
1796
1797inline _LIBCPP_INLINE_VISIBILITY
1798path proximate(const path& __p, error_code& __ec) {
1799 return proximate(__p, current_path(), __ec);
1800}
1801
1802inline _LIBCPP_INLINE_VISIBILITY
1803path proximate(const path& __p, const path& __base = current_path()) {
1804 return __weakly_canonical(__p).lexically_proximate(__weakly_canonical(__base));
1805}
1806
1807inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00001808path read_symlink(const path& __p) {
1809 return __read_symlink(__p);
1810}
1811
1812inline _LIBCPP_INLINE_VISIBILITY
1813path read_symlink(const path& __p, error_code& __ec) {
1814 return __read_symlink(__p, &__ec);
1815}
1816
Eric Fiselier91a182b2018-04-02 23:03:41 +00001817
1818inline _LIBCPP_INLINE_VISIBILITY
1819path relative(const path& __p, const path& __base, error_code& __ec) {
1820 path __tmp = __weakly_canonical(__p, &__ec);
1821 if (__ec)
1822 return path();
1823 path __tmpbase = __weakly_canonical(__base, &__ec);
1824 if (__ec)
1825 return path();
1826 return __tmp.lexically_relative(__tmpbase);
1827}
1828
1829inline _LIBCPP_INLINE_VISIBILITY
1830path relative(const path& __p, error_code& __ec) {
1831 return relative(__p, current_path(), __ec);
1832}
1833
1834inline _LIBCPP_INLINE_VISIBILITY
1835path relative(const path& __p, const path& __base=current_path()) {
1836 return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base));
1837}
1838
1839
Eric Fiselier435db152016-06-17 19:46:40 +00001840inline _LIBCPP_INLINE_VISIBILITY
1841bool remove(const path& __p) {
1842 return __remove(__p);
1843}
1844
1845inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001846bool remove(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001847 return __remove(__p, &__ec);
1848}
1849
1850inline _LIBCPP_INLINE_VISIBILITY
1851uintmax_t remove_all(const path& __p) {
1852 return __remove_all(__p);
1853}
1854
1855inline _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere1164812018-02-04 07:35:36 +00001856uintmax_t remove_all(const path& __p, error_code& __ec) {
Eric Fiselier435db152016-06-17 19:46:40 +00001857 return __remove_all(__p, &__ec);
1858}
1859
1860inline _LIBCPP_INLINE_VISIBILITY
1861void rename(const path& __from, const path& __to) {
1862 return __rename(__from, __to);
1863}
1864
1865inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001866void rename(const path& __from, const path& __to, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001867 return __rename(__from, __to, &__ec);
1868}
1869
1870inline _LIBCPP_INLINE_VISIBILITY
1871void resize_file(const path& __p, uintmax_t __ns) {
1872 return __resize_file(__p, __ns);
1873}
1874
1875inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001876void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001877 return __resize_file(__p, __ns, &__ec);
1878}
1879
1880inline _LIBCPP_INLINE_VISIBILITY
1881space_info space(const path& __p) {
1882 return __space(__p);
1883}
1884
1885inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001886space_info space(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001887 return __space(__p, &__ec);
1888}
1889
1890inline _LIBCPP_INLINE_VISIBILITY
1891file_status status(const path& __p) {
1892 return __status(__p);
1893}
1894
1895inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001896file_status status(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001897 return __status(__p, &__ec);
1898}
1899
1900inline _LIBCPP_INLINE_VISIBILITY
1901file_status symlink_status(const path& __p) {
1902 return __symlink_status(__p);
1903}
1904
1905inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001906file_status symlink_status(const path& __p, error_code& __ec) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001907 return __symlink_status(__p, &__ec);
1908}
1909
1910inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00001911path temp_directory_path() {
1912 return __temp_directory_path();
1913}
1914
1915inline _LIBCPP_INLINE_VISIBILITY
1916path temp_directory_path(error_code& __ec) {
1917 return __temp_directory_path(&__ec);
1918}
1919
Eric Fiselier91a182b2018-04-02 23:03:41 +00001920inline _LIBCPP_INLINE_VISIBILITY
1921path weakly_canonical(path const& __p) {
1922 return __weakly_canonical(__p);
1923}
1924
1925inline _LIBCPP_INLINE_VISIBILITY
1926path weakly_canonical(path const& __p, error_code& __ec) {
1927 return __weakly_canonical(__p, &__ec);
1928}
1929
Eric Fiselier435db152016-06-17 19:46:40 +00001930
Eric Fiselier70474082018-07-20 01:22:32 +00001931class directory_iterator;
1932class recursive_directory_iterator;
1933class __dir_stream;
1934
Eric Fiselier435db152016-06-17 19:46:40 +00001935class directory_entry
1936{
1937 typedef _VSTD_FS::path _Path;
1938
1939public:
1940 // constructors and destructors
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001941 directory_entry() noexcept = default;
Eric Fiselier435db152016-06-17 19:46:40 +00001942 directory_entry(directory_entry const&) = default;
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001943 directory_entry(directory_entry&&) noexcept = default;
Eric Fiselier435db152016-06-17 19:46:40 +00001944
1945 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier70474082018-07-20 01:22:32 +00001946 explicit directory_entry(_Path const& __p) : __p_(__p) {
1947 error_code __ec;
1948 __refresh(&__ec);
1949 }
1950
1951 _LIBCPP_INLINE_VISIBILITY
1952 directory_entry(_Path const& __p, error_code &__ec) : __p_(__p) {
1953 __refresh(&__ec);
1954 }
Eric Fiselier435db152016-06-17 19:46:40 +00001955
1956 ~directory_entry() {}
1957
1958 directory_entry& operator=(directory_entry const&) = default;
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001959 directory_entry& operator=(directory_entry&&) noexcept = default;
Eric Fiselier435db152016-06-17 19:46:40 +00001960
1961 _LIBCPP_INLINE_VISIBILITY
1962 void assign(_Path const& __p) {
1963 __p_ = __p;
Eric Fiselier70474082018-07-20 01:22:32 +00001964 error_code __ec;
1965 __refresh(&__ec);
1966 }
1967
1968 _LIBCPP_INLINE_VISIBILITY
1969 void assign(_Path const& __p, error_code& __ec) {
1970 __p_ = __p;
1971 __refresh(&__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00001972 }
1973
1974 _LIBCPP_INLINE_VISIBILITY
1975 void replace_filename(_Path const& __p) {
Eric Fiselier70474082018-07-20 01:22:32 +00001976 __p_.replace_filename(__p);
1977 error_code __ec;
1978 __refresh(&__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00001979 }
1980
1981 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier70474082018-07-20 01:22:32 +00001982 void replace_filename(_Path const& __p, error_code &__ec) {
1983 __p_ = __p_.parent_path() / __p;
1984 __refresh(&__ec);
1985 }
1986
1987 _LIBCPP_INLINE_VISIBILITY
1988 void refresh() {
1989 __refresh();
1990 }
1991
1992 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001993 void refresh(error_code& __ec) noexcept { __refresh(&__ec); }
Eric Fiselier70474082018-07-20 01:22:32 +00001994
1995 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00001996 _Path const& path() const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00001997 return __p_;
1998 }
1999
2000 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002001 operator const _Path&() const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002002 return __p_;
2003 }
2004
2005 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier70474082018-07-20 01:22:32 +00002006 bool exists() const {
2007 return _VSTD_FS::exists(file_status{__get_ft()});
2008 }
2009
2010 _LIBCPP_INLINE_VISIBILITY
2011 bool exists(error_code& __ec) const noexcept {
2012 return _VSTD_FS::exists(file_status{__get_ft(&__ec)});
2013 }
2014
2015 _LIBCPP_INLINE_VISIBILITY
2016 bool is_block_file() const {
2017 return __get_ft() == file_type::block;
2018 }
2019
2020 _LIBCPP_INLINE_VISIBILITY
2021 bool is_block_file(error_code& __ec) const noexcept {
2022 return __get_ft(&__ec) == file_type::block;
2023 }
2024
2025 _LIBCPP_INLINE_VISIBILITY
2026 bool is_character_file() const {
2027 return __get_ft() == file_type::character;
2028 }
2029
2030 _LIBCPP_INLINE_VISIBILITY
2031 bool is_character_file(error_code& __ec) const noexcept {
2032 return __get_ft(&__ec) == file_type::character;
2033 }
2034
2035 _LIBCPP_INLINE_VISIBILITY
2036 bool is_directory() const {
2037 return __get_ft() == file_type::directory;
2038 }
2039
2040 _LIBCPP_INLINE_VISIBILITY
2041 bool is_directory(error_code& __ec) const noexcept {
2042 return __get_ft(&__ec) == file_type::directory;
2043 }
2044
2045 _LIBCPP_INLINE_VISIBILITY
2046 bool is_fifo() const {
2047 return __get_ft() == file_type::fifo;
2048 }
2049
2050 _LIBCPP_INLINE_VISIBILITY
2051 bool is_fifo(error_code& __ec) const noexcept {
2052 return __get_ft(&__ec) == file_type::fifo;
2053 }
2054
2055 _LIBCPP_INLINE_VISIBILITY
2056 bool is_other() const {
2057 return _VSTD_FS::is_other(file_status{__get_ft()});
2058 }
2059
2060 _LIBCPP_INLINE_VISIBILITY
2061 bool is_other(error_code& __ec) const noexcept {
2062 return _VSTD_FS::is_other(file_status{__get_ft(&__ec)});
2063 }
2064
2065 _LIBCPP_INLINE_VISIBILITY
2066 bool is_regular_file() const {
2067 return __get_ft() == file_type::regular;
2068 }
2069
2070 _LIBCPP_INLINE_VISIBILITY
2071 bool is_regular_file(error_code& __ec) const noexcept {
2072 return __get_ft(&__ec) == file_type::regular;
2073 }
2074
2075 _LIBCPP_INLINE_VISIBILITY
2076 bool is_socket() const {
2077 return __get_ft() == file_type::socket;
2078 }
2079
2080 _LIBCPP_INLINE_VISIBILITY
2081 bool is_socket(error_code& __ec) const noexcept {
2082 return __get_ft(&__ec) == file_type::socket;
2083 }
2084
2085 _LIBCPP_INLINE_VISIBILITY
2086 bool is_symlink() const {
2087 return __get_sym_ft() == file_type::symlink;
2088 }
2089
2090 _LIBCPP_INLINE_VISIBILITY
2091 bool is_symlink(error_code& __ec) const noexcept {
2092 return __get_sym_ft(&__ec) == file_type::symlink;
2093 }
2094 _LIBCPP_INLINE_VISIBILITY
2095 uintmax_t file_size() const {
2096 return __get_size();
2097 }
2098
2099 _LIBCPP_INLINE_VISIBILITY
2100 uintmax_t file_size(error_code& __ec) const noexcept {
2101 return __get_size(&__ec);
2102 }
2103
2104 _LIBCPP_INLINE_VISIBILITY
2105 uintmax_t hard_link_count() const {
2106 return __get_nlink();
2107 }
2108
2109 _LIBCPP_INLINE_VISIBILITY
2110 uintmax_t hard_link_count(error_code& __ec) const noexcept {
2111 return __get_nlink(&__ec);
2112 }
2113
2114 _LIBCPP_INLINE_VISIBILITY
2115 file_time_type last_write_time() const {
2116 return __get_write_time();
2117 }
2118
2119 _LIBCPP_INLINE_VISIBILITY
2120 file_time_type last_write_time(error_code& __ec) const noexcept {
2121 return __get_write_time(&__ec);
2122 }
2123
2124 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00002125 file_status status() const {
Eric Fiselier70474082018-07-20 01:22:32 +00002126 return __get_status();
Eric Fiselier435db152016-06-17 19:46:40 +00002127 }
2128
2129 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002130 file_status status(error_code& __ec) const noexcept {
Eric Fiselier70474082018-07-20 01:22:32 +00002131 return __get_status(&__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00002132 }
2133
2134 _LIBCPP_INLINE_VISIBILITY
2135 file_status symlink_status() const {
Eric Fiselier70474082018-07-20 01:22:32 +00002136 return __get_symlink_status();
Eric Fiselier435db152016-06-17 19:46:40 +00002137 }
2138
2139 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002140 file_status symlink_status(error_code& __ec) const noexcept {
Eric Fiselier70474082018-07-20 01:22:32 +00002141 return __get_symlink_status(&__ec);
Eric Fiselier435db152016-06-17 19:46:40 +00002142 }
2143
2144 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002145 bool operator< (directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002146 return __p_ < __rhs.__p_;
2147 }
2148
2149 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002150 bool operator==(directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002151 return __p_ == __rhs.__p_;
2152 }
2153
2154 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002155 bool operator!=(directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002156 return __p_ != __rhs.__p_;
2157 }
2158
2159 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002160 bool operator<=(directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002161 return __p_ <= __rhs.__p_;
2162 }
2163
2164 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002165 bool operator> (directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002166 return __p_ > __rhs.__p_;
2167 }
2168
2169 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002170 bool operator>=(directory_entry const& __rhs) const noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002171 return __p_ >= __rhs.__p_;
2172 }
Eric Fiselier70474082018-07-20 01:22:32 +00002173
2174private:
2175 friend class directory_iterator;
2176 friend class recursive_directory_iterator;
2177 friend class __dir_stream;
2178
2179 enum _CacheType : unsigned char {
2180 _Empty,
2181 _IterSymlink,
2182 _IterNonSymlink,
2183 _RefreshSymlink,
2184 _RefreshSymlinkUnresolved,
2185 _RefreshNonSymlink
2186 };
2187
2188 struct __cached_data {
2189 uintmax_t __size_;
2190 uintmax_t __nlink_;
2191 file_time_type __write_time_;
2192 perms __sym_perms_;
2193 perms __non_sym_perms_;
2194 file_type __type_;
2195 _CacheType __cache_type_;
2196
2197 _LIBCPP_INLINE_VISIBILITY
2198 __cached_data() noexcept { __reset(); }
2199
2200 _LIBCPP_INLINE_VISIBILITY
2201 void __reset() {
2202 __cache_type_ = _Empty;
2203 __type_ = file_type::none;
2204 __sym_perms_ = __non_sym_perms_ = perms::unknown;
2205 __size_ = __nlink_ = uintmax_t(-1);
2206 __write_time_ = file_time_type::min();
2207 }
2208 };
2209
2210 _LIBCPP_INLINE_VISIBILITY
2211 static __cached_data __create_iter_result(file_type __ft) {
2212 __cached_data __data;
2213 __data.__type_ = __ft;
Eric Fiselierc9332892018-07-23 22:40:41 +00002214 __data.__cache_type_ = [&]() {
2215 switch (__ft) {
2216 case file_type::none:
2217 return _Empty;
2218 case file_type::symlink:
2219 return _IterSymlink;
2220 default:
2221 return _IterNonSymlink;
2222 }
2223 }();
Eric Fiselier70474082018-07-20 01:22:32 +00002224 return __data;
2225 }
2226
2227 _LIBCPP_INLINE_VISIBILITY
2228 void __assign_iter_entry(_Path&& __p, __cached_data __dt) {
2229 __p_ = std::move(__p);
2230 __data_ = __dt;
2231 }
2232
2233 _LIBCPP_FUNC_VIS
2234 error_code __do_refresh() noexcept;
2235
2236 _LIBCPP_INLINE_VISIBILITY
2237 static bool __is_dne_error(error_code const& __ec) {
2238 if (!__ec)
2239 return true;
2240 switch (static_cast<errc>(__ec.value())) {
2241 case errc::no_such_file_or_directory:
2242 case errc::not_a_directory:
2243 return true;
2244 default:
2245 return false;
2246 }
2247 }
2248
2249 _LIBCPP_INLINE_VISIBILITY
2250 void __handle_error(const char* __msg, error_code* __dest_ec,
2251 error_code const& __ec,
2252 bool __allow_dne = false) const {
2253 if (__dest_ec) {
2254 *__dest_ec = __ec;
2255 return;
2256 }
2257 if (__ec && (!__allow_dne || !__is_dne_error(__ec)))
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002258 __throw_filesystem_error(__msg, __p_, __ec);
Eric Fiselier70474082018-07-20 01:22:32 +00002259 }
2260
2261 _LIBCPP_INLINE_VISIBILITY
2262 void __refresh(error_code* __ec = nullptr) {
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002263 __handle_error("in directory_entry::refresh", __ec, __do_refresh(),
2264 /*allow_dne*/ true);
Eric Fiselier70474082018-07-20 01:22:32 +00002265 }
2266
2267 _LIBCPP_INLINE_VISIBILITY
2268 file_type __get_sym_ft(error_code *__ec = nullptr) const {
2269 switch (__data_.__cache_type_) {
2270 case _Empty:
2271 return __symlink_status(__p_, __ec).type();
2272 case _IterSymlink:
2273 case _RefreshSymlink:
2274 case _RefreshSymlinkUnresolved:
2275 if (__ec)
2276 __ec->clear();
2277 return file_type::symlink;
2278 case _IterNonSymlink:
2279 case _RefreshNonSymlink:
2280 file_status __st(__data_.__type_);
2281 if (__ec && !_VSTD_FS::exists(__st))
2282 *__ec = make_error_code(errc::no_such_file_or_directory);
2283 else if (__ec)
2284 __ec->clear();
2285 return __data_.__type_;
2286 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002287 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002288 }
2289
2290 _LIBCPP_INLINE_VISIBILITY
2291 file_type __get_ft(error_code *__ec = nullptr) const {
2292 switch (__data_.__cache_type_) {
2293 case _Empty:
2294 case _IterSymlink:
2295 case _RefreshSymlinkUnresolved:
2296 return __status(__p_, __ec).type();
2297 case _IterNonSymlink:
2298 case _RefreshNonSymlink:
2299 case _RefreshSymlink: {
2300 file_status __st(__data_.__type_);
2301 if (__ec && !_VSTD_FS::exists(__st))
2302 *__ec = make_error_code(errc::no_such_file_or_directory);
2303 else if (__ec)
2304 __ec->clear();
2305 return __data_.__type_;
2306 }
2307 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002308 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002309 }
2310
2311 _LIBCPP_INLINE_VISIBILITY
2312 file_status __get_status(error_code *__ec = nullptr) const {
2313 switch (__data_.__cache_type_) {
2314 case _Empty:
2315 case _IterNonSymlink:
2316 case _IterSymlink:
2317 case _RefreshSymlinkUnresolved:
2318 return __status(__p_, __ec);
2319 case _RefreshNonSymlink:
2320 case _RefreshSymlink:
2321 return file_status(__get_ft(__ec), __data_.__non_sym_perms_);
2322 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002323 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002324 }
2325
2326 _LIBCPP_INLINE_VISIBILITY
2327 file_status __get_symlink_status(error_code *__ec = nullptr) const {
2328 switch (__data_.__cache_type_) {
2329 case _Empty:
2330 case _IterNonSymlink:
2331 case _IterSymlink:
2332 return __symlink_status(__p_, __ec);
2333 case _RefreshNonSymlink:
2334 return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_);
2335 case _RefreshSymlink:
2336 case _RefreshSymlinkUnresolved:
2337 return file_status(__get_sym_ft(__ec), __data_.__sym_perms_);
2338 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002339 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002340 }
2341
2342
2343 _LIBCPP_INLINE_VISIBILITY
2344 uintmax_t __get_size(error_code *__ec = nullptr) const {
2345 switch (__data_.__cache_type_) {
2346 case _Empty:
2347 case _IterNonSymlink:
2348 case _IterSymlink:
2349 case _RefreshSymlinkUnresolved:
2350 return _VSTD_FS::__file_size(__p_, __ec);
2351 case _RefreshSymlink:
2352 case _RefreshNonSymlink: {
2353 error_code __m_ec;
2354 file_status __st(__get_ft(&__m_ec));
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002355 __handle_error("in directory_entry::file_size", __ec, __m_ec);
Eric Fiselier70474082018-07-20 01:22:32 +00002356 if (_VSTD_FS::exists(__st) && !_VSTD_FS::is_regular_file(__st)) {
2357 errc __err_kind = _VSTD_FS::is_directory(__st) ? errc::is_a_directory
2358 : errc::not_supported;
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002359 __handle_error("in directory_entry::file_size", __ec,
Eric Fiselier70474082018-07-20 01:22:32 +00002360 make_error_code(__err_kind));
2361 }
2362 return __data_.__size_;
2363 }
2364 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002365 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002366 }
2367
2368 _LIBCPP_INLINE_VISIBILITY
2369 uintmax_t __get_nlink(error_code *__ec = nullptr) const {
2370 switch (__data_.__cache_type_) {
2371 case _Empty:
2372 case _IterNonSymlink:
2373 case _IterSymlink:
2374 case _RefreshSymlinkUnresolved:
2375 return _VSTD_FS::__hard_link_count(__p_, __ec);
2376 case _RefreshSymlink:
2377 case _RefreshNonSymlink: {
2378 error_code __m_ec;
2379 (void)__get_ft(&__m_ec);
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002380 __handle_error("in directory_entry::hard_link_count", __ec, __m_ec);
Eric Fiselier70474082018-07-20 01:22:32 +00002381 return __data_.__nlink_;
2382 }
2383 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002384 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002385 }
2386
2387 _LIBCPP_INLINE_VISIBILITY
2388 file_time_type __get_write_time(error_code *__ec = nullptr) const {
2389 switch (__data_.__cache_type_) {
2390 case _Empty:
2391 case _IterNonSymlink:
2392 case _IterSymlink:
2393 case _RefreshSymlinkUnresolved:
2394 return _VSTD_FS::__last_write_time(__p_, __ec);
2395 case _RefreshSymlink:
2396 case _RefreshNonSymlink: {
2397 error_code __m_ec;
2398 file_status __st(__get_ft(&__m_ec));
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002399 __handle_error("in directory_entry::last_write_time", __ec, __m_ec);
Eric Fiselier70474082018-07-20 01:22:32 +00002400 if (_VSTD_FS::exists(__st) &&
2401 __data_.__write_time_ == file_time_type::min())
Eric Fiseliera75bbde2018-07-23 02:00:52 +00002402 __handle_error("in directory_entry::last_write_time", __ec,
Eric Fiselier70474082018-07-20 01:22:32 +00002403 make_error_code(errc::value_too_large));
2404 return __data_.__write_time_;
2405 }
2406 }
Eric Fiselierb3b129c2018-07-20 01:44:33 +00002407 _LIBCPP_UNREACHABLE();
Eric Fiselier70474082018-07-20 01:22:32 +00002408 }
Eric Fiselier435db152016-06-17 19:46:40 +00002409private:
2410 _Path __p_;
Eric Fiselier70474082018-07-20 01:22:32 +00002411 __cached_data __data_;
Eric Fiselier435db152016-06-17 19:46:40 +00002412};
2413
Eric Fiselier435db152016-06-17 19:46:40 +00002414class __dir_element_proxy {
2415public:
2416
2417 inline _LIBCPP_INLINE_VISIBILITY
2418 directory_entry operator*() { return _VSTD::move(__elem_); }
2419
2420private:
2421 friend class directory_iterator;
2422 friend class recursive_directory_iterator;
2423 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
2424 __dir_element_proxy(__dir_element_proxy&& __o) : __elem_(_VSTD::move(__o.__elem_)) {}
2425 directory_entry __elem_;
2426};
2427
2428class directory_iterator
2429{
2430public:
2431 typedef directory_entry value_type;
2432 typedef ptrdiff_t difference_type;
2433 typedef value_type const* pointer;
2434 typedef value_type const& reference;
2435 typedef input_iterator_tag iterator_category;
2436
2437public:
2438 //ctor & dtor
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002439 directory_iterator() noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00002440 { }
2441
2442 explicit directory_iterator(const path& __p)
2443 : directory_iterator(__p, nullptr)
2444 { }
2445
2446 directory_iterator(const path& __p, directory_options __opts)
2447 : directory_iterator(__p, nullptr, __opts)
2448 { }
2449
Eric Fiselierd56d5322017-10-30 18:59:59 +00002450 directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002451 : directory_iterator(__p, &__ec)
2452 { }
2453
2454 directory_iterator(const path& __p, directory_options __opts,
Eric Fiselierd56d5322017-10-30 18:59:59 +00002455 error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002456 : directory_iterator(__p, &__ec, __opts)
2457 { }
2458
2459 directory_iterator(const directory_iterator&) = default;
2460 directory_iterator(directory_iterator&&) = default;
2461 directory_iterator& operator=(const directory_iterator&) = default;
2462
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002463 directory_iterator& operator=(directory_iterator&& __o) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002464 // non-default implementation provided to support self-move assign.
2465 if (this != &__o) {
2466 __imp_ = _VSTD::move(__o.__imp_);
2467 }
2468 return *this;
2469 }
2470
2471 ~directory_iterator() = default;
2472
2473 const directory_entry& operator*() const {
2474 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002475 return __dereference();
Eric Fiselier435db152016-06-17 19:46:40 +00002476 }
2477
2478 const directory_entry* operator->() const
2479 { return &**this; }
2480
2481 directory_iterator& operator++()
2482 { return __increment(); }
2483
2484 __dir_element_proxy operator++(int) {
2485 __dir_element_proxy __p(**this);
2486 __increment();
2487 return __p;
2488 }
2489
Eric Fiselierd56d5322017-10-30 18:59:59 +00002490 directory_iterator& increment(error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002491 { return __increment(&__ec); }
2492
2493private:
Eric Fiselier28175a32016-09-16 00:07:16 +00002494 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00002495 friend bool operator==(const directory_iterator& __lhs,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002496 const directory_iterator& __rhs) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +00002497
2498 // construct the dir_stream
2499 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002500 directory_iterator(const path&, error_code *,
2501 directory_options = directory_options::none);
2502
Eric Fiselier435db152016-06-17 19:46:40 +00002503 _LIBCPP_FUNC_VIS
2504 directory_iterator& __increment(error_code * __ec = nullptr);
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002505
Eric Fiselier435db152016-06-17 19:46:40 +00002506 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002507 const directory_entry& __dereference() const;
Eric Fiselier435db152016-06-17 19:46:40 +00002508
2509private:
2510 shared_ptr<__dir_stream> __imp_;
2511};
2512
2513
2514inline _LIBCPP_INLINE_VISIBILITY
2515bool operator==(const directory_iterator& __lhs,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002516 const directory_iterator& __rhs) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002517 return __lhs.__imp_ == __rhs.__imp_;
2518}
2519
2520inline _LIBCPP_INLINE_VISIBILITY
2521bool operator!=(const directory_iterator& __lhs,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002522 const directory_iterator& __rhs) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002523 return !(__lhs == __rhs);
2524}
2525
2526// enable directory_iterator range-based for statements
2527inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002528directory_iterator begin(directory_iterator __iter) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002529 return __iter;
2530}
2531
2532inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002533directory_iterator end(const directory_iterator&) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002534 return directory_iterator();
2535}
2536
2537class recursive_directory_iterator {
2538public:
2539 using value_type = directory_entry;
2540 using difference_type = std::ptrdiff_t;
2541 using pointer = directory_entry const *;
2542 using reference = directory_entry const &;
2543 using iterator_category = std::input_iterator_tag;
2544
2545public:
2546 // constructors and destructor
2547 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002548 recursive_directory_iterator() noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00002549 : __rec_(false)
2550 {}
2551
2552 _LIBCPP_INLINE_VISIBILITY
2553 explicit recursive_directory_iterator(const path& __p,
2554 directory_options __xoptions = directory_options::none)
2555 : recursive_directory_iterator(__p, __xoptions, nullptr)
2556 { }
2557
2558 _LIBCPP_INLINE_VISIBILITY
2559 recursive_directory_iterator(const path& __p,
Eric Fiselierd56d5322017-10-30 18:59:59 +00002560 directory_options __xoptions, error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002561 : recursive_directory_iterator(__p, __xoptions, &__ec)
2562 { }
2563
2564 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd56d5322017-10-30 18:59:59 +00002565 recursive_directory_iterator(const path& __p, error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002566 : recursive_directory_iterator(__p, directory_options::none, &__ec)
2567 { }
2568
2569 recursive_directory_iterator(const recursive_directory_iterator&) = default;
2570 recursive_directory_iterator(recursive_directory_iterator&&) = default;
2571
2572 recursive_directory_iterator &
2573 operator=(const recursive_directory_iterator&) = default;
2574
2575 _LIBCPP_INLINE_VISIBILITY
2576 recursive_directory_iterator &
2577 operator=(recursive_directory_iterator&& __o) noexcept {
2578 // non-default implementation provided to support self-move assign.
2579 if (this != &__o) {
2580 __imp_ = _VSTD::move(__o.__imp_);
2581 __rec_ = __o.__rec_;
2582 }
2583 return *this;
2584 }
2585
2586 ~recursive_directory_iterator() = default;
2587
2588 _LIBCPP_INLINE_VISIBILITY
2589 const directory_entry& operator*() const
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002590 { return __dereference(); }
Eric Fiselier435db152016-06-17 19:46:40 +00002591
2592 _LIBCPP_INLINE_VISIBILITY
2593 const directory_entry* operator->() const
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002594 { return &__dereference(); }
Eric Fiselier435db152016-06-17 19:46:40 +00002595
2596 recursive_directory_iterator& operator++()
2597 { return __increment(); }
2598
2599 _LIBCPP_INLINE_VISIBILITY
2600 __dir_element_proxy operator++(int) {
2601 __dir_element_proxy __p(**this);
2602 __increment();
2603 return __p;
2604 }
2605
2606 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd56d5322017-10-30 18:59:59 +00002607 recursive_directory_iterator& increment(error_code& __ec)
Eric Fiselier435db152016-06-17 19:46:40 +00002608 { return __increment(&__ec); }
2609
2610 _LIBCPP_FUNC_VIS directory_options options() const;
2611 _LIBCPP_FUNC_VIS int depth() const;
2612
2613 _LIBCPP_INLINE_VISIBILITY
2614 void pop() { __pop(); }
2615
2616 _LIBCPP_INLINE_VISIBILITY
2617 void pop(error_code& __ec)
2618 { __pop(&__ec); }
2619
2620 _LIBCPP_INLINE_VISIBILITY
2621 bool recursion_pending() const
2622 { return __rec_; }
2623
2624 _LIBCPP_INLINE_VISIBILITY
2625 void disable_recursion_pending()
2626 { __rec_ = false; }
2627
2628private:
2629 recursive_directory_iterator(const path& __p, directory_options __opt,
2630 error_code *__ec);
2631
2632 _LIBCPP_FUNC_VIS
Saleem Abdulrasoolfbb2d0e2017-01-30 00:15:47 +00002633 const directory_entry& __dereference() const;
Eric Fiselier435db152016-06-17 19:46:40 +00002634
2635 _LIBCPP_FUNC_VIS
2636 bool __try_recursion(error_code* __ec);
2637
2638 _LIBCPP_FUNC_VIS
2639 void __advance(error_code* __ec=nullptr);
2640
2641 _LIBCPP_FUNC_VIS
2642 recursive_directory_iterator& __increment(error_code *__ec=nullptr);
2643
2644 _LIBCPP_FUNC_VIS
2645 void __pop(error_code* __ec=nullptr);
2646
Eric Fiselier28175a32016-09-16 00:07:16 +00002647 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier435db152016-06-17 19:46:40 +00002648 friend bool operator==(const recursive_directory_iterator&,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002649 const recursive_directory_iterator&) noexcept;
Eric Fiselier435db152016-06-17 19:46:40 +00002650
2651 struct __shared_imp;
2652 shared_ptr<__shared_imp> __imp_;
2653 bool __rec_;
2654}; // class recursive_directory_iterator
2655
2656
Eric Fiselier28175a32016-09-16 00:07:16 +00002657inline _LIBCPP_INLINE_VISIBILITY
2658bool operator==(const recursive_directory_iterator& __lhs,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002659 const recursive_directory_iterator& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00002660{
2661 return __lhs.__imp_ == __rhs.__imp_;
2662}
2663
2664_LIBCPP_INLINE_VISIBILITY
2665inline bool operator!=(const recursive_directory_iterator& __lhs,
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002666 const recursive_directory_iterator& __rhs) noexcept
Eric Fiselier435db152016-06-17 19:46:40 +00002667{
2668 return !(__lhs == __rhs);
2669}
2670// enable recursive_directory_iterator range-based for statements
2671inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002672recursive_directory_iterator begin(recursive_directory_iterator __iter) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002673 return __iter;
2674}
2675
2676inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002677recursive_directory_iterator end(const recursive_directory_iterator&) noexcept {
Eric Fiselier435db152016-06-17 19:46:40 +00002678 return recursive_directory_iterator();
2679}
2680
2681_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM
2682
Eric Fiselierd7c4ec82018-07-25 03:41:31 +00002683#endif // !_LIBCPP_CXX03_LANG
2684
Eric Fiselier3ad58be2018-07-20 01:51:48 +00002685_LIBCPP_POP_MACROS
2686
Eric Fiselier435db152016-06-17 19:46:40 +00002687#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM