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