libstdc++
|
00001 // Filesystem declarations -*- C++ -*- 00002 00003 // Copyright (C) 2014-2019 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file include/bits/fs_fwd.h 00026 * This is an internal header file, included by other library headers. 00027 * Do not attempt to use it directly. @headername{filesystem} 00028 */ 00029 00030 #ifndef _GLIBCXX_FS_FWD_H 00031 #define _GLIBCXX_FS_FWD_H 1 00032 00033 #if __cplusplus >= 201703L 00034 00035 #include <system_error> 00036 #include <cstdint> 00037 #include <chrono> 00038 00039 namespace std _GLIBCXX_VISIBILITY(default) 00040 { 00041 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00042 00043 namespace filesystem 00044 { 00045 #if _GLIBCXX_USE_CXX11_ABI 00046 inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { } 00047 #endif 00048 00049 /** 00050 * @defgroup filesystem Filesystem 00051 * 00052 * Utilities for performing operations on file systems and their components, 00053 * such as paths, regular files, and directories. 00054 * 00055 * @{ 00056 */ 00057 00058 class file_status; 00059 _GLIBCXX_BEGIN_NAMESPACE_CXX11 00060 class path; 00061 class filesystem_error; 00062 class directory_entry; 00063 class directory_iterator; 00064 class recursive_directory_iterator; 00065 _GLIBCXX_END_NAMESPACE_CXX11 00066 00067 struct space_info 00068 { 00069 uintmax_t capacity; 00070 uintmax_t free; 00071 uintmax_t available; 00072 }; 00073 00074 enum class file_type : signed char { 00075 none = 0, not_found = -1, regular = 1, directory = 2, symlink = 3, 00076 block = 4, character = 5, fifo = 6, socket = 7, unknown = 8 00077 }; 00078 00079 /// Bitmask type 00080 enum class copy_options : unsigned short { 00081 none = 0, 00082 skip_existing = 1, overwrite_existing = 2, update_existing = 4, 00083 recursive = 8, 00084 copy_symlinks = 16, skip_symlinks = 32, 00085 directories_only = 64, create_symlinks = 128, create_hard_links = 256 00086 }; 00087 00088 constexpr copy_options 00089 operator&(copy_options __x, copy_options __y) noexcept 00090 { 00091 using __utype = typename std::underlying_type<copy_options>::type; 00092 return static_cast<copy_options>( 00093 static_cast<__utype>(__x) & static_cast<__utype>(__y)); 00094 } 00095 00096 constexpr copy_options 00097 operator|(copy_options __x, copy_options __y) noexcept 00098 { 00099 using __utype = typename std::underlying_type<copy_options>::type; 00100 return static_cast<copy_options>( 00101 static_cast<__utype>(__x) | static_cast<__utype>(__y)); 00102 } 00103 00104 constexpr copy_options 00105 operator^(copy_options __x, copy_options __y) noexcept 00106 { 00107 using __utype = typename std::underlying_type<copy_options>::type; 00108 return static_cast<copy_options>( 00109 static_cast<__utype>(__x) ^ static_cast<__utype>(__y)); 00110 } 00111 00112 constexpr copy_options 00113 operator~(copy_options __x) noexcept 00114 { 00115 using __utype = typename std::underlying_type<copy_options>::type; 00116 return static_cast<copy_options>(~static_cast<__utype>(__x)); 00117 } 00118 00119 inline copy_options& 00120 operator&=(copy_options& __x, copy_options __y) noexcept 00121 { return __x = __x & __y; } 00122 00123 inline copy_options& 00124 operator|=(copy_options& __x, copy_options __y) noexcept 00125 { return __x = __x | __y; } 00126 00127 inline copy_options& 00128 operator^=(copy_options& __x, copy_options __y) noexcept 00129 { return __x = __x ^ __y; } 00130 00131 00132 /// Bitmask type 00133 enum class perms : unsigned { 00134 none = 0, 00135 owner_read = 0400, 00136 owner_write = 0200, 00137 owner_exec = 0100, 00138 owner_all = 0700, 00139 group_read = 040, 00140 group_write = 020, 00141 group_exec = 010, 00142 group_all = 070, 00143 others_read = 04, 00144 others_write = 02, 00145 others_exec = 01, 00146 others_all = 07, 00147 all = 0777, 00148 set_uid = 04000, 00149 set_gid = 02000, 00150 sticky_bit = 01000, 00151 mask = 07777, 00152 unknown = 0xFFFF, 00153 }; 00154 00155 constexpr perms 00156 operator&(perms __x, perms __y) noexcept 00157 { 00158 using __utype = typename std::underlying_type<perms>::type; 00159 return static_cast<perms>( 00160 static_cast<__utype>(__x) & static_cast<__utype>(__y)); 00161 } 00162 00163 constexpr perms 00164 operator|(perms __x, perms __y) noexcept 00165 { 00166 using __utype = typename std::underlying_type<perms>::type; 00167 return static_cast<perms>( 00168 static_cast<__utype>(__x) | static_cast<__utype>(__y)); 00169 } 00170 00171 constexpr perms 00172 operator^(perms __x, perms __y) noexcept 00173 { 00174 using __utype = typename std::underlying_type<perms>::type; 00175 return static_cast<perms>( 00176 static_cast<__utype>(__x) ^ static_cast<__utype>(__y)); 00177 } 00178 00179 constexpr perms 00180 operator~(perms __x) noexcept 00181 { 00182 using __utype = typename std::underlying_type<perms>::type; 00183 return static_cast<perms>(~static_cast<__utype>(__x)); 00184 } 00185 00186 inline perms& 00187 operator&=(perms& __x, perms __y) noexcept 00188 { return __x = __x & __y; } 00189 00190 inline perms& 00191 operator|=(perms& __x, perms __y) noexcept 00192 { return __x = __x | __y; } 00193 00194 inline perms& 00195 operator^=(perms& __x, perms __y) noexcept 00196 { return __x = __x ^ __y; } 00197 00198 /// Bitmask type 00199 enum class perm_options : unsigned { 00200 replace = 0x1, 00201 add = 0x2, 00202 remove = 0x4, 00203 nofollow = 0x8 00204 }; 00205 00206 constexpr perm_options 00207 operator&(perm_options __x, perm_options __y) noexcept 00208 { 00209 using __utype = typename std::underlying_type<perm_options>::type; 00210 return static_cast<perm_options>( 00211 static_cast<__utype>(__x) & static_cast<__utype>(__y)); 00212 } 00213 00214 constexpr perm_options 00215 operator|(perm_options __x, perm_options __y) noexcept 00216 { 00217 using __utype = typename std::underlying_type<perm_options>::type; 00218 return static_cast<perm_options>( 00219 static_cast<__utype>(__x) | static_cast<__utype>(__y)); 00220 } 00221 00222 constexpr perm_options 00223 operator^(perm_options __x, perm_options __y) noexcept 00224 { 00225 using __utype = typename std::underlying_type<perm_options>::type; 00226 return static_cast<perm_options>( 00227 static_cast<__utype>(__x) ^ static_cast<__utype>(__y)); 00228 } 00229 00230 constexpr perm_options 00231 operator~(perm_options __x) noexcept 00232 { 00233 using __utype = typename std::underlying_type<perm_options>::type; 00234 return static_cast<perm_options>(~static_cast<__utype>(__x)); 00235 } 00236 00237 inline perm_options& 00238 operator&=(perm_options& __x, perm_options __y) noexcept 00239 { return __x = __x & __y; } 00240 00241 inline perm_options& 00242 operator|=(perm_options& __x, perm_options __y) noexcept 00243 { return __x = __x | __y; } 00244 00245 inline perm_options& 00246 operator^=(perm_options& __x, perm_options __y) noexcept 00247 { return __x = __x ^ __y; } 00248 00249 // Bitmask type 00250 enum class directory_options : unsigned char { 00251 none = 0, follow_directory_symlink = 1, skip_permission_denied = 2 00252 }; 00253 00254 constexpr directory_options 00255 operator&(directory_options __x, directory_options __y) noexcept 00256 { 00257 using __utype = typename std::underlying_type<directory_options>::type; 00258 return static_cast<directory_options>( 00259 static_cast<__utype>(__x) & static_cast<__utype>(__y)); 00260 } 00261 00262 constexpr directory_options 00263 operator|(directory_options __x, directory_options __y) noexcept 00264 { 00265 using __utype = typename std::underlying_type<directory_options>::type; 00266 return static_cast<directory_options>( 00267 static_cast<__utype>(__x) | static_cast<__utype>(__y)); 00268 } 00269 00270 constexpr directory_options 00271 operator^(directory_options __x, directory_options __y) noexcept 00272 { 00273 using __utype = typename std::underlying_type<directory_options>::type; 00274 return static_cast<directory_options>( 00275 static_cast<__utype>(__x) ^ static_cast<__utype>(__y)); 00276 } 00277 00278 constexpr directory_options 00279 operator~(directory_options __x) noexcept 00280 { 00281 using __utype = typename std::underlying_type<directory_options>::type; 00282 return static_cast<directory_options>(~static_cast<__utype>(__x)); 00283 } 00284 00285 inline directory_options& 00286 operator&=(directory_options& __x, directory_options __y) noexcept 00287 { return __x = __x & __y; } 00288 00289 inline directory_options& 00290 operator|=(directory_options& __x, directory_options __y) noexcept 00291 { return __x = __x | __y; } 00292 00293 inline directory_options& 00294 operator^=(directory_options& __x, directory_options __y) noexcept 00295 { return __x = __x ^ __y; } 00296 00297 struct __file_clock 00298 { 00299 using duration = chrono::nanoseconds; 00300 using rep = duration::rep; 00301 using period = duration::period; 00302 using time_point = chrono::time_point<__file_clock>; 00303 static constexpr bool is_steady = false; 00304 00305 static time_point 00306 now() noexcept 00307 { return _S_from_sys(chrono::system_clock::now()); } 00308 00309 private: 00310 using __sys_clock = chrono::system_clock; 00311 00312 // This clock's (unspecified) epoch is 2174-01-01 00:00:00 UTC. 00313 // A signed 64-bit duration with nanosecond resolution gives roughly 00314 // +/- 292 years, which covers the 1901-2446 date range for ext4. 00315 static constexpr chrono::seconds _S_epoch_diff{6437664000}; 00316 00317 protected: 00318 // For internal use only 00319 template<typename _Dur> 00320 static 00321 chrono::time_point<__file_clock, _Dur> 00322 _S_from_sys(const chrono::time_point<__sys_clock, _Dur>& __t) noexcept 00323 { 00324 using __file_time = chrono::time_point<__file_clock, _Dur>; 00325 return __file_time{__t.time_since_epoch()} - _S_epoch_diff; 00326 } 00327 00328 // For internal use only 00329 template<typename _Dur> 00330 static 00331 chrono::time_point<__sys_clock, _Dur> 00332 _S_to_sys(const chrono::time_point<__file_clock, _Dur>& __t) noexcept 00333 { 00334 using __sys_time = chrono::time_point<__sys_clock, _Dur>; 00335 return __sys_time{__t.time_since_epoch()} + _S_epoch_diff; 00336 } 00337 }; 00338 00339 using file_time_type = __file_clock::time_point; 00340 00341 // operational functions 00342 00343 void copy(const path& __from, const path& __to, copy_options __options); 00344 void copy(const path& __from, const path& __to, copy_options __options, 00345 error_code&); 00346 00347 bool copy_file(const path& __from, const path& __to, copy_options __option); 00348 bool copy_file(const path& __from, const path& __to, copy_options __option, 00349 error_code&); 00350 00351 path current_path(); 00352 00353 bool exists(file_status) noexcept; 00354 00355 bool is_other(file_status) noexcept; 00356 00357 uintmax_t file_size(const path&); 00358 uintmax_t file_size(const path&, error_code&) noexcept; 00359 uintmax_t hard_link_count(const path&); 00360 uintmax_t hard_link_count(const path&, error_code&) noexcept; 00361 file_time_type last_write_time(const path&); 00362 file_time_type last_write_time(const path&, error_code&) noexcept; 00363 00364 void permissions(const path&, perms, perm_options, error_code&) noexcept; 00365 00366 path proximate(const path& __p, const path& __base, error_code& __ec); 00367 path proximate(const path& __p, const path& __base, error_code& __ec); 00368 00369 path relative(const path& __p, const path& __base, error_code& __ec); 00370 00371 file_status status(const path&); 00372 file_status status(const path&, error_code&) noexcept; 00373 00374 bool status_known(file_status) noexcept; 00375 00376 file_status symlink_status(const path&); 00377 file_status symlink_status(const path&, error_code&) noexcept; 00378 00379 bool is_regular_file(file_status) noexcept; 00380 bool is_symlink(file_status) noexcept; 00381 00382 // @} group filesystem 00383 } // namespace filesystem 00384 00385 _GLIBCXX_END_NAMESPACE_VERSION 00386 } // namespace std 00387 00388 #endif // C++17 00389 00390 #endif // _GLIBCXX_FS_FWD_H