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