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