45#ifndef GHC_FILESYSTEM_H
46#define GHC_FILESYSTEM_H
54#ifndef GHC_OS_DETECTED
55#if defined(__APPLE__) && defined(__MACH__)
57#elif defined(__linux__)
59#if defined(__ANDROID__)
68#elif defined(__CYGWIN__)
70#elif defined(__sun) && defined(__SVR4)
72#elif defined(__svr4__)
76#elif defined(__EMSCRIPTEN__)
82#error "Operating system currently not supported!"
84#define GHC_OS_DETECTED
85#if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
86#if _MSVC_LANG == 201703L
87#define GHC_FILESYSTEM_RUNNING_CPP17
89#define GHC_FILESYSTEM_RUNNING_CPP20
91#elif (defined(__cplusplus) && __cplusplus >= 201703L)
92#if __cplusplus == 201703L
93#define GHC_FILESYSTEM_RUNNING_CPP17
95#define GHC_FILESYSTEM_RUNNING_CPP20
100#if defined(GHC_FILESYSTEM_IMPLEMENTATION)
101#define GHC_EXPAND_IMPL
107#ifndef GHC_FS_API_CLASS
108#define GHC_FS_API_CLASS
112#define GHC_FS_API __attribute__((visibility("default")))
114#ifndef GHC_FS_API_CLASS
115#define GHC_FS_API_CLASS __attribute__((visibility("default")))
118#elif defined(GHC_FILESYSTEM_FWD)
122#define GHC_FS_API extern
124#ifndef GHC_FS_API_CLASS
125#define GHC_FS_API_CLASS
129#define GHC_FS_API extern
131#ifndef GHC_FS_API_CLASS
132#define GHC_FS_API_CLASS
136#define GHC_EXPAND_IMPL
137#define GHC_INLINE inline
141#ifndef GHC_FS_API_CLASS
142#define GHC_FS_API_CLASS
146#ifdef GHC_EXPAND_IMPL
153#include <sys/types.h>
160#include <sys/param.h>
163#include <sys/types.h>
166#include <android/api-level.h>
167#if __ANDROID_API__ < 12
168#include <sys/syscall.h>
171#define statvfs statfs
173#include <sys/statvfs.h>
178#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
183#include <Availability.h>
186#if defined(__cpp_impl_three_way_comparison) && defined(__has_include)
187#if __has_include(<compare>)
188#define GHC_HAS_THREEWAY_COMP
205#include <system_error>
206#include <type_traits>
212#if defined(__cpp_impl_three_way_comparison) && defined(__has_include)
213#if __has_include(<compare>)
214#define GHC_HAS_THREEWAY_COMP
224#include <system_error>
232#if defined(__cpp_lib_string_view)
233#define GHC_HAS_STD_STRING_VIEW
234#elif defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION >= 4000) && (__cplusplus >= 201402)
235#define GHC_HAS_STD_STRING_VIEW
236#elif defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE >= 7) && (__cplusplus >= 201703)
237#define GHC_HAS_STD_STRING_VIEW
238#elif defined(_MSC_VER) && (_MSC_VER >= 1910 && _MSVC_LANG >= 201703)
239#define GHC_HAS_STD_STRING_VIEW
243#if defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION >= 3700 && _LIBCPP_VERSION < 7000) && (__cplusplus >= 201402)
244#define GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW
245#elif defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4)) && (__cplusplus >= 201402)
246#define GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW
247#elif defined(__GLIBCXX__) && defined(_GLIBCXX_USE_DUAL_ABI) && (__cplusplus >= 201402)
249#define GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW
252#if defined(GHC_HAS_STD_STRING_VIEW)
253#include <string_view>
254#elif defined(GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW)
255#include <experimental/string_view>
258#if !defined(GHC_OS_WINDOWS) && !defined(PATH_MAX)
271#define LWG_2682_BEHAVIOUR
284#define LWG_2936_BEHAVIOUR
287#define LWG_2937_BEHAVIOUR
303#ifndef GHC_WIN_DISABLE_AUTO_PREFIXES
304#define GHC_WIN_AUTO_PREFIX_LONG_PATH
309#define GHC_FILESYSTEM_VERSION 10512L
311#if !defined(GHC_WITH_EXCEPTIONS) && (defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND))
312#define GHC_WITH_EXCEPTIONS
314#if !defined(GHC_WITH_EXCEPTIONS) && defined(GHC_RAISE_UNICODE_ERRORS)
315#error "Can't raise unicode errors with exception support disabled"
319namespace filesystem {
321#if defined(GHC_HAS_CUSTOM_STRING_VIEW)
322#define GHC_WITH_STRING_VIEW
323#elif defined(GHC_HAS_STD_STRING_VIEW)
324#define GHC_WITH_STRING_VIEW
325using std::basic_string_view;
326#elif defined(GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW)
327#define GHC_WITH_STRING_VIEW
328using std::experimental::basic_string_view;
336 : std::logic_error(
"function not implemented yet.")
341template <
typename char_type>
353#if __cplusplus < 201703L
354template <
typename char_type>
361bool has_executable_extension(
const path& p);
367#if defined(GHC_OS_WINDOWS) && !defined(GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE)
368#define GHC_USE_WCHAR_T
369#define GHC_NATIVEWP(p) p.c_str()
370#define GHC_PLATFORM_LITERAL(str) L##str
376#define GHC_NATIVEWP(p) p.wstring().c_str()
377#define GHC_PLATFORM_LITERAL(str) str
400 template <
class CharT,
class Traits,
class Alloc>
404 template <
class CharT>
405 struct _is_basic_string<std::basic_string<CharT, std::char_traits<CharT>, std::allocator<CharT>>> : std::true_type
408#ifdef GHC_WITH_STRING_VIEW
409 template <
class CharT,
class Traits>
413 template <
class CharT>
414 struct _is_basic_string<basic_string_view<CharT, std::char_traits<CharT>>> : std::true_type
419 template <
typename T1,
typename T2 =
void>
420 using path_type =
typename std::enable_if<!std::is_same<path, T1>::value,
path>::type;
421 template <
typename T>
422#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API)
424 typename std::enable_if<_is_basic_string<T>::value || std::is_same<char const*, typename std::decay<T>::type>::value || std::is_same<char*, typename std::decay<T>::type>::value || std::is_same<char8_t const*, typename std::decay<T>::type>::value ||
425 std::is_same<char8_t*, typename std::decay<T>::type>::value || std::is_same<char16_t const*, typename std::decay<T>::type>::value || std::is_same<char16_t*, typename std::decay<T>::type>::value ||
426 std::is_same<char32_t const*, typename std::decay<T>::type>::value || std::is_same<char32_t*, typename std::decay<T>::type>::value || std::is_same<wchar_t const*, typename std::decay<T>::type>::value ||
427 std::is_same<wchar_t*, typename std::decay<T>::type>::value,
429 template <
typename T>
430 using path_type_EcharT =
typename std::enable_if<std::is_same<T, char>::value || std::is_same<T, char8_t>::value || std::is_same<T, char16_t>::value || std::is_same<T, char32_t>::value || std::is_same<T, wchar_t>::value,
path>::type;
433 typename std::enable_if<_is_basic_string<T>::value || std::is_same<char const*, typename std::decay<T>::type>::value || std::is_same<char*, typename std::decay<T>::type>::value ||
434 std::is_same<char16_t const*, typename std::decay<T>::type>::value || std::is_same<char16_t*, typename std::decay<T>::type>::value || std::is_same<char32_t const*, typename std::decay<T>::type>::value ||
435 std::is_same<char32_t*, typename std::decay<T>::type>::value || std::is_same<wchar_t const*, typename std::decay<T>::type>::value || std::is_same<wchar_t*, typename std::decay<T>::type>::value,
437 template <
typename T>
438 using path_type_EcharT =
typename std::enable_if<std::is_same<T, char>::value || std::is_same<T, char16_t>::value || std::is_same<T, char32_t>::value || std::is_same<T, wchar_t>::value,
path>::type;
446 path(const Source& source,
format fmt = auto_format);
447 template <class InputIterator>
448 path(InputIterator first, InputIterator last,
format fmt = auto_format);
449#ifdef GHC_WITH_EXCEPTIONS
450 template <
class Source,
typename = path_from_
string<Source>>
451 path(
const Source& source,
const std::locale& loc,
format fmt = auto_format);
452 template <
class InputIterator>
453 path(InputIterator first, InputIterator last,
const std::locale& loc,
format fmt = auto_format);
462 template <
class Source>
463 path& operator=(
const Source& source);
464 template <
class Source>
465 path& assign(
const Source& source);
466 template <
class InputIterator>
467 path& assign(InputIterator first, InputIterator last);
471 template <
class Source>
472 path& operator/=(
const Source& source);
473 template <
class Source>
474 path& append(
const Source& source);
475 template <
class InputIterator>
476 path& append(InputIterator first, InputIterator last);
481#ifdef GHC_WITH_STRING_VIEW
482 path& operator+=(basic_string_view<value_type> x);
484 path& operator+=(
const value_type* x);
485 path& operator+=(value_type x);
486 template <
class Source>
488 template <
class E
charT>
490 template <
class Source>
491 path& concat(
const Source& x);
492 template <
class InputIterator>
493 path& concat(InputIterator first, InputIterator last);
496 void clear() noexcept;
497 path& make_preferred();
498 path& remove_filename();
499 path& replace_filename(const
path& replacement);
500 path& replace_extension(const
path& replacement =
path());
505 const value_type* c_str() const noexcept;
507 template <class EcharT, class traits = std::char_traits<EcharT>, class Allocator = std::allocator<EcharT>>
508 std::basic_string<EcharT, traits, Allocator>
string(const Allocator& a = Allocator()) const;
509 std::
string string() const;
510 std::wstring wstring() const;
511#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API)
512 std::u8string u8string()
const;
514 std::string u8string()
const;
516 std::u16string u16string()
const;
517 std::u32string u32string()
const;
520 template <
class E
charT,
class traits = std::
char_traits<E
charT>,
class Allocator = std::allocator<E
charT>>
521 std::basic_string<EcharT, traits, Allocator> generic_string(
const Allocator& a = Allocator())
const;
522 std::string generic_string()
const;
523 std::wstring generic_wstring()
const;
524#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API)
525 std::u8string generic_u8string()
const;
527 std::string generic_u8string()
const;
529 std::u16string generic_u16string()
const;
530 std::u32string generic_u32string()
const;
533 int compare(
const path& p)
const noexcept;
535#ifdef GHC_WITH_STRING_VIEW
536 int compare(basic_string_view<value_type> s)
const;
538 int compare(
const value_type* s)
const;
541 path root_name()
const;
542 path root_directory()
const;
543 path root_path()
const;
544 path relative_path()
const;
545 path parent_path()
const;
546 path filename()
const;
548 path extension()
const;
551 bool empty() const noexcept;
552 bool has_root_name() const;
553 bool has_root_directory() const;
554 bool has_root_path() const;
555 bool has_relative_path() const;
556 bool has_parent_path() const;
557 bool has_filename() const;
558 bool has_stem() const;
559 bool has_extension() const;
560 bool is_absolute() const;
561 bool is_relative() const;
564 path lexically_normal() const;
565 path lexically_relative(const
path& base) const;
566 path lexically_proximate(const
path& base) const;
575 using impl_value_type = value_type;
576 using impl_string_type = std::basic_string<impl_value_type>;
578 void append_name(const value_type* name);
579 static constexpr impl_value_type generic_separator = '/';
580 template <typename InputIterator>
581 class input_iterator_range
586 typedef typename InputIterator::difference_type difference_type;
588 input_iterator_range(
const InputIterator& first,
const InputIterator& last)
594 InputIterator
begin()
const {
return _first; }
595 InputIterator
end()
const {
return _last; }
598 InputIterator _first;
605 string_type::size_type root_name_length() const noexcept;
606 void postprocess_path_with_format(format fmt);
607 void check_long_path();
608 impl_string_type _path;
610 void handle_prefixes();
611 friend bool detail::has_executable_extension(
const path& p);
612#ifdef GHC_WIN_AUTO_PREFIX_LONG_PATH
613 string_type::size_type _prefixLength{0};
615 static const string_type::size_type _prefixLength{0};
618 static const string_type::size_type _prefixLength{0};
625#ifdef GHC_HAS_THREEWAY_COMP
626GHC_FS_API std::strong_ordering operator<=>(
const path& lhs,
const path& rhs)
noexcept;
637template <
class charT,
class traits>
638std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os,
const path& p);
639template <
class charT,
class traits>
640std::basic_istream<charT, traits>&
operator>>(std::basic_istream<charT, traits>& is, path& p);
643template <
class Source,
typename = path::path_from_
string<Source>>
644#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API)
645[[deprecated(
"use ghc::filesystem::path::path() with std::u8string instead")]]
647path
u8path(
const Source& source);
648template <
class InputIterator>
649#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API)
650[[deprecated(
"use ghc::filesystem::path::path() with std::u8string instead")]]
652path
u8path(InputIterator first, InputIterator last);
661 const path& path1()
const noexcept;
662 const path& path2()
const noexcept;
663 const char* what()
const noexcept override;
666 std::string _what_arg;
681 iterator(
const path& p,
const impl_string_type::const_iterator& pos);
693 impl_string_type::const_iterator increment(
const impl_string_type::const_iterator& pos)
const;
694 impl_string_type::const_iterator decrement(
const impl_string_type::const_iterator& pos)
const;
695 void updateCurrent();
696 impl_string_type::const_iterator _first;
697 impl_string_type::const_iterator _last;
698 impl_string_type::const_iterator _prefix;
699 impl_string_type::const_iterator _root;
700 impl_string_type::const_iterator _iter;
825#ifdef GHC_WITH_EXCEPTIONS
836#ifdef GHC_WITH_EXCEPTIONS
837 void assign(
const path& p);
838 void replace_filename(
const path& p);
841 void assign(
const path& p, std::error_code& ec);
842 void replace_filename(
const path& p, std::error_code& ec);
843 void refresh(std::error_code& ec)
noexcept;
847 operator const filesystem::
path&() const noexcept;
848#ifdef GHC_WITH_EXCEPTIONS
863 bool exists(std::error_code& ec)
const noexcept;
867 bool is_fifo(std::error_code& ec)
const noexcept;
868 bool is_other(std::error_code& ec)
const noexcept;
870 bool is_socket(std::error_code& ec)
const noexcept;
871 bool is_symlink(std::error_code& ec)
const noexcept;
872 uintmax_t
file_size(std::error_code& ec)
const noexcept;
878#ifdef GHC_WITH_EXCEPTIONS
884#ifdef GHC_HAS_THREEWAY_COMP
885 std::strong_ordering operator<=>(
const directory_entry& rhs)
const noexcept;
896#ifdef GHC_WITH_EXCEPTIONS
899 file_type status_file_type(std::error_code& ec)
const noexcept;
903 uintmax_t _file_size =
static_cast<uintmax_t
>(-1);
904#ifndef GHC_OS_WINDOWS
905 uintmax_t _hard_link_count =
static_cast<uintmax_t
>(-1);
907 time_t _last_write_time = 0;
922 : _dir_entry(dir_entry)
937#ifdef GHC_WITH_EXCEPTIONS
950#ifdef GHC_WITH_EXCEPTIONS
956#ifdef GHC_WITH_EXCEPTIONS
957 proxy operator++(
int)
964 bool operator==(
const directory_iterator& rhs)
const;
965 bool operator!=(
const directory_iterator& rhs)
const;
970 std::shared_ptr<impl> _impl;
989#ifdef GHC_WITH_EXCEPTIONS
1002 bool recursion_pending()
const;
1010#ifdef GHC_WITH_EXCEPTIONS
1015#ifdef GHC_WITH_EXCEPTIONS
1018 void pop(std::error_code& ec);
1019 void disable_recursion_pending();
1022#ifdef GHC_WITH_EXCEPTIONS
1030 bool operator==(
const recursive_directory_iterator& rhs)
const;
1031 bool operator!=(
const recursive_directory_iterator& rhs)
const;
1034 struct recursive_directory_iterator_impl
1036 directory_options _options;
1037 bool _recursion_pending;
1038 std::stack<directory_iterator> _dir_iter_stack;
1039 recursive_directory_iterator_impl(directory_options options,
bool recursion_pending)
1041 , _recursion_pending(recursion_pending)
1045 std::shared_ptr<recursive_directory_iterator_impl> _impl;
1049GHC_FS_API recursive_directory_iterator
begin(recursive_directory_iterator iter)
noexcept;
1050GHC_FS_API recursive_directory_iterator
end(
const recursive_directory_iterator&)
noexcept;
1053#ifdef GHC_WITH_EXCEPTIONS
1098GHC_FS_API void copy(
const path& from,
const path& to, std::error_code& ec)
noexcept;
1102GHC_FS_API void copy_symlink(
const path& existing_symlink,
const path& new_symlink, std::error_code& ec)
noexcept;
1152#ifdef GHC_WITH_EXCEPTIONS
1161template <
class charT,
class traits = std::
char_traits<
charT>>
1171#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
1172 return std::basic_filebuf<charT, traits>::open(p.
wstring().c_str(), mode) ? this : 0;
1174 return std::basic_filebuf<charT, traits>::open(p.
string().c_str(), mode) ? this : 0;
1179template <
class charT,
class traits = std::
char_traits<
charT>>
1184#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
1185 explicit basic_ifstream(
const path& p, std::ios_base::openmode mode = std::ios_base::in)
1189 void open(
const path& p, std::ios_base::openmode mode = std::ios_base::in) { std::basic_ifstream<charT, traits>::open(p.wstring().c_str(), mode); }
1195 void open(
const path& p, std::ios_base::openmode mode = std::ios_base::in) { std::basic_ifstream<charT, traits>::open(p.
string().c_str(), mode); }
1202template <
class charT,
class traits = std::
char_traits<
charT>>
1207#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
1208 explicit basic_ofstream(
const path& p, std::ios_base::openmode mode = std::ios_base::out)
1212 void open(
const path& p, std::ios_base::openmode mode = std::ios_base::out) { std::basic_ofstream<charT, traits>::open(p.wstring().c_str(), mode); }
1218 void open(
const path& p, std::ios_base::openmode mode = std::ios_base::out) { std::basic_ofstream<charT, traits>::open(p.
string().c_str(), mode); }
1225template <
class charT,
class traits = std::
char_traits<
charT>>
1230#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
1231 explicit basic_fstream(
const path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
1232 : std::
basic_fstream<charT, traits>(p.wstring().c_str(), mode)
1235 void open(
const path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) { std::basic_fstream<charT, traits>::open(p.wstring().c_str(), mode); }
1237 explicit basic_fstream(
const path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
1238 : std::
basic_fstream<charT, traits>(p.string().c_str(), mode)
1241 void open(
const path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) { std::basic_fstream<charT, traits>::open(p.
string().c_str(), mode); }
1275#ifdef GHC_OS_WINDOWS
1276 std::vector<std::string> _args;
1277 std::vector<char*> _argp;
1302#ifdef GHC_OS_WINDOWS
1307template <
typename T,
typename =
int>
1310template <
typename T>
1311struct has_d_type<T, decltype((void)T::d_type, 0)> : std::true_type {};
1313template <
typename T>
1319template <
typename T>
1370#ifdef GHC_EXPAND_IMPL
1374#ifdef GHC_OS_WINDOWS
1377 return std::error_code();
1379 return std::error_code(ERROR_ALREADY_EXISTS, std::system_category());
1381 return std::error_code(ERROR_PATH_NOT_FOUND, std::system_category());
1383 return std::error_code(ERROR_NOT_SUPPORTED, std::system_category());
1385 return std::error_code(ERROR_CALL_NOT_IMPLEMENTED, std::system_category());
1387 return std::error_code(ERROR_INVALID_PARAMETER, std::system_category());
1389#ifdef ERROR_DIRECTORY_NOT_SUPPORTED
1390 return std::error_code(ERROR_DIRECTORY_NOT_SUPPORTED, std::system_category());
1392 return std::error_code(ERROR_NOT_SUPPORTED, std::system_category());
1398 return std::error_code();
1400 return std::error_code(EEXIST, std::system_category());
1402 return std::error_code(ENOENT, std::system_category());
1404 return std::error_code(ENOTSUP, std::system_category());
1406 return std::error_code(ENOSYS, std::system_category());
1408 return std::error_code(EINVAL, std::system_category());
1410 return std::error_code(EISDIR, std::system_category());
1413 return std::error_code();
1416#ifdef GHC_OS_WINDOWS
1419 return std::error_code(err ?
static_cast<int>(err) : static_cast<int>(::GetLastError()), std::system_category());
1424 return std::error_code(err ? err : errno, std::system_category());
1430template <
typename Enum>
1431using EnableBitmask =
typename std::enable_if<std::is_same<Enum, perms>::value || std::is_same<Enum, perm_options>::value || std::is_same<Enum, copy_options>::value || std::is_same<Enum, directory_options>::value, Enum>::type;
1434template <
typename Enum>
1437 using underlying =
typename std::underlying_type<Enum>::type;
1438 return static_cast<Enum
>(
static_cast<underlying
>(X) &
static_cast<underlying
>(Y));
1441template <
typename Enum>
1444 using underlying =
typename std::underlying_type<Enum>::type;
1445 return static_cast<Enum
>(
static_cast<underlying
>(X) |
static_cast<underlying
>(Y));
1448template <
typename Enum>
1451 using underlying =
typename std::underlying_type<Enum>::type;
1452 return static_cast<Enum
>(
static_cast<underlying
>(X) ^
static_cast<underlying
>(Y));
1455template <
typename Enum>
1458 using underlying =
typename std::underlying_type<Enum>::type;
1459 return static_cast<Enum
>(~static_cast<underlying>(X));
1462template <
typename Enum>
1469template <
typename Enum>
1476template <
typename Enum>
1483#ifdef GHC_EXPAND_IMPL
1489 return (
static_cast<uint32_t
>(c - lo) < (hi - lo + 1));
1494 return in_range(c, 0xd800, 0xdfff);
1499 return (c & 0xfffffc00) == 0xd800;
1504 return (c & 0xfffffc00) == 0xdc00;
1509 if (unicode <= 0x7f) {
1510 str.push_back(
static_cast<char>(unicode));
1512 else if (unicode >= 0x80 && unicode <= 0x7ff) {
1513 str.push_back(
static_cast<char>((unicode >> 6) + 192));
1514 str.push_back(
static_cast<char>((unicode & 0x3f) + 128));
1516 else if ((unicode >= 0x800 && unicode <= 0xd7ff) || (unicode >= 0xe000 && unicode <= 0xffff)) {
1517 str.push_back(
static_cast<char>((unicode >> 12) + 224));
1518 str.push_back(
static_cast<char>(((unicode & 0xfff) >> 6) + 128));
1519 str.push_back(
static_cast<char>((unicode & 0x3f) + 128));
1521 else if (unicode >= 0x10000 && unicode <= 0x10ffff) {
1522 str.push_back(
static_cast<char>((unicode >> 18) + 240));
1523 str.push_back(
static_cast<char>(((unicode & 0x3ffff) >> 12) + 128));
1524 str.push_back(
static_cast<char>(((unicode & 0xfff) >> 6) + 128));
1525 str.push_back(
static_cast<char>((unicode & 0x3f) + 128));
1528#ifdef GHC_RAISE_UNICODE_ERRORS
1529 throw filesystem_error(
"Illegal code point for unicode character.", str, std::make_error_code(std::errc::illegal_byte_sequence));
1541 static const uint32_t utf8_state_info[] = {
1543 0x11111111u, 0x11111111u, 0x77777777u, 0x77777777u, 0x88888888u, 0x88888888u, 0x88888888u, 0x88888888u, 0x22222299u, 0x22222222u, 0x22222222u, 0x22222222u, 0x3333333au, 0x33433333u, 0x9995666bu, 0x99999999u,
1544 0x88888880u, 0x22818108u, 0x88888881u, 0x88888882u, 0x88888884u, 0x88888887u, 0x88888886u, 0x82218108u, 0x82281108u, 0x88888888u, 0x88888883u, 0x88888885u, 0u, 0u, 0u, 0u,
1546 uint8_t category = fragment < 128 ? 0 : (utf8_state_info[(fragment >> 3) & 0xf] >> ((fragment & 7) << 2)) & 0xf;
1547 codepoint = (state ? (codepoint << 6) | (fragment & 0x3fu) : (0xffu >> category) & fragment);
1548 return state ==
S_RJCT ?
static_cast<unsigned>(
S_RJCT) :
static_cast<unsigned>((utf8_state_info[category + 16] >> (state << 2)) & 0xf);
1553 std::string::const_iterator iter = utf8String.begin();
1554 unsigned utf8_state =
S_STRT;
1555 std::uint32_t codepoint = 0;
1556 while (iter < utf8String.end()) {
1573template <class StringType, class Utf8String, typename std::enable_if<path::_is_basic_string<Utf8String>::value && (
sizeof(
typename Utf8String::value_type) == 1) && (
sizeof(
typename StringType::value_type) == 1)>::type* =
nullptr>
1574inline StringType
fromUtf8(
const Utf8String& utf8String,
const typename StringType::allocator_type& alloc =
typename StringType::allocator_type())
1576 return StringType(utf8String.begin(), utf8String.end(), alloc);
1579template <class StringType, class Utf8String, typename std::enable_if<path::_is_basic_string<Utf8String>::value && (
sizeof(
typename Utf8String::value_type) == 1) && (
sizeof(
typename StringType::value_type) == 2)>::type* =
nullptr>
1580inline StringType
fromUtf8(
const Utf8String& utf8String,
const typename StringType::allocator_type& alloc =
typename StringType::allocator_type())
1582 StringType result(alloc);
1583 result.reserve(utf8String.length());
1584 auto iter = utf8String.cbegin();
1585 unsigned utf8_state =
S_STRT;
1586 std::uint32_t codepoint = 0;
1587 while (iter < utf8String.cend()) {
1589 if (codepoint <= 0xffff) {
1590 result +=
static_cast<typename StringType::value_type
>(codepoint);
1593 codepoint -= 0x10000;
1594 result +=
static_cast<typename StringType::value_type
>((codepoint >> 10) + 0xd800);
1595 result +=
static_cast<typename StringType::value_type
>((codepoint & 0x3ff) + 0xdc00);
1599 else if (utf8_state ==
S_RJCT) {
1600#ifdef GHC_RAISE_UNICODE_ERRORS
1601 throw filesystem_error(
"Illegal byte sequence for unicode character.", utf8String, std::make_error_code(std::errc::illegal_byte_sequence));
1603 result +=
static_cast<typename StringType::value_type
>(0xfffd);
1610#ifdef GHC_RAISE_UNICODE_ERRORS
1611 throw filesystem_error(
"Illegal byte sequence for unicode character.", utf8String, std::make_error_code(std::errc::illegal_byte_sequence));
1613 result +=
static_cast<typename StringType::value_type
>(0xfffd);
1619template <class StringType, class Utf8String, typename std::enable_if<path::_is_basic_string<Utf8String>::value && (
sizeof(
typename Utf8String::value_type) == 1) && (
sizeof(
typename StringType::value_type) == 4)>::type* =
nullptr>
1620inline StringType
fromUtf8(
const Utf8String& utf8String,
const typename StringType::allocator_type& alloc =
typename StringType::allocator_type())
1622 StringType result(alloc);
1623 result.reserve(utf8String.length());
1624 auto iter = utf8String.cbegin();
1625 unsigned utf8_state =
S_STRT;
1626 std::uint32_t codepoint = 0;
1627 while (iter < utf8String.cend()) {
1629 result +=
static_cast<typename StringType::value_type
>(codepoint);
1632 else if (utf8_state ==
S_RJCT) {
1633#ifdef GHC_RAISE_UNICODE_ERRORS
1634 throw filesystem_error(
"Illegal byte sequence for unicode character.", utf8String, std::make_error_code(std::errc::illegal_byte_sequence));
1636 result +=
static_cast<typename StringType::value_type
>(0xfffd);
1643#ifdef GHC_RAISE_UNICODE_ERRORS
1644 throw filesystem_error(
"Illegal byte sequence for unicode character.", utf8String, std::make_error_code(std::errc::illegal_byte_sequence));
1646 result +=
static_cast<typename StringType::value_type
>(0xfffd);
1652template <
class StringType,
typename charT, std::
size_t N>
1653inline StringType
fromUtf8(
const charT (&utf8String)[N])
1655#ifdef GHC_WITH_STRING_VIEW
1656 return fromUtf8<StringType>(basic_string_view<charT>(utf8String, N - 1));
1658 return fromUtf8<StringType>(std::basic_string<charT>(utf8String, N - 1));
1662template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value && (
sizeof(
typename strT::value_type) == 1),
int>::type size = 1>
1663inline std::string
toUtf8(
const strT& unicodeString)
1665 return std::string(unicodeString.begin(), unicodeString.end());
1668template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value && (
sizeof(
typename strT::value_type) == 2),
int>::type size = 2>
1669inline std::string
toUtf8(
const strT& unicodeString)
1672 for (
auto iter = unicodeString.begin(); iter != unicodeString.end(); ++iter) {
1677 appendUTF8(result, (
char32_t(c) << 10) + *iter - 0x35fdc00);
1680#ifdef GHC_RAISE_UNICODE_ERRORS
1681 throw filesystem_error(
"Illegal code point for unicode character.", result, std::make_error_code(std::errc::illegal_byte_sequence));
1684 if (iter == unicodeString.end()) {
1697template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value && (
sizeof(
typename strT::value_type) == 4),
int>::type size = 4>
1698inline std::string
toUtf8(
const strT& unicodeString)
1701 for (
auto c : unicodeString) {
1702 appendUTF8(result,
static_cast<uint32_t
>(c));
1707template <
typename charT>
1708inline std::string
toUtf8(
const charT* unicodeString)
1710#ifdef GHC_WITH_STRING_VIEW
1711 return toUtf8(basic_string_view<charT, std::char_traits<charT>>(unicodeString));
1713 return toUtf8(std::basic_string<charT, std::char_traits<charT>>(unicodeString));
1717#ifdef GHC_USE_WCHAR_T
1718template <class StringType, class WString, typename std::enable_if<path::_is_basic_string<WString>::value && (
sizeof(
typename WString::value_type) == 2) && (
sizeof(
typename StringType::value_type) == 1),
bool>::type =
false>
1719inline StringType fromWChar(
const WString& wString,
const typename StringType::allocator_type& alloc =
typename StringType::allocator_type())
1721 auto temp =
toUtf8(wString);
1722 return StringType(temp.begin(), temp.end(), alloc);
1725template <class StringType, class WString, typename std::enable_if<path::_is_basic_string<WString>::value && (
sizeof(
typename WString::value_type) == 2) && (
sizeof(
typename StringType::value_type) == 2),
bool>::type =
false>
1726inline StringType fromWChar(
const WString& wString,
const typename StringType::allocator_type& alloc =
typename StringType::allocator_type())
1728 return StringType(wString.begin(), wString.end(), alloc);
1731template <class StringType, class WString, typename std::enable_if<path::_is_basic_string<WString>::value && (
sizeof(
typename WString::value_type) == 2) && (
sizeof(
typename StringType::value_type) == 4),
bool>::type =
false>
1732inline StringType fromWChar(
const WString& wString,
const typename StringType::allocator_type& alloc =
typename StringType::allocator_type())
1734 auto temp =
toUtf8(wString);
1735 return fromUtf8<StringType>(temp, alloc);
1738template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value && (
sizeof(
typename strT::value_type) == 1),
bool>::type =
false>
1739inline std::wstring toWChar(
const strT& unicodeString)
1741 return fromUtf8<std::wstring>(unicodeString);
1744template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value && (
sizeof(
typename strT::value_type) == 2),
bool>::type =
false>
1745inline std::wstring toWChar(
const strT& unicodeString)
1747 return std::wstring(unicodeString.begin(), unicodeString.end());
1750template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value && (
sizeof(
typename strT::value_type) == 4),
bool>::type =
false>
1751inline std::wstring toWChar(
const strT& unicodeString)
1753 auto temp =
toUtf8(unicodeString);
1754 return fromUtf8<std::wstring>(temp);
1757template <
typename charT>
1758inline std::wstring toWChar(
const charT* unicodeString)
1760#ifdef GHC_WITH_STRING_VIEW
1761 return toWChar(basic_string_view<charT, std::char_traits<charT>>(unicodeString));
1763 return toWChar(std::basic_string<charT, std::char_traits<charT>>(unicodeString));
1770#ifdef GHC_EXPAND_IMPL
1774template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value,
bool>::type =
true>
1777 return with.length() <= what.length() && equal(with.begin(), with.end(), what.begin());
1780template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value,
bool>::type =
true>
1783 return with.length() <= what.length() && what.compare(what.length() - with.length(), with.size(), with) == 0;
1790#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
1799#ifdef GHC_RAISE_UNICODE_ERRORS
1803 throw filesystem_error(
"Illegal byte sequence for unicode character.", t, std::make_error_code(std::errc::illegal_byte_sequence));
1807#ifdef GHC_OS_WINDOWS
1811 for (
auto& c : _path) {
1812 if (c == generic_separator) {
1816#ifdef GHC_WIN_AUTO_PREFIX_LONG_PATH
1832 impl_string_type::iterator new_end = std::unique(_path.begin() +
static_cast<string_type::difference_type
>(_prefixLength) + 2, _path.end(), [](
path::value_type lhs,
path::value_type rhs) { return lhs == rhs && lhs == preferred_separator; });
1833 _path.erase(new_end, _path.end());
1836 impl_string_type::iterator new_end = std::unique(_path.begin() +
static_cast<string_type::difference_type
>(_prefixLength), _path.end(), [](
path::value_type lhs,
path::value_type rhs) { return lhs == rhs && lhs == preferred_separator; });
1837 _path.erase(new_end, _path.end());
1843template <
class Source,
typename>
1845#ifdef GHC_USE_WCHAR_T
1846 : _path(detail::toWChar(source))
1851 postprocess_path_with_format(fmt);
1854template <
class Source,
typename>
1857 return path(source);
1859template <
class InputIterator>
1862 return path(first, last);
1865template <
class InputIterator>
1867 :
path(std::basic_string<typename std::iterator_traits<InputIterator>::value_type>(first, last), fmt)
1872#ifdef GHC_EXPAND_IMPL
1878#ifdef GHC_OS_WINDOWS
1880 while (::tolower((
unsigned char)*str1) == ::tolower((
unsigned char)*str2++)) {
1886#ifdef GHC_USE_WCHAR_T
1887 return 0 == ::_wcsicmp(str1, str2);
1889 return 0 == ::_stricmp(str1, str2);
1893 return 0 == ::strcasecmp(str1, str2);
1899 while (len1 > 0 && len2 > 0 && ::tolower(
static_cast<unsigned char>(*str1)) == ::tolower(
static_cast<unsigned char>(*str2))) {
1906 return *str1 < *str2 ? -1 : 1;
1908 if (len1 == 0 && len2 == 0) {
1911 return len1 == 0 ? -1 : 1;
1922 return "Error in strerror_r!";
1927template <
typename ErrorNumber>
1930#if defined(GHC_OS_WINDOWS)
1932 DWORD dw = code ?
static_cast<DWORD
>(code) : ::GetLastError();
1933 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&msgBuf, 0, NULL);
1934 std::string msg =
toUtf8(std::wstring((LPWSTR)msgBuf));
1939 return strerror_adapter(strerror_r(code ? code : errno, buffer,
sizeof(buffer)), buffer);
1943#ifdef GHC_OS_WINDOWS
1944using CreateSymbolicLinkW_fp = BOOLEAN(WINAPI*)(LPCWSTR, LPCWSTR, DWORD);
1945using CreateHardLinkW_fp = BOOLEAN(WINAPI*)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES);
1949 std::error_code tec;
1950 auto fs =
status(target_name, tec);
1955#if defined(__GNUC__) && __GNUC__ >= 8
1956#pragma GCC diagnostic push
1957#pragma GCC diagnostic ignored "-Wcast-function-type"
1959 static CreateSymbolicLinkW_fp api_call =
reinterpret_cast<CreateSymbolicLinkW_fp
>(GetProcAddress(GetModuleHandleW(L
"kernel32.dll"),
"CreateSymbolicLinkW"));
1960#if defined(__GNUC__) && __GNUC__ >= 8
1961#pragma GCC diagnostic pop
1965 auto result = ::GetLastError();
1966 if (result == ERROR_PRIVILEGE_NOT_HELD && api_call(
GHC_NATIVEWP(new_symlink),
GHC_NATIVEWP(target_name), to_directory ? 3 : 2) != 0) {
1979#if defined(__GNUC__) && __GNUC__ >= 8
1980#pragma GCC diagnostic push
1981#pragma GCC diagnostic ignored "-Wcast-function-type"
1983 static CreateHardLinkW_fp api_call =
reinterpret_cast<CreateHardLinkW_fp
>(GetProcAddress(GetModuleHandleW(L
"kernel32.dll"),
"CreateHardLinkW"));
1984#if defined(__GNUC__) && __GNUC__ >= 8
1985#pragma GCC diagnostic pop
1997GHC_INLINE path getFullPathName(
const wchar_t* p, std::error_code& ec)
1999 ULONG size = ::GetFullPathNameW(p, 0, 0, 0);
2001 std::vector<wchar_t> buf(size, 0);
2002 ULONG s2 = GetFullPathNameW(p, size, buf.data(),
nullptr);
2003 if (s2 && s2 < size) {
2004 return path(std::wstring(buf.data(), s2));
2022 if (::link(target_name.
c_str(), new_hardlink.
c_str()) != 0) {
2029template <
typename T>
2032#ifdef GHC_OS_WINDOWS
2034 if ((mode & _S_IFDIR) == _S_IFDIR) {
2037 else if ((mode & _S_IFREG) == _S_IFREG) {
2040 else if ((mode & _S_IFCHR) == _S_IFCHR) {
2043 perms prms =
static_cast<perms>(mode & 0xfff);
2047 if (S_ISDIR(mode)) {
2050 else if (S_ISREG(mode)) {
2053 else if (S_ISCHR(mode)) {
2056 else if (S_ISBLK(mode)) {
2059 else if (S_ISFIFO(mode)) {
2062 else if (S_ISLNK(mode)) {
2065 else if (S_ISSOCK(mode)) {
2068 perms prms =
static_cast<perms>(mode & 0xfff);
2073#ifdef GHC_OS_WINDOWS
2078 typedef HANDLE element_type;
2080 unique_handle() noexcept
2081 : _handle(INVALID_HANDLE_VALUE)
2084 explicit unique_handle(element_type h) noexcept
2088 unique_handle(unique_handle&& u) noexcept
2089 : _handle(u.release())
2092 ~unique_handle() { reset(); }
2093 unique_handle& operator=(unique_handle&& u)
noexcept
2098 element_type get() const noexcept {
return _handle; }
2099 explicit operator bool() const noexcept {
return _handle != INVALID_HANDLE_VALUE; }
2100 element_type release() noexcept
2102 element_type tmp = _handle;
2103 _handle = INVALID_HANDLE_VALUE;
2106 void reset(element_type h = INVALID_HANDLE_VALUE)
noexcept
2108 element_type tmp = _handle;
2110 if (tmp != INVALID_HANDLE_VALUE) {
2114 void swap(unique_handle& u)
noexcept { std::swap(_handle, u._handle); }
2117 element_type _handle;
2120#ifndef REPARSE_DATA_BUFFER_HEADER_SIZE
2121typedef struct _REPARSE_DATA_BUFFER
2124 USHORT ReparseDataLength;
2130 USHORT SubstituteNameOffset;
2131 USHORT SubstituteNameLength;
2132 USHORT PrintNameOffset;
2133 USHORT PrintNameLength;
2135 WCHAR PathBuffer[1];
2136 } SymbolicLinkReparseBuffer;
2139 USHORT SubstituteNameOffset;
2140 USHORT SubstituteNameLength;
2141 USHORT PrintNameOffset;
2142 USHORT PrintNameLength;
2143 WCHAR PathBuffer[1];
2144 } MountPointReparseBuffer;
2147 UCHAR DataBuffer[1];
2148 } GenericReparseBuffer;
2150} REPARSE_DATA_BUFFER;
2151#ifndef MAXIMUM_REPARSE_DATA_BUFFER_SIZE
2152#define MAXIMUM_REPARSE_DATA_BUFFER_SIZE (16 * 1024)
2159 void operator()(T* p)
const { std::free(p); }
2162GHC_INLINE std::unique_ptr<REPARSE_DATA_BUFFER, free_deleter<REPARSE_DATA_BUFFER>> getReparseData(
const path& p, std::error_code& ec)
2164 unique_handle
file(CreateFileW(
GHC_NATIVEWP(p), 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0));
2170 std::unique_ptr<REPARSE_DATA_BUFFER, free_deleter<REPARSE_DATA_BUFFER>> reparseData(
reinterpret_cast<REPARSE_DATA_BUFFER*
>(std::calloc(1, MAXIMUM_REPARSE_DATA_BUFFER_SIZE)));
2172 if (DeviceIoControl(
file.get(), FSCTL_GET_REPARSE_POINT, 0, 0, reparseData.get(), MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &bufferUsed, 0)) {
2184#ifdef GHC_OS_WINDOWS
2186 auto reparseData = detail::getReparseData(p, ec);
2188 if (reparseData && IsReparseTagMicrosoft(reparseData->ReparseTag)) {
2189 switch (reparseData->ReparseTag) {
2190 case IO_REPARSE_TAG_SYMLINK: {
2191 auto printName = std::wstring(&reparseData->SymbolicLinkReparseBuffer.PathBuffer[reparseData->SymbolicLinkReparseBuffer.PrintNameOffset /
sizeof(WCHAR)], reparseData->SymbolicLinkReparseBuffer.PrintNameLength /
sizeof(WCHAR));
2192 auto substituteName =
2193 std::wstring(&reparseData->SymbolicLinkReparseBuffer.PathBuffer[reparseData->SymbolicLinkReparseBuffer.SubstituteNameOffset /
sizeof(WCHAR)], reparseData->SymbolicLinkReparseBuffer.SubstituteNameLength /
sizeof(WCHAR));
2198 result = substituteName;
2200 if (reparseData->SymbolicLinkReparseBuffer.Flags & 0x1 ) {
2205 case IO_REPARSE_TAG_MOUNT_POINT:
2216 size_t bufferSize = 256;
2218 std::vector<char> buffer(bufferSize,
static_cast<char>(0));
2219 auto rc = ::readlink(p.
c_str(), buffer.data(), buffer.size());
2224 else if (rc <
static_cast<int>(bufferSize)) {
2225 return path(std::string(buffer.data(),
static_cast<std::string::size_type
>(rc)));
2233#ifdef GHC_OS_WINDOWS
2234GHC_INLINE time_t timeFromFILETIME(
const FILETIME& ft)
2237 ull.LowPart = ft.dwLowDateTime;
2238 ull.HighPart = ft.dwHighDateTime;
2239 return static_cast<time_t
>(ull.QuadPart / 10000000ULL - 11644473600ULL);
2242GHC_INLINE void timeToFILETIME(time_t t, FILETIME& ft)
2245 ll = Int32x32To64(t, 10000000) + 116444736000000000;
2246 ft.dwLowDateTime =
static_cast<DWORD
>(ll);
2247 ft.dwHighDateTime =
static_cast<DWORD
>(ll >> 32);
2250template <
typename INFO>
2251GHC_INLINE uintmax_t hard_links_from_INFO(
const INFO* info)
2253 return static_cast<uintmax_t
>(-1);
2257GHC_INLINE uintmax_t hard_links_from_INFO<BY_HANDLE_FILE_INFORMATION>(
const BY_HANDLE_FILE_INFORMATION* info)
2259 return info->nNumberOfLinks;
2262template <
typename INFO>
2263GHC_INLINE DWORD reparse_tag_from_INFO(
const INFO*)
2269GHC_INLINE DWORD reparse_tag_from_INFO(
const WIN32_FIND_DATAW* info)
2271 return info->dwReserved0;
2274template <
typename INFO>
2275GHC_INLINE file_status status_from_INFO(
const path& p,
const INFO* info, std::error_code& ec, uintmax_t* sz =
nullptr, time_t* lwt =
nullptr)
2278 if (
sizeof(INFO) ==
sizeof(WIN32_FIND_DATAW)) {
2279 if (detail::reparse_tag_from_INFO(info) == IO_REPARSE_TAG_SYMLINK) {
2284 if ((info->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) {
2285 auto reparseData = detail::getReparseData(p, ec);
2286 if (!ec && reparseData && IsReparseTagMicrosoft(reparseData->ReparseTag) && reparseData->ReparseTag == IO_REPARSE_TAG_SYMLINK) {
2292 if ((info->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
2300 if (!(info->dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
2303 if (has_executable_extension(p)) {
2307 *sz =
static_cast<uintmax_t
>(info->nFileSizeHigh) << (
sizeof(info->nFileSizeHigh) * 8) | info->nFileSizeLow;
2310 *lwt = detail::timeFromFILETIME(info->ftLastWriteTime);
2312 return file_status(ft, prms);
2319#ifdef GHC_OS_WINDOWS
2320 return ec.value() == ERROR_FILE_NOT_FOUND || ec.value() == ERROR_PATH_NOT_FOUND || ec.value() == ERROR_INVALID_NAME;
2322 return ec.value() == ENOENT || ec.value() == ENOTDIR;
2328#ifdef GHC_OS_WINDOWS
2330 WIN32_FILE_ATTRIBUTE_DATA attr;
2331 if (!GetFileAttributesExW(
GHC_NATIVEWP(p), GetFileExInfoStandard, &attr)) {
2336 fs = detail::status_from_INFO(p, &attr, ec, sz, lwt);
2350 auto result = ::lstat(p.
c_str(), &
fs);
2367#ifdef GHC_OS_WINDOWS
2368 if (recurse_count > 16) {
2372 WIN32_FILE_ATTRIBUTE_DATA attr;
2373 if (!::GetFileAttributesExW(
GHC_NATIVEWP(p), GetFileExInfoStandard, &attr)) {
2376 else if (attr.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
2377 auto reparseData = detail::getReparseData(p, ec);
2378 if (!ec && reparseData && IsReparseTagMicrosoft(reparseData->ReparseTag) && reparseData->ReparseTag == IO_REPARSE_TAG_SYMLINK) {
2381 if (!ec && !target.
empty()) {
2383 *sls = status_from_INFO(p, &attr, ec);
2399 return detail::status_from_INFO(p, &attr, ec, sz, lwt);
2401 (void)recurse_count;
2403 auto result = ::lstat(p.
c_str(), &st);
2411 result = ::stat(p.
c_str(), &st);
2424 *sz =
static_cast<uintmax_t
>(st.st_size);
2453#ifdef GHC_OS_WINDOWS
2455 p = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
2456 _args.reserve(
static_cast<size_t>(argc));
2457 _argp.reserve(
static_cast<size_t>(argc));
2458 for (
size_t i = 0; i < static_cast<size_t>(argc); ++i) {
2460 _argp.push_back((
char*)_args[i].data());
2462 argv = _argp.data();
2466 std::setlocale(LC_ALL,
"");
2467#if defined(__ANDROID__) && __ANDROID_API__ < 26
2485 , _prefixLength(p._prefixLength)
2491 : _path(std::move(p._path))
2492#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
2493 , _prefixLength(p._prefixLength)
2499 : _path(std::move(source))
2501 postprocess_path_with_format(fmt);
2506#ifdef GHC_WITH_EXCEPTIONS
2507template <
class Source,
typename>
2508inline path::path(
const Source& source,
const std::locale& loc, format fmt)
2511 std::string locName = loc.name();
2512 if (!(locName.length() >= 5 && (locName.substr(locName.length() - 5) ==
"UTF-8" || locName.substr(locName.length() - 5) ==
"utf-8"))) {
2517template <
class InputIterator>
2518inline path::path(InputIterator first, InputIterator last,
const std::locale& loc, format fmt)
2519 : path(std::basic_string<typename std::iterator_traits<InputIterator>::value_type>(first, last), fmt)
2521 std::string locName = loc.name();
2522 if (!(locName.length() >= 5 && (locName.substr(locName.length() - 5) ==
"UTF-8" || locName.substr(locName.length() - 5) ==
"utf-8"))) {
2528#ifdef GHC_EXPAND_IMPL
2538#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
2539 _prefixLength = p._prefixLength;
2546 _path = std::move(p._path);
2547#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
2548 _prefixLength = p._prefixLength;
2560 _path = std::move(source);
2567template <
class Source>
2573template <
class Source>
2576#ifdef GHC_USE_WCHAR_T
2577 _path.assign(detail::toWChar(source));
2588 _path = source._path;
2589#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
2590 _prefixLength = source._prefixLength;
2595template <
class InputIterator>
2598 _path.assign(first, last);
2603#ifdef GHC_EXPAND_IMPL
2612 if (!_path.empty() && _path[_path.length() - 1] !=
preferred_separator && _path[_path.length() - 1] !=
':') {
2627 auto iter = p.
begin();
2632 while (iter != p.
end()) {
2637 _path += (*iter++).
native();
2643GHC_INLINE void path::append_name(
const value_type* name)
2645 if (_path.empty()) {
2659template <
class Source>
2665template <
class Source>
2677template <
class InputIterator>
2680 std::basic_string<typename std::iterator_traits<InputIterator>::value_type> part(first, last);
2684#ifdef GHC_EXPAND_IMPL
2699#ifdef GHC_WITH_STRING_VIEW
2708#ifdef GHC_WITH_STRING_VIEW
2709 basic_string_view<value_type> part(x);
2718#ifdef GHC_OS_WINDOWS
2719 if (x == generic_separator) {
2732template <
class Source>
2738template <
class E
charT>
2741#ifdef GHC_WITH_STRING_VIEW
2742 basic_string_view<EcharT> part(&x, 1);
2744 std::basic_string<EcharT> part(1, x);
2750template <
class Source>
2758template <
class InputIterator>
2761 _path.append(first, last);
2766#ifdef GHC_EXPAND_IMPL
2773#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
2788 _path.erase(_path.size() -
filename()._path.size());
2796 return append(replacement);
2802 _path.erase(_path.size() -
extension()._path.size());
2804 if (!replacement.
empty() && replacement._path[0] !=
'.') {
2807 return concat(replacement);
2812 _path.swap(rhs._path);
2813#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
2814 std::swap(_prefixLength, rhs._prefixLength);
2837template <
class E
charT,
class traits,
class Allocator>
2838inline std::basic_string<EcharT, traits, Allocator>
path::string(
const Allocator& a)
const
2840#ifdef GHC_USE_WCHAR_T
2841 return detail::fromWChar<std::basic_string<EcharT, traits, Allocator>>(_path, a);
2843 return detail::fromUtf8<std::basic_string<EcharT, traits, Allocator>>(_path, a);
2847#ifdef GHC_EXPAND_IMPL
2851#ifdef GHC_USE_WCHAR_T
2860#ifdef GHC_USE_WCHAR_T
2863 return detail::fromUtf8<std::wstring>(
native());
2867#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API)
2870#ifdef GHC_USE_WCHAR_T
2873 return std::u8string(
reinterpret_cast<const char8_t*
>(
c_str()));
2879#ifdef GHC_USE_WCHAR_T
2890 return detail::fromUtf8<std::u16string>(
string());
2896 return detail::fromUtf8<std::u32string>(
string());
2903template <
class E
charT,
class traits,
class Allocator>
2906#ifdef GHC_OS_WINDOWS
2907#ifdef GHC_USE_WCHAR_T
2908 auto result = detail::fromWChar<std::basic_string<EcharT, traits, Allocator>,
path::string_type>(_path, a);
2910 auto result = detail::fromUtf8<std::basic_string<EcharT, traits, Allocator>>(_path, a);
2912 for (
auto& c : result) {
2914 c = generic_separator;
2919 return detail::fromUtf8<std::basic_string<EcharT, traits, Allocator>>(_path, a);
2923#ifdef GHC_EXPAND_IMPL
2927#ifdef GHC_OS_WINDOWS
2928 return generic_string<std::string::value_type, std::string::traits_type, std::string::allocator_type>();
2936#ifdef GHC_OS_WINDOWS
2937 return generic_string<std::wstring::value_type, std::wstring::traits_type, std::wstring::allocator_type>();
2939 return detail::fromUtf8<std::wstring>(_path);
2943#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API)
2946#ifdef GHC_OS_WINDOWS
2947 return generic_string<std::u8string::value_type, std::u8string::traits_type, std::u8string::allocator_type>();
2949 return std::u8string(
reinterpret_cast<const char8_t*
>(_path.c_str()));
2955#ifdef GHC_OS_WINDOWS
2956 return generic_string<std::string::value_type, std::string::traits_type, std::string::allocator_type>();
2965#ifdef GHC_OS_WINDOWS
2966 return generic_string<std::u16string::value_type, std::u16string::traits_type, std::u16string::allocator_type>();
2968 return detail::fromUtf8<std::u16string>(_path);
2974#ifdef GHC_OS_WINDOWS
2975 return generic_string<std::u32string::value_type, std::u32string::traits_type, std::u32string::allocator_type>();
2977 return detail::fromUtf8<std::u32string>(_path);
2985#ifdef LWG_2936_BEHAVIOUR
2986 auto rnl1 = root_name_length();
2987 auto rnl2 = p.root_name_length();
2988#ifdef GHC_OS_WINDOWS
2991 auto rnc = _path.compare(0, rnl1, p._path, 0, (std::min(rnl1, rnl2)));
2996 bool hrd1 = has_root_directory(), hrd2 = p.has_root_directory();
2998 return hrd1 ? 1 : -1;
3004 auto iter1 = _path.begin() +
static_cast<int>(rnl1);
3005 auto iter2 = p._path.begin() +
static_cast<int>(rnl2);
3006 while (iter1 != _path.end() && iter2 != p._path.end() && *iter1 == *iter2) {
3010 if (iter1 == _path.end()) {
3011 return iter2 == p._path.end() ? 0 : -1;
3013 if (iter2 == p._path.end()) {
3016 if (*iter1 == preferred_separator) {
3019 if (*iter2 == preferred_separator) {
3022 return *iter1 < *iter2 ? -1 : 1;
3024#ifdef GHC_OS_WINDOWS
3025 auto rnl1 = root_name_length();
3026 auto rnl2 = p.root_name_length();
3031 return _path.compare(rnl1, std::string::npos, p._path, rnl2, std::string::npos);
3033 return _path.compare(p._path);
3043#ifdef GHC_WITH_STRING_VIEW
3057#ifdef GHC_OS_WINDOWS
3060#if defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
3062 if (_path.length() >= 6 && _path[2] ==
'?' && std::toupper(
static_cast<unsigned char>(_path[4])) >=
'A' && std::toupper(
static_cast<unsigned char>(_path[4])) <=
'Z' && _path[5] ==
':') {
3071GHC_INLINE path::string_type::size_type path::root_name_length() const noexcept
3073#ifdef GHC_OS_WINDOWS
3074 if (_path.length() >= _prefixLength + 2 && std::toupper(
static_cast<unsigned char>(_path[_prefixLength])) >=
'A' && std::toupper(
static_cast<unsigned char>(_path[_prefixLength])) <=
'Z' && _path[_prefixLength + 1] ==
':') {
3080 if (pos == impl_string_type::npos) {
3081 return _path.length();
3111 auto rootPathLen = _prefixLength + root_name_length() + (
has_root_directory() ? 1 : 0);
3117 auto rootPathLen = _prefixLength + root_name_length() + (
has_root_directory() ? 1 : 0);
3118 if (rootPathLen < _path.length()) {
3124 auto iter = piter.decrement(_path.end());
3125 if (iter > _path.begin() +
static_cast<long>(rootPathLen) && *iter !=
preferred_separator) {
3144 if (fn !=
"." && fn !=
"..") {
3145 impl_string_type::size_type pos = fn.rfind(
'.');
3146 if (pos != impl_string_type::npos && pos > 0) {
3157 const auto& fn = *--iter;
3158 impl_string_type::size_type pos = fn._path.rfind(
'.');
3159 if (pos != std::string::npos && pos > 0) {
3166#ifdef GHC_OS_WINDOWS
3171 auto iter = p.
end();
3172 const auto& fn = *--iter;
3173 auto pos = fn._path.find_last_of(
'.');
3174 if (pos == std::string::npos || pos == 0 || fn._path.length() - pos != 3) {
3192 return _path.empty();
3197 return root_name_length() > 0;
3202 auto rootLen = _prefixLength + root_name_length();
3213 auto rootPathLen = _prefixLength + root_name_length() + (
has_root_directory() ? 1 : 0);
3214 return rootPathLen < _path.length();
3239#ifdef GHC_OS_WINDOWS
3256 bool lastDotDot =
false;
3262 else if (s ==
".." && !dest.
empty()) {
3267 else if (*(--dest.
end()) !=
"..") {
3269 dest._path.pop_back();
3275 if (!(s.empty() && lastDotDot)) {
3278 lastDotDot = s ==
"..";
3292 while (a !=
end() && b != base.
end() && *a == *b) {
3296 if (a ==
end() && b == base.
end()) {
3300 for (
const auto& element : input_iterator_range<const_iterator>(b, base.
end())) {
3301 if (element !=
"." && element !=
"" && element !=
"..") {
3304 else if (element ==
"..") {
3312 for (
int i = 0; i < count; ++i) {
3315 for (
const auto& element : input_iterator_range<const_iterator>(a,
end())) {
3324 return result.
empty() ? *this : result;
3332 : _first(p._path.
begin())
3333 , _last(p._path.
end())
3343GHC_INLINE path::impl_string_type::const_iterator path::iterator::increment(
const path::impl_string_type::const_iterator& pos)
const
3345 path::impl_string_type::const_iterator i = pos;
3346 bool fromStart = i == _first || i == _prefix;
3348 if (fromStart && i == _first && _prefix > _first) {
3368 if (fromStart && i != _last && *i ==
':') {
3379GHC_INLINE path::impl_string_type::const_iterator path::iterator::decrement(
const path::impl_string_type::const_iterator& pos)
const
3381 path::impl_string_type::const_iterator i = pos;
3387#ifdef GHC_OS_WINDOWS
3389 i = std::find_first_of(std::reverse_iterator<path::impl_string_type::const_iterator>(i), std::reverse_iterator<path::impl_string_type::const_iterator>(_first), seps.begin(), seps.end()).base();
3390 if (i > _first && *i ==
':') {
3394 i = std::find(std::reverse_iterator<path::impl_string_type::const_iterator>(i), std::reverse_iterator<path::impl_string_type::const_iterator>(_first),
preferred_separator).base();
3405GHC_INLINE void path::iterator::updateCurrent()
3407 if ((_iter == _last) || (_iter != _first && _iter != _last && (*_iter ==
preferred_separator && _iter != _root) && (_iter + 1 == _last))) {
3411 _current.assign(_iter, increment(_iter));
3417 _iter = increment(_iter);
3418 while (_iter != _last &&
3421 (_iter + 1) != _last
3438 _iter = decrement(_iter);
3452 return _iter == other._iter;
3457 return _iter != other._iter;
3472 return iterator(*
this, _path.begin());
3477 return iterator(*
this, _path.end());
3484 swap(lhs._path, rhs._path);
3492#ifdef GHC_HAS_THREEWAY_COMP
3493GHC_INLINE std::strong_ordering operator<=>(
const path& lhs,
const path& rhs)
noexcept
3495 return lhs.compare(rhs) <=> 0;
3501 return lhs.compare(rhs) == 0;
3506 return !(lhs == rhs);
3511 return lhs.compare(rhs) < 0;
3516 return lhs.compare(rhs) <= 0;
3521 return lhs.compare(rhs) > 0;
3526 return lhs.compare(rhs) >= 0;
3540template <
class charT,
class traits>
3541inline std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os,
const path& p)
3544 auto ps = p.string<charT, traits>();
3546 if (c ==
'"' || c ==
'\\') {
3555template <
class charT,
class traits>
3556inline std::basic_istream<charT, traits>&
operator>>(std::basic_istream<charT, traits>& is,
path& p)
3558 std::basic_string<charT, traits> tmp;
3562 auto sf = is.flags();
3563 is >> std::noskipws;
3570 tmp +=
static_cast<charT
>(c2);
3573 else if (c2 ==
'"') {
3577 tmp +=
static_cast<charT
>(c2);
3581 if ((sf & std::ios_base::skipws) == std::ios_base::skipws) {
3588 p =
path(
static_cast<charT
>(c) + tmp);
3593#ifdef GHC_EXPAND_IMPL
3598 : std::system_error(ec, what_arg)
3599 , _what_arg(what_arg)
3605 : std::system_error(ec, what_arg)
3606 , _what_arg(what_arg)
3611 _what_arg +=
": '" + _p1.
string() +
"'";
3616 : std::system_error(ec, what_arg)
3617 , _what_arg(what_arg)
3623 _what_arg +=
": '" + _p1.
string() +
"'";
3626 _what_arg +=
", '" + _p2.
string() +
"'";
3642 return _what_arg.c_str();
3647#ifdef GHC_WITH_EXCEPTIONS
3662#ifdef GHC_OS_WINDOWS
3666 ULONG size = ::GetFullPathNameW(
GHC_NATIVEWP(p), 0, 0, 0);
3668 std::vector<wchar_t> buf(size, 0);
3669 ULONG s2 = GetFullPathNameW(
GHC_NATIVEWP(p), size, buf.data(),
nullptr);
3670 if (s2 && s2 < size) {
3671 path result =
path(std::wstring(buf.data(), s2));
3708#ifdef GHC_WITH_EXCEPTIONS
3739 auto rootPathLen = work._prefixLength + work.root_name_length() + (work.
has_root_directory() ? 1 : 0);
3742 for (
auto pe : work) {
3743 if (pe.empty() || pe ==
".") {
3746 else if (pe ==
"..") {
3750 else if ((result / pe).string().length() <= rootPathLen) {
3764 if (target.is_absolute()) {
3783#ifdef GHC_WITH_EXCEPTIONS
3792 copy(from, to, options, ec);
3806 std::error_code tec;
3813 fs_from =
status(from, ec);
3851 copy_file(from, to / from.filename(), options, ec);
3858#ifdef LWG_2682_BEHAVIOUR
3872 copy(iter->path(), to / iter->path().filename(), options |
static_cast<copy_options>(0x8000), ec);
3882#ifdef GHC_WITH_EXCEPTIONS
3891 auto result =
copy_file(from, to, option, ec);
3906 std::error_code tecf, tect;
3907 auto sf =
status(from, tecf);
3908 auto st =
status(to, tect);
3909 bool overwrite =
false;
3931 if (from_time <= to_time) {
3937#ifdef GHC_OS_WINDOWS
3944 std::vector<char> buffer(16384,
'\0');
3945 int in = -1, out = -1;
3946 if ((in = ::open(from.c_str(), O_RDONLY)) < 0) {
3950 int mode = O_CREAT | O_WRONLY | O_TRUNC;
3954 if ((out = ::open(to.c_str(), mode,
static_cast<int>(sf.permissions() &
perms::all))) < 0) {
3960 while ((br = ::read(in, buffer.data(), buffer.size())) > 0) {
3963 if ((bw = ::write(out, buffer.data() + offset,
static_cast<size_t>(br))) > 0) {
3981#ifdef GHC_WITH_EXCEPTIONS
4006#ifdef GHC_WITH_EXCEPTIONS
4022 bool didCreate =
false;
4023 auto rootPathLen = p._prefixLength + p.root_name_length() + (p.has_root_directory() ? 1 : 0);
4024 current = p.
native().substr(0, rootPathLen);
4025 path folders(p._path.substr(rootPathLen));
4028 std::error_code tec;
4037 std::error_code tmp_ec;
4047#ifndef LWG_2935_BEHAVIOUR
4057#ifdef GHC_WITH_EXCEPTIONS
4074#ifdef GHC_WITH_EXCEPTIONS
4088 std::error_code tec;
4091#ifdef LWG_2935_BEHAVIOUR
4100#ifdef GHC_OS_WINDOWS
4101 if (!attributes.empty()) {
4112 ::mode_t attribs =
static_cast<mode_t
>(
perms::all);
4113 if (!attributes.empty()) {
4114 struct ::stat fileStat;
4115 if (::stat(attributes.c_str(), &fileStat) != 0) {
4119 attribs = fileStat.st_mode;
4121 if (::mkdir(p.c_str(), attribs) != 0) {
4129#ifdef GHC_WITH_EXCEPTIONS
4146#ifdef GHC_WITH_EXCEPTIONS
4163#ifdef GHC_WITH_EXCEPTIONS
4179#ifdef GHC_WITH_EXCEPTIONS
4194#ifdef GHC_OS_WINDOWS
4195 DWORD pathlen = ::GetCurrentDirectoryW(0, 0);
4196 std::unique_ptr<wchar_t[]> buffer(
new wchar_t[
size_t(pathlen) + 1]);
4197 if (::GetCurrentDirectoryW(pathlen, buffer.get()) == 0) {
4203 size_t pathlen =
static_cast<size_t>(std::max(
int(::pathconf(
".", _PC_PATH_MAX)),
int(
PATH_MAX)));
4204 std::unique_ptr<char[]> buffer(
new char[pathlen + 1]);
4205 if (::getcwd(buffer.get(), pathlen) ==
nullptr) {
4209 return path(buffer.get());
4213#ifdef GHC_WITH_EXCEPTIONS
4227#ifdef GHC_OS_WINDOWS
4232 if (::chdir(p.string().c_str()) == -1) {
4243#ifdef GHC_WITH_EXCEPTIONS
4259#ifdef GHC_WITH_EXCEPTIONS
4274#ifdef GHC_OS_WINDOWS
4275 detail::unique_handle file1(::CreateFileW(
GHC_NATIVEWP(p1), 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0));
4276 auto e1 = ::GetLastError();
4277 detail::unique_handle file2(::CreateFileW(
GHC_NATIVEWP(p2), 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0));
4278 if (!file1 || !file2) {
4279#ifdef LWG_2937_BEHAVIOUR
4282 if (file1 == file2) {
4288 BY_HANDLE_FILE_INFORMATION inf1, inf2;
4289 if (!::GetFileInformationByHandle(file1.get(), &inf1)) {
4293 if (!::GetFileInformationByHandle(file2.get(), &inf2)) {
4297 return inf1.ftLastWriteTime.dwLowDateTime == inf2.ftLastWriteTime.dwLowDateTime && inf1.ftLastWriteTime.dwHighDateTime == inf2.ftLastWriteTime.dwHighDateTime && inf1.nFileIndexHigh == inf2.nFileIndexHigh && inf1.nFileIndexLow == inf2.nFileIndexLow &&
4298 inf1.nFileSizeHigh == inf2.nFileSizeHigh && inf1.nFileSizeLow == inf2.nFileSizeLow && inf1.dwVolumeSerialNumber == inf2.dwVolumeSerialNumber;
4300 struct ::stat s1, s2;
4301 auto rc1 = ::stat(p1.c_str(), &s1);
4303 auto rc2 = ::stat(p2.c_str(), &s2);
4305#ifdef LWG_2937_BEHAVIOUR
4314 return s1.st_dev == s2.st_dev && s1.st_ino == s2.st_ino && s1.st_size == s2.st_size && s1.st_mtime == s2.st_mtime;
4318#ifdef GHC_WITH_EXCEPTIONS
4333#ifdef GHC_OS_WINDOWS
4334 WIN32_FILE_ATTRIBUTE_DATA attr;
4335 if (!GetFileAttributesExW(
GHC_NATIVEWP(p), GetFileExInfoStandard, &attr)) {
4337 return static_cast<uintmax_t
>(-1);
4339 return static_cast<uintmax_t
>(attr.nFileSizeHigh) << (
sizeof(attr.nFileSizeHigh) * 8) | attr.nFileSizeLow;
4341 struct ::stat fileStat;
4342 if (::stat(p.c_str(), &fileStat) == -1) {
4344 return static_cast<uintmax_t
>(-1);
4346 return static_cast<uintmax_t
>(fileStat.st_size);
4351#ifdef GHC_WITH_EXCEPTIONS
4366#ifdef GHC_OS_WINDOWS
4367 uintmax_t result =
static_cast<uintmax_t
>(-1);
4368 detail::unique_handle file(::CreateFileW(
GHC_NATIVEWP(p), 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0));
4369 BY_HANDLE_FILE_INFORMATION inf;
4374 if (!::GetFileInformationByHandle(file.get(), &inf)) {
4378 result = inf.nNumberOfLinks;
4383 uintmax_t result = 0;
4388 return ec ?
static_cast<uintmax_t
>(-1) : result;
4398#ifdef GHC_WITH_EXCEPTIONS
4415#ifdef GHC_WITH_EXCEPTIONS
4432#ifdef GHC_WITH_EXCEPTIONS
4444#ifdef GHC_WITH_EXCEPTIONS
4448 return directory_iterator(p) == directory_iterator();
4483#ifdef GHC_WITH_EXCEPTIONS
4500#ifdef GHC_WITH_EXCEPTIONS
4517#ifdef GHC_WITH_EXCEPTIONS
4534#ifdef GHC_WITH_EXCEPTIONS
4551#ifdef GHC_WITH_EXCEPTIONS
4563#ifdef GHC_WITH_EXCEPTIONS
4580 return ec ? (file_time_type::min)() : std::chrono::system_clock::from_time_t(result);
4583#ifdef GHC_WITH_EXCEPTIONS
4597 auto d = new_time.time_since_epoch();
4598#ifdef GHC_OS_WINDOWS
4599 detail::unique_handle file(::CreateFileW(
GHC_NATIVEWP(p), FILE_WRITE_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL));
4601 auto tt = std::chrono::duration_cast<std::chrono::microseconds>(d).count() * 10 + 116444736000000000;
4602 ft.dwLowDateTime =
static_cast<DWORD
>(tt);
4603 ft.dwHighDateTime =
static_cast<DWORD
>(tt >> 32);
4604 if (!::SetFileTime(file.get(), 0, 0, &ft)) {
4607#elif defined(GHC_OS_MACOS)
4608#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
4609#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
4611 if (::stat(p.c_str(), &
fs) == 0) {
4612 struct ::timeval tv[2];
4613 tv[0].tv_sec =
fs.st_atimespec.tv_sec;
4614 tv[0].tv_usec =
static_cast<int>(
fs.st_atimespec.tv_nsec / 1000);
4615 tv[1].tv_sec = std::chrono::duration_cast<std::chrono::seconds>(d).count();
4616 tv[1].tv_usec =
static_cast<int>(std::chrono::duration_cast<std::chrono::microseconds>(d).count() % 1000000);
4617 if (::utimes(p.c_str(), tv) == 0) {
4624 struct ::timespec times[2];
4625 times[0].tv_sec = 0;
4627 times[1].tv_sec = std::chrono::duration_cast<std::chrono::seconds>(d).count();
4628 times[1].tv_nsec = 0;
4629 if (::utimensat(AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) {
4637#define UTIME_OMIT ((1l << 30) - 2l)
4639 struct ::timespec times[2];
4640 times[0].tv_sec = 0;
4642 times[1].tv_sec =
static_cast<decltype(times[1].tv_sec)
>(std::chrono::duration_cast<std::chrono::seconds>(d).count());
4643 times[1].tv_nsec =
static_cast<decltype(times[1].tv_nsec)
>(std::chrono::duration_cast<std::chrono::nanoseconds>(d).count() % 1000000000);
4644#if defined(__ANDROID_API__) && __ANDROID_API__ < 12
4645 if (syscall(__NR_utimensat, AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) {
4647 if (::utimensat((
int)AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) {
4655#ifdef GHC_WITH_EXCEPTIONS
4680 prms =
fs.permissions() | prms;
4683 prms =
fs.permissions() & ~prms;
4686#ifdef GHC_OS_WINDOWS
4689 if (oldAttr != INVALID_FILE_ATTRIBUTES) {
4691 if (oldAttr == newAttr || SetFileAttributesW(
GHC_NATIVEWP(p), newAttr)) {
4704 if (::_wchmod(p.
wstring().c_str(), mode) != 0) {
4710 if (::chmod(p.
c_str(),
static_cast<mode_t
>(prms)) != 0) {
4717#ifdef GHC_WITH_EXCEPTIONS
4728#ifdef GHC_WITH_EXCEPTIONS
4740#ifdef GHC_WITH_EXCEPTIONS
4760 return ec ?
path() : result;
4768#ifdef GHC_WITH_EXCEPTIONS
4780#ifdef GHC_WITH_EXCEPTIONS
4784 auto result =
remove(p, ec);
4795#ifdef GHC_OS_WINDOWS
4796#ifdef GHC_USE_WCHAR_T
4797 auto cstr = p.c_str();
4799 std::wstring np = detail::fromUtf8<std::wstring>(p.u8string());
4800 auto cstr = np.c_str();
4802 DWORD attr = GetFileAttributesW(cstr);
4803 if (attr == INVALID_FILE_ATTRIBUTES) {
4804 auto error = ::GetLastError();
4805 if (error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND) {
4810 else if (attr & FILE_ATTRIBUTE_READONLY) {
4811 auto new_attr = attr & ~static_cast<DWORD>(FILE_ATTRIBUTE_READONLY);
4812 if (!SetFileAttributesW(cstr, new_attr)) {
4813 auto error = ::GetLastError();
4818 if (attr & FILE_ATTRIBUTE_DIRECTORY) {
4819 if (!RemoveDirectoryW(cstr)) {
4824 if (!DeleteFileW(cstr)) {
4832 if (error == ENOENT) {
4838 return ec ? false :
true;
4841#ifdef GHC_WITH_EXCEPTIONS
4856 uintmax_t count = 0;
4859 return static_cast<uintmax_t
>(-1);
4861 std::error_code tec;
4868 bool is_symlink_result = iter->is_symlink(ec);
4870 return static_cast<uintmax_t
>(-1);
4871 if (!is_symlink_result && iter->is_directory(ec)) {
4874 return static_cast<uintmax_t
>(-1);
4879 remove(iter->path(), ec);
4882 return static_cast<uintmax_t
>(-1);
4894 return static_cast<uintmax_t
>(-1);
4899#ifdef GHC_WITH_EXCEPTIONS
4913#ifdef GHC_OS_WINDOWS
4921 if (
::rename(from.c_str(), to.c_str()) != 0) {
4928#ifdef GHC_WITH_EXCEPTIONS
4942#ifdef GHC_OS_WINDOWS
4943 LARGE_INTEGER lisize;
4944 lisize.QuadPart =
static_cast<LONGLONG
>(size);
4945 if (lisize.QuadPart < 0) {
4946#ifdef ERROR_FILE_TOO_LARGE
4953 detail::unique_handle file(CreateFileW(
GHC_NATIVEWP(p), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL));
4957 else if (SetFilePointerEx(file.get(), lisize, NULL, FILE_BEGIN) == 0 || SetEndOfFile(file.get()) == 0) {
4961 if (::truncate(p.c_str(),
static_cast<off_t
>(size)) != 0) {
4967#ifdef GHC_WITH_EXCEPTIONS
4971 auto result =
space(p, ec);
4982#ifdef GHC_OS_WINDOWS
4983 ULARGE_INTEGER freeBytesAvailableToCaller = {{ 0, 0 }};
4984 ULARGE_INTEGER totalNumberOfBytes = {{ 0, 0 }};
4985 ULARGE_INTEGER totalNumberOfFreeBytes = {{ 0, 0 }};
4986 if (!GetDiskFreeSpaceExW(
GHC_NATIVEWP(p), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) {
4988 return {
static_cast<uintmax_t
>(-1),
static_cast<uintmax_t
>(-1),
static_cast<uintmax_t
>(-1)};
4990 return {
static_cast<uintmax_t
>(totalNumberOfBytes.QuadPart),
static_cast<uintmax_t
>(totalNumberOfFreeBytes.QuadPart),
static_cast<uintmax_t
>(freeBytesAvailableToCaller.QuadPart)};
4992 struct ::statvfs sfs;
4993 if (::statvfs(p.c_str(), &sfs) != 0) {
4995 return {
static_cast<uintmax_t
>(-1),
static_cast<uintmax_t
>(-1),
static_cast<uintmax_t
>(-1)};
4997 return {
static_cast<uintmax_t
>(sfs.f_blocks) *
static_cast<uintmax_t
>(sfs.f_frsize),
static_cast<uintmax_t
>(sfs.f_bfree) *
static_cast<uintmax_t
>(sfs.f_frsize),
static_cast<uintmax_t
>(sfs.f_bavail) *
static_cast<uintmax_t
>(sfs.f_frsize)};
5001#ifdef GHC_WITH_EXCEPTIONS
5005 auto result =
status(p, ec);
5023#ifdef GHC_WITH_EXCEPTIONS
5040#ifdef GHC_WITH_EXCEPTIONS
5055#ifdef GHC_OS_WINDOWS
5056 wchar_t buffer[512];
5057 auto rc = GetTempPathW(511, buffer);
5058 if (!rc || rc > 511) {
5062 return path(std::wstring(buffer));
5064 static const char* temp_vars[] = {
"TMPDIR",
"TMP",
"TEMP",
"TEMPDIR",
nullptr};
5065 const char* temp_path =
nullptr;
5066 for (
auto temp_name = temp_vars; *temp_name !=
nullptr; ++temp_name) {
5067 temp_path = std::getenv(*temp_name);
5069 return path(temp_path);
5072 return path(
"/tmp");
5076#ifdef GHC_WITH_EXCEPTIONS
5095 std::error_code tec;
5096 if (
exists(result / pe, tec)) {
5104 if (!result.
empty()) {
5120 if (!result.
empty()) {
5142 : _type(other._type)
5143 , _perms(other._perms)
5148 : _type(other._type)
5149 , _perms(other._perms)
5159 _perms = rhs._perms;
5166 _perms = rhs._perms;
5198#ifdef GHC_WITH_EXCEPTIONS
5201 , _file_size(static_cast<uintmax_t>(-1))
5202#ifndef GHC_OS_WINDOWS
5203 , _hard_link_count(static_cast<uintmax_t>(-1))
5205 , _last_write_time(0)
5213 , _file_size(static_cast<uintmax_t>(-1))
5214#ifndef GHC_OS_WINDOWS
5215 , _hard_link_count(static_cast<uintmax_t>(-1))
5217 , _last_write_time(0)
5229#ifdef GHC_WITH_EXCEPTIONS
5243#ifdef GHC_WITH_EXCEPTIONS
5257#ifdef GHC_WITH_EXCEPTIONS
5270#ifdef GHC_OS_WINDOWS
5271 _status =
detail::status_ex(_path, ec, &_symlink_status, &_file_size,
nullptr, &_last_write_time);
5273 _status =
detail::status_ex(_path, ec, &_symlink_status, &_file_size, &_hard_link_count, &_last_write_time);
5288#ifdef GHC_WITH_EXCEPTIONS
5299 return _status.type();
5304#ifdef GHC_WITH_EXCEPTIONS
5316#ifdef GHC_WITH_EXCEPTIONS
5327#ifdef GHC_WITH_EXCEPTIONS
5339#ifdef GHC_WITH_EXCEPTIONS
5351#ifdef GHC_WITH_EXCEPTIONS
5363#ifdef GHC_WITH_EXCEPTIONS
5366 auto ft = status_file_type();
5373 auto ft = status_file_type(ec);
5375 return !ec && other;
5378#ifdef GHC_WITH_EXCEPTIONS
5390#ifdef GHC_WITH_EXCEPTIONS
5402#ifdef GHC_WITH_EXCEPTIONS
5418#ifdef GHC_WITH_EXCEPTIONS
5421 if (_file_size !=
static_cast<uintmax_t
>(-1)) {
5430 if (_file_size !=
static_cast<uintmax_t
>(-1)) {
5438#ifdef GHC_WITH_EXCEPTIONS
5441#ifndef GHC_OS_WINDOWS
5442 if (_hard_link_count !=
static_cast<uintmax_t
>(-1)) {
5443 return _hard_link_count;
5452#ifndef GHC_OS_WINDOWS
5453 if (_hard_link_count !=
static_cast<uintmax_t
>(-1)) {
5455 return _hard_link_count;
5462#ifdef GHC_WITH_EXCEPTIONS
5465 if (_last_write_time != 0) {
5466 return std::chrono::system_clock::from_time_t(_last_write_time);
5474 if (_last_write_time != 0) {
5476 return std::chrono::system_clock::from_time_t(_last_write_time);
5481#ifdef GHC_WITH_EXCEPTIONS
5500#ifdef GHC_WITH_EXCEPTIONS
5504 return _symlink_status;
5514 return _symlink_status;
5519#ifdef GHC_HAS_THREEWAY_COMP
5522 return _path <=> rhs._path;
5528 return _path < rhs._path;
5533 return _path == rhs._path;
5538 return _path != rhs._path;
5543 return _path <= rhs._path;
5548 return _path > rhs._path;
5553 return _path >= rhs._path;
5559#ifdef GHC_OS_WINDOWS
5566 , _dirHandle(INVALID_HANDLE_VALUE)
5569 ZeroMemory(&_findData,
sizeof(WIN32_FIND_DATAW));
5570 if ((_dirHandle = FindFirstFileW(
GHC_NATIVEWP((
_base /
"*")), &_findData)) != INVALID_HANDLE_VALUE) {
5571 if (std::wstring(_findData.cFileName) == L
"." || std::wstring(_findData.cFileName) == L
"..") {
5580 auto error = ::GetLastError();
5581 _base = filesystem::path();
5588 impl(
const impl& other) =
delete;
5591 if (_dirHandle != INVALID_HANDLE_VALUE) {
5592 FindClose(_dirHandle);
5593 _dirHandle = INVALID_HANDLE_VALUE;
5598 if (_dirHandle != INVALID_HANDLE_VALUE) {
5600 if (FindNextFileW(_dirHandle, &_findData)) {
5602#ifdef GHC_USE_WCHAR_T
5603 _dir_entry._path.append_name(_findData.cFileName);
5605#ifdef GHC_RAISE_UNICODE_ERRORS
5609 catch (filesystem_error& fe) {
5620 auto err = ::GetLastError();
5621 if (err != ERROR_NO_MORE_FILES) {
5624 FindClose(_dirHandle);
5625 _dirHandle = INVALID_HANDLE_VALUE;
5629 }
while (std::wstring(_findData.cFileName) == L
"." || std::wstring(_findData.cFileName) == L
"..");
5637 if (_findData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
5649 _dir_entry._file_size =
static_cast<uintmax_t
>(-1);
5656 WIN32_FIND_DATAW _findData;
5659 std::error_code
_ec;
5719 }
while (skip || std::strcmp(
_entry->d_name,
".") == 0 || std::strcmp(
_entry->d_name,
"..") == 0);
5735 _dir_entry._file_size =
static_cast<uintmax_t
>(-1);
5736 _dir_entry._hard_link_count =
static_cast<uintmax_t
>(-1);
5754#ifdef GHC_WITH_EXCEPTIONS
5765 : _impl(new impl(p, options))
5782 : _impl(
new impl(p, options))
5795 : _impl(std::move(rhs._impl))
5809 _impl = std::move(rhs._impl);
5815 return _impl->_dir_entry;
5820 return &_impl->_dir_entry;
5823#ifdef GHC_WITH_EXCEPTIONS
5827 _impl->increment(ec);
5837 _impl->increment(ec);
5843 return _impl->_dir_entry._path == rhs._impl->_dir_entry._path;
5848 return _impl->_dir_entry._path != rhs._impl->_dir_entry._path;
5872#ifdef GHC_WITH_EXCEPTIONS
5880 : _impl(new recursive_directory_iterator_impl(options, true))
5882 _impl->_dir_iter_stack.push(directory_iterator(p,
options));
5887 : _impl(
new recursive_directory_iterator_impl(options,
true))
5904 : _impl(std::move(rhs._impl))
5913 return _impl->_options;
5918 return static_cast<int>(_impl->_dir_iter_stack.size() - 1);
5923 return _impl->_recursion_pending;
5928 return *(_impl->_dir_iter_stack.top());
5933 return &(*(_impl->_dir_iter_stack.top()));
5945 _impl = std::move(rhs._impl);
5949#ifdef GHC_WITH_EXCEPTIONS
5964 bool isDir = !ec && (*this)->is_directory(ec);
5970 _impl->_dir_iter_stack.push(
directory_iterator((*this)->path(), _impl->_options, ec));
5973 _impl->_dir_iter_stack.top().increment(ec);
5977 _impl->_dir_iter_stack.pop();
5978 _impl->_dir_iter_stack.top().increment(ec);
5981 else if (!_impl->_dir_iter_stack.empty()) {
5982 _impl->_dir_iter_stack.pop();
5984 _impl->_recursion_pending =
true;
5989#ifdef GHC_WITH_EXCEPTIONS
6007 _impl->_dir_iter_stack.pop();
6008 _impl->_dir_iter_stack.top().increment(ec);
6015 _impl->_recursion_pending =
false;
6021 return _impl->_dir_iter_stack.top() == rhs._impl->_dir_iter_stack.top();
6026 return _impl->_dir_iter_stack.top() != rhs._impl->_dir_iter_stack.top();
6047#undef GHC_EXPAND_IMPL
std::ostream & operator<<(std::ostream &s, const FcidumpReader::FcidumpHeader &h)
Definition FcidumpWriter.cxx:25
Definition filesystem.hpp:1163
const basic_filebuf & operator=(const basic_filebuf &)=delete
~basic_filebuf() override
Definition filesystem.hpp:1166
basic_filebuf< charT, traits > * open(const path &p, std::ios_base::openmode mode)
Definition filesystem.hpp:1169
basic_filebuf()
Definition filesystem.hpp:1165
basic_filebuf(const basic_filebuf &)=delete
Definition filesystem.hpp:1227
const basic_fstream & operator=(const basic_fstream &)=delete
basic_fstream(const basic_fstream &)=delete
~basic_fstream() override
Definition filesystem.hpp:1245
basic_fstream(const path &p, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
Definition filesystem.hpp:1237
basic_fstream()
Definition filesystem.hpp:1229
void open(const path &p, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
Definition filesystem.hpp:1241
Definition filesystem.hpp:1181
basic_ifstream(const path &p, std::ios_base::openmode mode=std::ios_base::in)
Definition filesystem.hpp:1191
basic_ifstream(const basic_ifstream &)=delete
~basic_ifstream() override
Definition filesystem.hpp:1199
void open(const path &p, std::ios_base::openmode mode=std::ios_base::in)
Definition filesystem.hpp:1195
basic_ifstream()
Definition filesystem.hpp:1183
const basic_ifstream & operator=(const basic_ifstream &)=delete
Definition filesystem.hpp:1204
const basic_ofstream & operator=(const basic_ofstream &)=delete
basic_ofstream(const basic_ofstream &)=delete
basic_ofstream()
Definition filesystem.hpp:1206
~basic_ofstream() override
Definition filesystem.hpp:1222
basic_ofstream(const path &p, std::ios_base::openmode mode=std::ios_base::out)
Definition filesystem.hpp:1214
void open(const path &p, std::ios_base::openmode mode=std::ios_base::out)
Definition filesystem.hpp:1218
Definition filesystem.hpp:819
void replace_filename(const path &p, std::error_code &ec)
Definition filesystem.hpp:5251
bool is_directory(std::error_code &ec) const noexcept
Definition filesystem.hpp:5346
bool operator!=(const directory_entry &rhs) const noexcept
Definition filesystem.hpp:5536
void assign(const path &p, std::error_code &ec)
Definition filesystem.hpp:5237
uintmax_t file_size(std::error_code &ec) const noexcept
Definition filesystem.hpp:5428
bool is_fifo(std::error_code &ec) const noexcept
Definition filesystem.hpp:5358
bool operator==(const directory_entry &rhs) const noexcept
Definition filesystem.hpp:5531
file_status status(std::error_code &ec) const noexcept
Definition filesystem.hpp:5491
~directory_entry()
Definition filesystem.hpp:5222
bool is_regular_file(std::error_code &ec) const noexcept
Definition filesystem.hpp:5385
bool is_other(std::error_code &ec) const noexcept
Definition filesystem.hpp:5371
bool is_socket(std::error_code &ec) const noexcept
Definition filesystem.hpp:5397
bool is_block_file(std::error_code &ec) const noexcept
Definition filesystem.hpp:5322
bool operator>=(const directory_entry &rhs) const noexcept
Definition filesystem.hpp:5551
file_status symlink_status(std::error_code &ec) const noexcept
Definition filesystem.hpp:5510
directory_entry() noexcept=default
bool exists(std::error_code &ec) const noexcept
Definition filesystem.hpp:5311
file_time_type last_write_time(std::error_code &ec) const noexcept
Definition filesystem.hpp:5472
directory_entry & operator=(directory_entry &&) noexcept=default
bool operator<(const directory_entry &rhs) const noexcept
Definition filesystem.hpp:5526
bool is_character_file(std::error_code &ec) const noexcept
Definition filesystem.hpp:5334
directory_entry & operator=(const directory_entry &)=default
uintmax_t hard_link_count(std::error_code &ec) const noexcept
Definition filesystem.hpp:5450
const filesystem::path & path() const noexcept
Definition filesystem.hpp:5278
bool operator<=(const directory_entry &rhs) const noexcept
Definition filesystem.hpp:5541
void refresh(std::error_code &ec) noexcept
Definition filesystem.hpp:5268
bool is_symlink(std::error_code &ec) const noexcept
Definition filesystem.hpp:5409
bool operator>(const directory_entry &rhs) const noexcept
Definition filesystem.hpp:5546
Definition filesystem.hpp:5664
~impl()
Definition filesystem.hpp:5687
impl(const path &path, directory_options options)
Definition filesystem.hpp:5666
std::error_code _ec
Definition filesystem.hpp:5744
void copyToDirEntry()
Definition filesystem.hpp:5723
impl(const impl &other)=delete
struct::dirent * _entry
Definition filesystem.hpp:5742
directory_options _options
Definition filesystem.hpp:5740
directory_entry _dir_entry
Definition filesystem.hpp:5743
DIR * _dir
Definition filesystem.hpp:5741
void increment(std::error_code &ec)
Definition filesystem.hpp:5693
path _base
Definition filesystem.hpp:5739
Definition filesystem.hpp:915
const directory_entry & operator*() const &noexcept
Definition filesystem.hpp:917
directory_entry operator*() &&noexcept
Definition filesystem.hpp:918
Definition filesystem.hpp:912
bool operator==(const directory_iterator &rhs) const
Definition filesystem.hpp:5841
std::ptrdiff_t difference_type
Definition filesystem.hpp:931
directory_iterator() noexcept
Definition filesystem.hpp:5749
bool operator!=(const directory_iterator &rhs) const
Definition filesystem.hpp:5846
directory_iterator & increment(std::error_code &ec) noexcept
Definition filesystem.hpp:5835
std::input_iterator_tag iterator_category
Definition filesystem.hpp:929
const directory_entry * operator->() const
Definition filesystem.hpp:5818
const directory_entry & operator*() const
Definition filesystem.hpp:5813
directory_iterator & operator=(const directory_iterator &rhs)
Definition filesystem.hpp:5801
~directory_iterator()
Definition filesystem.hpp:5799
Definition filesystem.hpp:791
file_type type() const noexcept
Definition filesystem.hpp:5182
friend bool operator==(const file_status &lhs, const file_status &rhs) noexcept
Definition filesystem.hpp:808
perms permissions() const noexcept
Definition filesystem.hpp:5187
void permissions(perms prms) noexcept
Definition filesystem.hpp:5176
file_status & operator=(const file_status &) noexcept
Definition filesystem.hpp:5156
~file_status()
Definition filesystem.hpp:5153
void type(file_type ft) noexcept
Definition filesystem.hpp:5171
file_status() noexcept
Definition filesystem.hpp:5130
Definition filesystem.hpp:656
const path & path2() const noexcept
Definition filesystem.hpp:3635
filesystem_error(const std::string &what_arg, std::error_code ec)
Definition filesystem.hpp:3597
const char * what() const noexcept override
Definition filesystem.hpp:3640
const path & path1() const noexcept
Definition filesystem.hpp:3630
Definition filesystem.hpp:333
not_implemented_exception()
Definition filesystem.hpp:335
Definition filesystem.hpp:672
reference operator*() const
Definition filesystem.hpp:3460
pointer operator->() const
Definition filesystem.hpp:3465
bool operator!=(const iterator &other) const
Definition filesystem.hpp:3455
std::bidirectional_iterator_tag iterator_category
Definition filesystem.hpp:678
std::ptrdiff_t difference_type
Definition filesystem.hpp:675
iterator()
Definition filesystem.hpp:3329
iterator & operator--()
Definition filesystem.hpp:3436
bool operator==(const iterator &other) const
Definition filesystem.hpp:3450
iterator & operator++()
Definition filesystem.hpp:3415
Definition filesystem.hpp:343
static constexpr value_type preferred_separator
Definition filesystem.hpp:349
char_type value_type
Definition filesystem.hpp:345
Definition filesystem.hpp:379
bool has_parent_path() const
Definition filesystem.hpp:3217
path & operator=(const path &p)
Definition filesystem.hpp:2535
bool has_root_path() const
Definition filesystem.hpp:3206
void clear() noexcept
Definition filesystem.hpp:2770
bool is_relative() const
Definition filesystem.hpp:3246
path parent_path() const
Definition filesystem.hpp:3115
std::basic_string< value_type > string_type
Definition filesystem.hpp:383
std::wstring wstring() const
Definition filesystem.hpp:2858
path & remove_filename()
Definition filesystem.hpp:2785
bool has_root_name() const
Definition filesystem.hpp:3195
path & make_preferred()
Definition filesystem.hpp:2778
typename std::enable_if<!std::is_same< path, T1 >::value, path >::type path_type
Definition filesystem.hpp:420
path & replace_extension(const path &replacement=path())
Definition filesystem.hpp:2799
path lexically_relative(const path &base) const
Definition filesystem.hpp:3286
const value_type * c_str() const noexcept
Definition filesystem.hpp:2825
iterator begin() const
Definition filesystem.hpp:3470
typename std::enable_if< _is_basic_string< T >::value||std::is_same< char const *, typename std::decay< T >::type >::value||std::is_same< char *, typename std::decay< T >::type >::value||std::is_same< char16_t const *, typename std::decay< T >::type >::value||std::is_same< char16_t *, typename std::decay< T >::type >::value||std::is_same< char32_t const *, typename std::decay< T >::type >::value||std::is_same< char32_t *, typename std::decay< T >::type >::value||std::is_same< wchar_t const *, typename std::decay< T >::type >::value||std::is_same< wchar_t *, typename std::decay< T >::type >::value, path >::type path_from_string
Definition filesystem.hpp:436
friend size_t hash_value(const path &p) noexcept
Definition filesystem.hpp:3487
bool is_absolute() const
Definition filesystem.hpp:3237
path & append(const Source &source)
Definition filesystem.hpp:2666
std::u16string u16string() const
Definition filesystem.hpp:2887
path root_directory() const
Definition filesystem.hpp:3095
bool has_stem() const
Definition filesystem.hpp:3227
format
The path format in which the constructor argument is given.
Definition filesystem.hpp:388
@ native_format
Definition filesystem.hpp:391
@ auto_format
Try to auto-detect the format, fallback to native.
Definition filesystem.hpp:393
@ generic_format
Definition filesystem.hpp:389
bool empty() const noexcept
Definition filesystem.hpp:3190
path stem() const
Definition filesystem.hpp:3141
std::string u8string() const
Definition filesystem.hpp:2877
std::u16string generic_u16string() const
Definition filesystem.hpp:2963
const string_type & native() const noexcept
Definition filesystem.hpp:2820
~path()
Definition filesystem.hpp:2530
std::u32string u32string() const
Definition filesystem.hpp:2893
std::string generic_string() const
Definition filesystem.hpp:2925
bool has_root_directory() const
Definition filesystem.hpp:3200
path filename() const
Definition filesystem.hpp:3136
path & concat(const Source &x)
Definition filesystem.hpp:2751
bool has_extension() const
Definition filesystem.hpp:3232
path extension() const
Definition filesystem.hpp:3153
path & operator/=(const path &p)
Definition filesystem.hpp:2608
path() noexcept
Definition filesystem.hpp:2480
std::string string() const
Definition filesystem.hpp:2849
friend void swap(path &lhs, path &rhs) noexcept
Definition filesystem.hpp:3482
std::u32string generic_u32string() const
Definition filesystem.hpp:2972
path & operator+=(const path &x)
Definition filesystem.hpp:2689
bool has_relative_path() const
Definition filesystem.hpp:3211
path & assign(string_type &&source)
Definition filesystem.hpp:2558
std::basic_string< EcharT, traits, Allocator > generic_string(const Allocator &a=Allocator()) const
Definition filesystem.hpp:2904
std::basic_string< EcharT, traits, Allocator > string(const Allocator &a=Allocator()) const
Definition filesystem.hpp:2838
typename std::enable_if< std::is_same< T, char >::value||std::is_same< T, char16_t >::value||std::is_same< T, char32_t >::value||std::is_same< T, wchar_t >::value, path >::type path_type_EcharT
Definition filesystem.hpp:438
path root_name() const
Definition filesystem.hpp:3090
path lexically_proximate(const path &base) const
Definition filesystem.hpp:3321
std::wstring generic_wstring() const
Definition filesystem.hpp:2934
path relative_path() const
Definition filesystem.hpp:3109
int compare(const path &p) const noexcept
Definition filesystem.hpp:2983
bool has_filename() const
Definition filesystem.hpp:3222
path root_path() const
Definition filesystem.hpp:3104
iterator end() const
Definition filesystem.hpp:3475
std::string generic_u8string() const
Definition filesystem.hpp:2953
path & replace_filename(const path &replacement)
Definition filesystem.hpp:2793
path lexically_normal() const
Definition filesystem.hpp:3253
Definition filesystem.hpp:979
directory_options options() const
Definition filesystem.hpp:5911
bool operator==(const recursive_directory_iterator &rhs) const
Definition filesystem.hpp:6019
void disable_recursion_pending()
Definition filesystem.hpp:6013
void pop(std::error_code &ec)
Definition filesystem.hpp:6000
recursive_directory_iterator() noexcept
Definition filesystem.hpp:5866
std::ptrdiff_t difference_type
Definition filesystem.hpp:983
const directory_entry & operator*() const
Definition filesystem.hpp:5926
const directory_entry * operator->() const
Definition filesystem.hpp:5931
bool operator!=(const recursive_directory_iterator &rhs) const
Definition filesystem.hpp:6024
recursive_directory_iterator & operator=(const recursive_directory_iterator &rhs)
Definition filesystem.hpp:5937
int depth() const
Definition filesystem.hpp:5916
~recursive_directory_iterator()
Definition filesystem.hpp:5908
recursive_directory_iterator & increment(std::error_code &ec) noexcept
Definition filesystem.hpp:5961
bool recursion_pending() const
Definition filesystem.hpp:5921
std::input_iterator_tag iterator_category
Definition filesystem.hpp:981
Definition filesystem.hpp:1258
~u8arguments()
Definition filesystem.hpp:1261
bool valid() const
Definition filesystem.hpp:1267
u8arguments(int &argc, char **&argv)
Definition filesystem.hpp:2446
#define GHC_INLINE
Definition filesystem.hpp:137
#define GHC_WIN_AUTO_PREFIX_LONG_PATH
Definition filesystem.hpp:304
#define GHC_PLATFORM_LITERAL(str)
#define PATH_MAX
Definition filesystem.hpp:259
#define GHC_FS_API_CLASS
Definition filesystem.hpp:142
#define GHC_FS_API
Definition filesystem.hpp:139
bool startsWith(const strT &what, const strT &with)
Definition filesystem.hpp:1775
file_type file_type_from_dirent(const T &t)
Definition filesystem.hpp:1361
std::string systemErrorText(ErrorNumber code=0)
Definition filesystem.hpp:1928
path resolveSymlink(const path &p, std::error_code &ec)
Definition filesystem.hpp:2182
StringType fromUtf8(const Utf8String &utf8String, const typename StringType::allocator_type &alloc=typename StringType::allocator_type())
Definition filesystem.hpp:1574
bool endsWith(const strT &what, const strT &with)
Definition filesystem.hpp:1781
bool is_not_found_error(std::error_code &ec)
Definition filesystem.hpp:2317
file_status symlink_status_ex(const path &p, std::error_code &ec, uintmax_t *sz=nullptr, uintmax_t *nhl=nullptr, time_t *lwt=nullptr) noexcept
Definition filesystem.hpp:2326
portable_error
Definition filesystem.hpp:1292
int compare_simple_insensitive(const path::value_type *str1, size_t len1, const path::value_type *str2, size_t len2)
Definition filesystem.hpp:1897
void create_symlink(const path &target_name, const path &new_symlink, bool, std::error_code &ec)
Definition filesystem.hpp:2012
const char * strerror_adapter(char *gnu, char *)
Definition filesystem.hpp:1914
bool in_range(uint32_t c, uint32_t lo, uint32_t hi)
Definition filesystem.hpp:1487
file_status status_ex(const path &p, std::error_code &ec, file_status *sls=nullptr, uintmax_t *sz=nullptr, uintmax_t *nhl=nullptr, time_t *lwt=nullptr, int recurse_count=0) noexcept
Definition filesystem.hpp:2364
typename std::enable_if< std::is_same< Enum, perms >::value||std::is_same< Enum, perm_options >::value||std::is_same< Enum, copy_options >::value||std::is_same< Enum, directory_options >::value, Enum >::type EnableBitmask
Definition filesystem.hpp:1431
file_status file_status_from_st_mode(T mode)
Definition filesystem.hpp:2030
unsigned consumeUtf8Fragment(const unsigned state, const uint8_t fragment, uint32_t &codepoint)
Definition filesystem.hpp:1539
bool validUtf8(const std::string &utf8String)
Definition filesystem.hpp:1551
file_type file_type_from_dirent_impl(const T &, std::false_type)
Definition filesystem.hpp:1314
bool is_low_surrogate(uint32_t c)
Definition filesystem.hpp:1502
std::error_code make_error_code(portable_error err)
Definition filesystem.hpp:1372
bool is_surrogate(uint32_t c)
Definition filesystem.hpp:1492
void create_hardlink(const path &target_name, const path &new_hardlink, std::error_code &ec)
Definition filesystem.hpp:2020
bool equals_simple_insensitive(const path::value_type *str1, const path::value_type *str2)
Definition filesystem.hpp:1876
std::string toUtf8(const strT &unicodeString)
Definition filesystem.hpp:1663
bool is_high_surrogate(uint32_t c)
Definition filesystem.hpp:1497
std::error_code make_system_error(int err=0)
Definition filesystem.hpp:1422
utf8_states_t
Definition filesystem.hpp:1286
@ S_STRT
Definition filesystem.hpp:1286
@ S_RJCT
Definition filesystem.hpp:1286
void appendUTF8(std::string &str, uint32_t unicode)
Definition filesystem.hpp:1507
Definition filesystem.hpp:319
path operator/(const path &lhs, const path &rhs)
Definition filesystem.hpp:3529
bool is_symlink(file_status s) noexcept
Definition filesystem.hpp:4546
file_status status(const path &p, std::error_code &ec) noexcept
Definition filesystem.hpp:5013
void create_hard_link(const path &to, const path &new_hard_link, std::error_code &ec) noexcept
Definition filesystem.hpp:4157
constexpr detail::EnableBitmask< Enum > operator&(Enum X, Enum Y)
Definition filesystem.hpp:1435
void create_directory_symlink(const path &to, const path &new_symlink, std::error_code &ec) noexcept
Definition filesystem.hpp:4140
uintmax_t remove_all(const path &p, std::error_code &ec) noexcept
Definition filesystem.hpp:4853
bool operator>(const path &lhs, const path &rhs) noexcept
Definition filesystem.hpp:3519
bool copy_file(const path &from, const path &to, std::error_code &ec) noexcept
Definition filesystem.hpp:3899
perms
Definition filesystem.hpp:727
bool status_known(file_status s) noexcept
Definition filesystem.hpp:5018
bool is_regular_file(file_status s) noexcept
Definition filesystem.hpp:4512
void resize_file(const path &p, uintmax_t size, std::error_code &ec) noexcept
Definition filesystem.hpp:4939
void swap(path &lhs, path &rhs) noexcept
Definition filesystem.hpp:3482
bool operator!=(const path &lhs, const path &rhs) noexcept
Definition filesystem.hpp:3504
path u8path(const Source &source)
Definition filesystem.hpp:1855
bool operator==(const path &lhs, const path &rhs) noexcept
Definition filesystem.hpp:3499
constexpr detail::EnableBitmask< Enum > operator^(Enum X, Enum Y)
Definition filesystem.hpp:1449
bool exists(file_status s) noexcept
Definition filesystem.hpp:4238
directory_options
Definition filesystem.hpp:783
@ follow_directory_symlink
directory_iterator end(const directory_iterator &) noexcept
Definition filesystem.hpp:5858
file_type
Definition filesystem.hpp:713
bool create_directory(const path &p, std::error_code &ec) noexcept
Definition filesystem.hpp:4069
bool is_fifo(file_status s) noexcept
Definition filesystem.hpp:4478
void create_symlink(const path &to, const path &new_symlink, std::error_code &ec) noexcept
Definition filesystem.hpp:4174
bool operator>=(const path &lhs, const path &rhs) noexcept
Definition filesystem.hpp:3524
detail::EnableBitmask< Enum > & operator&=(Enum &X, Enum Y)
Definition filesystem.hpp:1463
bool operator<=(const path &lhs, const path &rhs) noexcept
Definition filesystem.hpp:3514
std::chrono::time_point< std::chrono::system_clock > file_time_type
Definition filesystem.hpp:815
constexpr detail::EnableBitmask< Enum > operator~(Enum X)
Definition filesystem.hpp:1456
basic_fstream< wchar_t > wfstream
Definition filesystem.hpp:1255
bool equivalent(const path &p1, const path &p2, std::error_code &ec) noexcept
Definition filesystem.hpp:4271
bool is_empty(const path &p, std::error_code &ec) noexcept
Definition filesystem.hpp:4456
constexpr detail::EnableBitmask< Enum > operator|(Enum X, Enum Y)
Definition filesystem.hpp:1442
uintmax_t hard_link_count(const path &p, std::error_code &ec) noexcept
Definition filesystem.hpp:4363
bool is_character_file(file_status s) noexcept
Definition filesystem.hpp:4410
file_time_type last_write_time(const path &p, std::error_code &ec) noexcept
Definition filesystem.hpp:4575
bool operator<(const path &lhs, const path &rhs) noexcept
Definition filesystem.hpp:3509
path canonical(const path &p, std::error_code &ec)
Definition filesystem.hpp:3720
basic_filebuf< char > filebuf
Definition filesystem.hpp:1248
path relative(const path &p, std::error_code &ec)
Definition filesystem.hpp:4763
directory_iterator begin(directory_iterator iter) noexcept
Definition filesystem.hpp:5853
copy_options
Definition filesystem.hpp:763
std::basic_istream< charT, traits > & operator>>(std::basic_istream< charT, traits > &is, path &p)
Definition filesystem.hpp:3556
basic_filebuf< wchar_t > wfilebuf
Definition filesystem.hpp:1249
path temp_directory_path(std::error_code &ec) noexcept
Definition filesystem.hpp:5052
basic_ifstream< wchar_t > wifstream
Definition filesystem.hpp:1251
bool is_directory(file_status s) noexcept
Definition filesystem.hpp:4427
path absolute(const path &p, std::error_code &ec)
Definition filesystem.hpp:3659
detail::EnableBitmask< Enum > & operator|=(Enum &X, Enum Y)
Definition filesystem.hpp:1470
basic_ofstream< char > ofstream
Definition filesystem.hpp:1252
path weakly_canonical(const path &p, std::error_code &ec) noexcept
Definition filesystem.hpp:5088
basic_fstream< char > fstream
Definition filesystem.hpp:1254
bool is_other(file_status s) noexcept
Definition filesystem.hpp:4495
space_info space(const path &p, std::error_code &ec) noexcept
Definition filesystem.hpp:4979
path proximate(const path &p, std::error_code &ec)
bool is_block_file(file_status s) noexcept
Definition filesystem.hpp:4393
bool is_socket(file_status s) noexcept
Definition filesystem.hpp:4529
perm_options
Definition filesystem.hpp:755
path current_path(std::error_code &ec)
Definition filesystem.hpp:4191
basic_ofstream< wchar_t > wofstream
Definition filesystem.hpp:1253
size_t hash_value(const path &p) noexcept
Definition filesystem.hpp:3487
path read_symlink(const path &p, std::error_code &ec)
Definition filesystem.hpp:4752
basic_ifstream< char > ifstream
Definition filesystem.hpp:1250
void rename(const path &from, const path &to, std::error_code &ec) noexcept
Definition filesystem.hpp:4910
void copy_symlink(const path &existing_symlink, const path &new_symlink, std::error_code &ec) noexcept
Definition filesystem.hpp:3992
uintmax_t file_size(const path &p, std::error_code &ec) noexcept
Definition filesystem.hpp:4330
detail::EnableBitmask< Enum > & operator^=(Enum &X, Enum Y)
Definition filesystem.hpp:1477
file_status symlink_status(const path &p, std::error_code &ec) noexcept
Definition filesystem.hpp:5035
void copy(const path &from, const path &to, std::error_code &ec) noexcept
Definition filesystem.hpp:3799
bool create_directories(const path &p, std::error_code &ec) noexcept
Definition filesystem.hpp:4018
void permissions(const path &p, perms prms, std::error_code &ec) noexcept
Definition filesystem.hpp:4666
Definition filesystem.hpp:318
Definition filesystem.hpp:1308
Definition filesystem.hpp:398
Definition filesystem.hpp:705
uintmax_t free
Definition filesystem.hpp:707
uintmax_t available
Definition filesystem.hpp:708
uintmax_t capacity
Definition filesystem.hpp:706