From 270d6876dc277fbe4a65ffbb1d6f3c7db3fc5ce2 Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Tue, 26 Oct 2021 07:57:43 +0200 Subject: [PATCH] Work on shared/static library mode Took 1 hour 56 minutes --- .clang-format | 2 +- CMakeLists.txt | 26 +- README.md | 2 +- cmake/config.cmake.in | 2 +- include/ghc/filesystem.hpp | 1195 ++++++++++++++++++------------------ src/filesystem.cpp | 28 + test/CMakeLists.txt | 12 + test/filesystem_test.cpp | 187 +++--- 8 files changed, 757 insertions(+), 697 deletions(-) create mode 100644 src/filesystem.cpp diff --git a/.clang-format b/.clang-format index b24fe34..7d6162c 100644 --- a/.clang-format +++ b/.clang-format @@ -21,5 +21,5 @@ BraceWrapping: SplitEmptyNamespace: true BreakConstructorInitializers: BeforeComma ConstructorInitializerAllOnOneLineOrOnePerLine: false -IndentPPDirectives: None +IndentPPDirectives: AfterHash ... diff --git a/CMakeLists.txt b/CMakeLists.txt index f6b7f54..4e1b5b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.7.2) -project(ghcfilesystem) +project(ghc_filesystem) if (POLICY CMP0077) cmake_policy(SET CMP0077 NEW) @@ -17,6 +17,8 @@ else() option(GHC_FILESYSTEM_BUILD_TESTING "Enable tests" OFF) option(GHC_FILESYSTEM_WITH_INSTALL "With install target" ON) endif() +option(GHC_FILESYSTEM_BUILD_STATIC "Enable building static library" OFF) +option(GHC_FILESYSTEM_BUILD_SHARED "Enable building shared library" OFF) option(GHC_FILESYSTEM_BUILD_STD_TESTING "Enable STD tests" ${GHC_FILESYSTEM_BUILD_TESTING}) if(NOT DEFINED GHC_FILESYSTEM_TEST_COMPILE_FEATURES) set(GHC_FILESYSTEM_TEST_COMPILE_FEATURES ${CMAKE_CXX_COMPILE_FEATURES}) @@ -41,6 +43,28 @@ target_include_directories(ghc_filesystem INTERFACE target_compile_options(ghc_filesystem INTERFACE "$<$:/utf-8>") target_compile_options(ghc_filesystem INTERFACE "$<$:/utf-8>") +if(GHC_FILESYSTEM_BUILD_STATIC) + add_library(ghc_filesystem_static STATIC src/filesystem.cpp) + target_include_directories(ghc_filesystem_static PUBLIC + $ + $) + target_compile_definitions(ghc_filesystem_static PRIVATE GHC_FILESYSTEM_IMPLEMENTATION) + target_compile_definitions(ghc_filesystem_static INTERFACE GHC_FILESYSTEM_FWD) + target_compile_options(ghc_filesystem_static PUBLIC "$<$:/utf-8>") + target_compile_options(ghc_filesystem_static PUBLIC "$<$:/utf-8>") +endif() + +if(GHC_FILESYSTEM_BUILD_SHARED) + add_library(ghc_filesystem_shared SHARED src/filesystem.cpp) + target_include_directories(ghc_filesystem_shared PUBLIC + $ + $) + target_compile_definitions(ghc_filesystem_shared PRIVATE GHC_FILESYSTEM_IMPLEMENTATION GHC_FILESYSTEM_SHARED) + target_compile_definitions(ghc_filesystem_shared INTERFACE GHC_FILESYSTEM_FWD GHC_FILESYSTEM_SHARED) + target_compile_options(ghc_filesystem_shared PUBLIC "$<$:/utf-8>") + target_compile_options(ghc_filesystem_shared PUBLIC "$<$:/utf-8>") +endif() + if(GHC_FILESYSTEM_BUILD_TESTING OR GHC_FILESYSTEM_BUILD_EXAMPLES) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") diff --git a/README.md b/README.md index 6b525b8..de08fd9 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ for more information._ Unit tests are currently run with: -* macOS 10.12: Xcode 9.2 (clang-900.0.39.2), GCC 9.2, Clang 9.0, macOS 10.13: Xcode 10.1, macOS 10.14: Xcode 11.2, macOS 10.15: Xcode 11.6, Xcode 12.4 +* macOS 10.12: Xcode 9.2 (clang-900.0.39.2), GCC 9.2, Clang 9.0, macOS 10.13: Xcode 10.1, macOS 10.14: Xcode 11.2, macOS 10.15: Xcode 11.6, Xcode 12.4, macOS 11.6: Xcode 13.0 * Windows: Visual Studio 2017, Visual Studio 2015, Visual Studio 2019, MinGW GCC 6.3 (Win32), GCC 7.2 (Win64), Cygwin GCC 10.2 (no CI yet) * Linux (Ubuntu): GCC (5.5, 6.5, 7.4, 8.3, 9.2), Clang (5.0, 6.0, 7.1, 8.0, 9.0) * Linux (Alpine ARM/ARM64): GCC 9.2.0 diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index ace9761..4750acd 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -3,4 +3,4 @@ # import targets include("${CMAKE_CURRENT_LIST_DIR}/ghc_filesystem-targets.cmake") -check_required_components(ghcfilesystem) \ No newline at end of file +check_required_components(ghc_filesystem) \ No newline at end of file diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index a319def..fa02e00 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -48,210 +48,200 @@ // #define BSD manifest constant only in // sys/param.h #ifndef _WIN32 -#include +# include #endif #ifndef GHC_OS_DETECTED -#if defined(__APPLE__) && defined(__MACH__) -#define GHC_OS_MACOS -#elif defined(__linux__) -#define GHC_OS_LINUX -#if defined(__ANDROID__) -#define GHC_OS_ANDROID +# if defined(__APPLE__) && defined(__MACH__) +# define GHC_OS_MACOS +# elif defined(__linux__) +# define GHC_OS_LINUX +# if defined(__ANDROID__) +# define GHC_OS_ANDROID +# endif +# elif defined(_WIN64) +# define GHC_OS_WINDOWS +# define GHC_OS_WIN64 +# elif defined(_WIN32) +# define GHC_OS_WINDOWS +# define GHC_OS_WIN32 +# elif defined(__CYGWIN__) +# define GHC_OS_CYGWIN +# elif defined(__svr4__) +# define GHC_OS_SYS5R4 +# elif defined(BSD) +# define GHC_OS_BSD +# elif defined(__EMSCRIPTEN__) +# define GHC_OS_WEB +# include +# elif defined(__QNX__) +# define GHC_OS_QNX +# define GHC_NO_DIRENT_D_TYPE +# else +# error "Operating system currently not supported!" +# endif +# define GHC_OS_DETECTED +# if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +# if _MSVC_LANG == 201703L +# define GHC_FILESYSTEM_RUNNING_CPP17 +# else +# define GHC_FILESYSTEM_RUNNING_CPP20 +# endif +# elif (defined(__cplusplus) && __cplusplus >= 201703L) +# if __cplusplus == 201703L +# define GHC_FILESYSTEM_RUNNING_CPP17 +# else +# define GHC_FILESYSTEM_RUNNING_CPP20 +# endif +# endif #endif -#elif defined(_WIN64) -#define GHC_OS_WINDOWS -#define GHC_OS_WIN64 -#elif defined(_WIN32) -#define GHC_OS_WINDOWS -#define GHC_OS_WIN32 -#elif defined(__CYGWIN__) -#define GHC_OS_CYGWIN -#elif defined(__svr4__) -#define GHC_OS_SYS5R4 -#elif defined(BSD) -#define GHC_OS_BSD -#elif defined(__EMSCRIPTEN__) -#define GHC_OS_WEB -#include -#elif defined(__QNX__) -#define GHC_OS_QNX -#define GHC_NO_DIRENT_D_TYPE + +#if defined GHC_OS_WINDOWS +#define GHC_FS_DLL_IMPORT __declspec(dllimport) +#define GHC_FS_DLL_EXPORT __declspec(dllexport) +#define GHC_FS_DLL_LOCAL #else -#error "Operating system currently not supported!" -#endif -#define GHC_OS_DETECTED -#if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) -#if _MSVC_LANG == 201703L -#define GHC_FILESYSTEM_RUNNING_CPP17 -#else -#define GHC_FILESYSTEM_RUNNING_CPP20 -#endif -#elif (defined(__cplusplus) && __cplusplus >= 201703L) -#if __cplusplus == 201703L -#define GHC_FILESYSTEM_RUNNING_CPP17 -#else -#define GHC_FILESYSTEM_RUNNING_CPP20 -#endif -#endif +#define GHC_FS_DLL_IMPORT __attribute__ ((visibility ("default"))) +#define GHC_FS_DLL_EXPORT __attribute__ ((visibility ("default"))) +#define GHC_FS_DLL_LOCAL __attribute__ ((visibility ("hidden"))) #endif #if defined(GHC_FILESYSTEM_IMPLEMENTATION) -#define GHC_EXPAND_IMPL -#define GHC_INLINE -#ifdef GHC_OS_WINDOWS -#ifndef GHC_FS_API -#define GHC_FS_API -#endif -#ifndef GHC_FS_API_CLASS -#define GHC_FS_API_CLASS -#endif -#else -#ifndef GHC_FS_API -#define GHC_FS_API __attribute__((visibility("default"))) -#endif -#ifndef GHC_FS_API_CLASS -#define GHC_FS_API_CLASS __attribute__((visibility("default"))) -#endif -#endif +# define GHC_EXPAND_IMPL +# define GHC_INLINE +# ifdef GHC_FILESYSTEM_SHARED +# define GHC_FS_API GHC_FS_DLL_EXPORT +# define GHC_FS_API_CLASS GHC_FS_DLL_EXPORT +# else +# define GHC_FS_API +# define GHC_FS_API_CLASS +# endif #elif defined(GHC_FILESYSTEM_FWD) -#define GHC_INLINE -#ifdef GHC_OS_WINDOWS -#ifndef GHC_FS_API -#define GHC_FS_API extern -#endif -#ifndef GHC_FS_API_CLASS -#define GHC_FS_API_CLASS -#endif -#else -#ifndef GHC_FS_API -#define GHC_FS_API extern -#endif -#ifndef GHC_FS_API_CLASS -#define GHC_FS_API_CLASS -#endif -#endif -#else -#define GHC_EXPAND_IMPL -#define GHC_INLINE inline -#ifndef GHC_FS_API -#define GHC_FS_API -#endif -#ifndef GHC_FS_API_CLASS -#define GHC_FS_API_CLASS -#endif +# define GHC_INLINE +# ifdef GHC_FILESYSTEM_SHARED +# define GHC_FS_API GHC_FS_DLL_IMPORT +# define GHC_FS_API_CLASS GHC_FS_DLL_IMPORT +# else // static instead +# define GHC_FS_API extern +# define GHC_FS_API_CLASS +# endif +#else // header-only +# define GHC_EXPAND_IMPL +# define GHC_INLINE inline +# define GHC_FS_API +# define GHC_FS_API_CLASS #endif #ifdef GHC_EXPAND_IMPL -#ifdef GHC_OS_WINDOWS -#include +# ifdef GHC_OS_WINDOWS +# include // additional includes -#include -#include -#include -#include -#include -#else -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef GHC_OS_ANDROID -#include -#if __ANDROID_API__ < 12 -#include -#endif -#include -#define statvfs statfs -#else -#include -#endif -#ifdef GHC_OS_CYGWIN -#include -#endif -#if !defined(__ANDROID__) || __ANDROID_API__ >= 26 -#include -#endif -#endif -#ifdef GHC_OS_MACOS -#include -#endif +# include +# include +# include +# include +# include +# else +# include +# include +# include +# include +# include +# include +# include +# include +# ifdef GHC_OS_ANDROID +# include +# if __ANDROID_API__ < 12 +# include +# endif +# include +# define statvfs statfs +# else +# include +# endif +# ifdef GHC_OS_CYGWIN +# include +# endif +# if !defined(__ANDROID__) || __ANDROID_API__ >= 26 +# include +# endif +# endif +# ifdef GHC_OS_MACOS +# include +# endif -#if defined(__cpp_impl_three_way_comparison) && defined(__has_include) -#if __has_include() -#define GHC_HAS_THREEWAY_COMP -#include -#endif -#endif +# if defined(__cpp_impl_three_way_comparison) && defined(__has_include) +# if __has_include() +# define GHC_HAS_THREEWAY_COMP +# include +# endif +# endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include #else // GHC_EXPAND_IMPL -#if defined(__cpp_impl_three_way_comparison) && defined(__has_include) -#if __has_include() -#define GHC_HAS_THREEWAY_COMP -#include -#endif -#endif -#include -#include -#include -#include -#include -#include -#include -#ifdef GHC_OS_WINDOWS -#include -#endif +# if defined(__cpp_impl_three_way_comparison) && defined(__has_include) +# if __has_include() +# define GHC_HAS_THREEWAY_COMP +# include +# endif +# endif +# include +# include +# include +# include +# include +# include +# include +# ifdef GHC_OS_WINDOWS +# include +# endif #endif // GHC_EXPAND_IMPL // After standard library includes. // Standard library support for std::string_view. #if defined(__cpp_lib_string_view) -#define GHC_HAS_STD_STRING_VIEW +# define GHC_HAS_STD_STRING_VIEW #elif defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION >= 4000) && (__cplusplus >= 201402) -#define GHC_HAS_STD_STRING_VIEW +# define GHC_HAS_STD_STRING_VIEW #elif defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE >= 7) && (__cplusplus >= 201703) -#define GHC_HAS_STD_STRING_VIEW +# define GHC_HAS_STD_STRING_VIEW #elif defined(_MSC_VER) && (_MSC_VER >= 1910 && _MSVC_LANG >= 201703) -#define GHC_HAS_STD_STRING_VIEW +# define GHC_HAS_STD_STRING_VIEW #endif // Standard library support for std::experimental::string_view. #if defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION >= 3700 && _LIBCPP_VERSION < 7000) && (__cplusplus >= 201402) -#define GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW +# define GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW #elif defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4)) && (__cplusplus >= 201402) -#define GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW +# define GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW #elif defined(__GLIBCXX__) && defined(_GLIBCXX_USE_DUAL_ABI) && (__cplusplus >= 201402) // macro _GLIBCXX_USE_DUAL_ABI is always defined in libstdc++ from gcc-5 and newer -#define GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW +# define GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW #endif #if defined(GHC_HAS_STD_STRING_VIEW) -#include +# include #elif defined(GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW) -#include +# include #endif //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -296,30 +286,30 @@ // Automatic prefix windows path with "\\?\" if they would break the MAX_PATH length. // instead of replacing them with the unicode replacement character (U+FFFD). #ifndef GHC_WIN_DISABLE_AUTO_PREFIXES -#define GHC_WIN_AUTO_PREFIX_LONG_PATH +# define GHC_WIN_AUTO_PREFIX_LONG_PATH #endif // GHC_WIN_DISABLE_AUTO_PREFIXES //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ghc::filesystem version in decimal (major * 10000 + minor * 100 + patch) -#define GHC_FILESYSTEM_VERSION 10510L +#define GHC_FILESYSTEM_VERSION 10599L #if !defined(GHC_WITH_EXCEPTIONS) && (defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)) -#define GHC_WITH_EXCEPTIONS +# define GHC_WITH_EXCEPTIONS #endif #if !defined(GHC_WITH_EXCEPTIONS) && defined(GHC_RAISE_UNICODE_ERRORS) -#error "Can't raise unicode errors with exception support disabled" +# error "Can't raise unicode errors with exception support disabled" #endif namespace ghc { namespace filesystem { #if defined(GHC_HAS_CUSTOM_STRING_VIEW) -#define GHC_WITH_STRING_VIEW +# define GHC_WITH_STRING_VIEW #elif defined(GHC_HAS_STD_STRING_VIEW) -#define GHC_WITH_STRING_VIEW +# define GHC_WITH_STRING_VIEW using std::basic_string_view; #elif defined(GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW) -#define GHC_WITH_STRING_VIEW +# define GHC_WITH_STRING_VIEW using std::experimental::basic_string_view; #endif @@ -345,6 +335,13 @@ public: #endif }; + +#if defined(GHC_OS_WINDOWS) && !defined(GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE) +template class GHC_FS_API_CLASS path_helper_base; +#else +template class GHC_FS_API_CLASS path_helper_base; +#endif + #if __cplusplus < 201703L template constexpr char_type path_helper_base::preferred_separator; @@ -360,16 +357,16 @@ bool has_executable_extension(const path& p); // [fs.class.path] class path class GHC_FS_API_CLASS path #if defined(GHC_OS_WINDOWS) && !defined(GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE) -#define GHC_USE_WCHAR_T -#define GHC_NATIVEWP(p) p.c_str() -#define GHC_PLATFORM_LITERAL(str) L##str +# define GHC_USE_WCHAR_T +# define GHC_NATIVEWP(p) p.c_str() +# define GHC_PLATFORM_LITERAL(str) L##str : private path_helper_base { public: using path_helper_base::value_type; #else -#define GHC_NATIVEWP(p) p.wstring().c_str() -#define GHC_PLATFORM_LITERAL(str) str +# define GHC_NATIVEWP(p) p.wstring().c_str() +# define GHC_PLATFORM_LITERAL(str) str : private path_helper_base { public: @@ -604,11 +601,11 @@ private: #ifdef GHC_OS_WINDOWS void handle_prefixes(); friend bool detail::has_executable_extension(const path& p); -#ifdef GHC_WIN_AUTO_PREFIX_LONG_PATH +# ifdef GHC_WIN_AUTO_PREFIX_LONG_PATH string_type::size_type _prefixLength{0}; -#else // GHC_WIN_AUTO_PREFIX_LONG_PATH +# else // GHC_WIN_AUTO_PREFIX_LONG_PATH static const string_type::size_type _prefixLength{0}; -#endif // GHC_WIN_AUTO_PREFIX_LONG_PATH +# endif // GHC_WIN_AUTO_PREFIX_LONG_PATH #else static const string_type::size_type _prefixLength{0}; #endif @@ -870,9 +867,9 @@ public: file_status symlink_status(std::error_code& ec) const noexcept; #ifndef GHC_OS_WEB -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS uintmax_t hard_link_count() const; -#endif +# endif uintmax_t hard_link_count(std::error_code& ec) const noexcept; #endif @@ -1144,10 +1141,10 @@ GHC_FS_API path temp_directory_path(std::error_code& ec) noexcept; GHC_FS_API path weakly_canonical(const path& p, std::error_code& ec) noexcept; #ifndef GHC_OS_WEB -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_FS_API void create_hard_link(const path& to, const path& new_hard_link); GHC_FS_API uintmax_t hard_link_count(const path& p); -#endif +# endif GHC_FS_API void create_hard_link(const path& to, const path& new_hard_link, std::error_code& ec) noexcept; GHC_FS_API uintmax_t hard_link_count(const path& p, std::error_code& ec) noexcept; #endif @@ -1307,7 +1304,7 @@ namespace detail { GHC_INLINE std::error_code make_error_code(portable_error err) { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS switch (err) { case portable_error::none: return std::error_code(); @@ -1322,13 +1319,13 @@ GHC_INLINE std::error_code make_error_code(portable_error err) case portable_error::invalid_argument: return std::error_code(ERROR_INVALID_PARAMETER, std::system_category()); case portable_error::is_a_directory: -#ifdef ERROR_DIRECTORY_NOT_SUPPORTED +# ifdef ERROR_DIRECTORY_NOT_SUPPORTED return std::error_code(ERROR_DIRECTORY_NOT_SUPPORTED, std::system_category()); -#else +# else return std::error_code(ERROR_NOT_SUPPORTED, std::system_category()); -#endif +# endif } -#else +# else switch (err) { case portable_error::none: return std::error_code(); @@ -1345,21 +1342,21 @@ GHC_INLINE std::error_code make_error_code(portable_error err) case portable_error::is_a_directory: return std::error_code(EISDIR, std::system_category()); } -#endif +# endif return std::error_code(); } -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS GHC_INLINE std::error_code make_system_error(uint32_t err) { return std::error_code(err ? static_cast(err) : static_cast(::GetLastError()), std::system_category()); } -#else +# else GHC_INLINE std::error_code make_system_error(int err) { return std::error_code(err ? err : errno, std::system_category()); } -#endif +# endif #endif // GHC_EXPAND_IMPL @@ -1461,11 +1458,11 @@ GHC_INLINE void appendUTF8(std::string& str, uint32_t unicode) str.push_back(static_cast((unicode & 0x3f) + 128)); } else { -#ifdef GHC_RAISE_UNICODE_ERRORS +# ifdef GHC_RAISE_UNICODE_ERRORS throw filesystem_error("Illegal code point for unicode character.", str, std::make_error_code(std::errc::illegal_byte_sequence)); -#else +# else appendUTF8(str, 0xfffd); -#endif +# endif } } @@ -1693,11 +1690,11 @@ inline std::wstring toWChar(const strT& unicodeString) template inline std::wstring toWChar(const charT* unicodeString) { -#ifdef GHC_WITH_STRING_VIEW +# ifdef GHC_WITH_STRING_VIEW return toWChar(basic_string_view>(unicodeString)); -#else +# else return toWChar(std::basic_string>(unicodeString)); -#endif +# endif } #endif // GHC_USE_WCHAR_T @@ -1723,24 +1720,24 @@ GHC_INLINE bool endsWith(const strT& what, const strT& with) GHC_INLINE void path::check_long_path() { -#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) +# if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) if (is_absolute() && _path.length() >= MAX_PATH - 12 && !detail::startsWith(_path, impl_string_type(GHC_PLATFORM_LITERAL("\\\\?\\")))) { postprocess_path_with_format(native_format); } -#endif +# endif } GHC_INLINE void path::postprocess_path_with_format(path::format fmt) { -#ifdef GHC_RAISE_UNICODE_ERRORS +# ifdef GHC_RAISE_UNICODE_ERRORS if (!detail::validUtf8(_path)) { path t; t._path = _path; throw filesystem_error("Illegal byte sequence for unicode character.", t, std::make_error_code(std::errc::illegal_byte_sequence)); } -#endif +# endif switch (fmt) { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS case path::native_format: case path::auto_format: case path::generic_format: @@ -1749,20 +1746,20 @@ GHC_INLINE void path::postprocess_path_with_format(path::format fmt) c = preferred_separator; } } -#ifdef GHC_WIN_AUTO_PREFIX_LONG_PATH +# ifdef GHC_WIN_AUTO_PREFIX_LONG_PATH if (is_absolute() && _path.length() >= MAX_PATH - 12 && !detail::startsWith(_path, impl_string_type(GHC_PLATFORM_LITERAL("\\\\?\\")))) { _path = GHC_PLATFORM_LITERAL("\\\\?\\") + _path; } -#endif +# endif handle_prefixes(); break; -#else +# else case path::auto_format: case path::native_format: case path::generic_format: // nothing to do break; -#endif +# endif } if (_path.length() > _prefixLength + 2 && _path[_prefixLength] == preferred_separator && _path[_prefixLength + 1] == preferred_separator && _path[_prefixLength + 2] != preferred_separator) { impl_string_type::iterator new_end = std::unique(_path.begin() + static_cast(_prefixLength) + 2, _path.end(), [](path::value_type lhs, path::value_type rhs) { return lhs == rhs && lhs == preferred_separator; }); @@ -1811,23 +1808,23 @@ namespace detail { GHC_INLINE bool equals_simple_insensitive(const path::value_type* str1, const path::value_type* str2) { -#ifdef GHC_OS_WINDOWS -#ifdef __GNUC__ +# ifdef GHC_OS_WINDOWS +# ifdef __GNUC__ while (::tolower((unsigned char)*str1) == ::tolower((unsigned char)*str2++)) { if (*str1++ == 0) return true; } return false; -#else // __GNUC__ -#ifdef GHC_USE_WCHAR_T +# else // __GNUC__ +# ifdef GHC_USE_WCHAR_T return 0 == ::_wcsicmp(str1, str2); -#else // GHC_USE_WCHAR_T +# else // GHC_USE_WCHAR_T return 0 == ::_stricmp(str1, str2); -#endif // GHC_USE_WCHAR_T -#endif // __GNUC__ -#else // GHC_OS_WINDOWS +# endif // GHC_USE_WCHAR_T +# endif // __GNUC__ +# else // GHC_OS_WINDOWS return 0 == ::strcasecmp(str1, str2); -#endif // GHC_OS_WINDOWS +# endif // GHC_OS_WINDOWS } GHC_INLINE int compare_simple_insensitive(const path::value_type* str1, size_t len1, const path::value_type* str2, size_t len2) @@ -1863,20 +1860,20 @@ GHC_INLINE const char* strerror_adapter(int posix, char* buffer) template GHC_INLINE std::string systemErrorText(ErrorNumber code = 0) { -#if defined(GHC_OS_WINDOWS) +# if defined(GHC_OS_WINDOWS) LPVOID msgBuf; DWORD dw = code ? static_cast(code) : ::GetLastError(); FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&msgBuf, 0, NULL); std::string msg = toUtf8(std::wstring((LPWSTR)msgBuf)); LocalFree(msgBuf); return msg; -#else +# else char buffer[512]; return strerror_adapter(strerror_r(code ? code : errno, buffer, sizeof(buffer)), buffer); -#endif +# endif } -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS using CreateSymbolicLinkW_fp = BOOLEAN(WINAPI*)(LPCWSTR, LPCWSTR, DWORD); using CreateHardLinkW_fp = BOOLEAN(WINAPI*)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES); @@ -1888,14 +1885,14 @@ GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, ec = detail::make_error_code(detail::portable_error::not_supported); return; } -#if defined(__GNUC__) && __GNUC__ >= 8 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-function-type" -#endif +# if defined(__GNUC__) && __GNUC__ >= 8 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wcast-function-type" +# endif static CreateSymbolicLinkW_fp api_call = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "CreateSymbolicLinkW")); -#if defined(__GNUC__) && __GNUC__ >= 8 -#pragma GCC diagnostic pop -#endif +# if defined(__GNUC__) && __GNUC__ >= 8 +# pragma GCC diagnostic pop +# endif if (api_call) { if (api_call(GHC_NATIVEWP(new_symlink), GHC_NATIVEWP(target_name), to_directory ? 1 : 0) == 0) { auto result = ::GetLastError(); @@ -1912,14 +1909,14 @@ GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, GHC_INLINE void create_hardlink(const path& target_name, const path& new_hardlink, std::error_code& ec) { -#if defined(__GNUC__) && __GNUC__ >= 8 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-function-type" -#endif +# if defined(__GNUC__) && __GNUC__ >= 8 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wcast-function-type" +# endif static CreateHardLinkW_fp api_call = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "CreateHardLinkW")); -#if defined(__GNUC__) && __GNUC__ >= 8 -#pragma GCC diagnostic pop -#endif +# if defined(__GNUC__) && __GNUC__ >= 8 +# pragma GCC diagnostic pop +# endif if (api_call) { if (api_call(GHC_NATIVEWP(new_hardlink), GHC_NATIVEWP(target_name), NULL) == 0) { ec = detail::make_system_error(); @@ -1944,7 +1941,7 @@ GHC_INLINE path getFullPathName(const wchar_t* p, std::error_code& ec) return path(); } -#else +# else GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, bool, std::error_code& ec) { if (::symlink(target_name.c_str(), new_symlink.c_str()) != 0) { @@ -1952,20 +1949,20 @@ GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, } } -#ifndef GHC_OS_WEB +# ifndef GHC_OS_WEB GHC_INLINE void create_hardlink(const path& target_name, const path& new_hardlink, std::error_code& ec) { if (::link(target_name.c_str(), new_hardlink.c_str()) != 0) { ec = detail::make_system_error(); } } -#endif -#endif +# endif +# endif template GHC_INLINE file_status file_status_from_st_mode(T mode) { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS file_type ft = file_type::unknown; if ((mode & _S_IFDIR) == _S_IFDIR) { ft = file_type::directory; @@ -1978,7 +1975,7 @@ GHC_INLINE file_status file_status_from_st_mode(T mode) } perms prms = static_cast(mode & 0xfff); return file_status(ft, prms); -#else +# else file_type ft = file_type::unknown; if (S_ISDIR(mode)) { ft = file_type::directory; @@ -2003,10 +2000,10 @@ GHC_INLINE file_status file_status_from_st_mode(T mode) } perms prms = static_cast(mode & 0xfff); return file_status(ft, prms); -#endif +# endif } -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS class unique_handle { @@ -2053,7 +2050,7 @@ private: element_type _handle; }; -#ifndef REPARSE_DATA_BUFFER_HEADER_SIZE +# ifndef REPARSE_DATA_BUFFER_HEADER_SIZE typedef struct _REPARSE_DATA_BUFFER { ULONG ReparseTag; @@ -2084,10 +2081,10 @@ typedef struct _REPARSE_DATA_BUFFER } GenericReparseBuffer; } DUMMYUNIONNAME; } REPARSE_DATA_BUFFER; -#ifndef MAXIMUM_REPARSE_DATA_BUFFER_SIZE -#define MAXIMUM_REPARSE_DATA_BUFFER_SIZE (16 * 1024) -#endif -#endif +# ifndef MAXIMUM_REPARSE_DATA_BUFFER_SIZE +# define MAXIMUM_REPARSE_DATA_BUFFER_SIZE (16 * 1024) +# endif +# endif template struct free_deleter @@ -2113,11 +2110,11 @@ GHC_INLINE std::unique_ptr buffer(bufferSize, static_cast(0)); @@ -2163,10 +2160,10 @@ GHC_INLINE path resolveSymlink(const path& p, std::error_code& ec) bufferSize *= 2; } return path(); -#endif +# endif } -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS GHC_INLINE time_t timeFromFILETIME(const FILETIME& ft) { ULARGE_INTEGER ull; @@ -2248,20 +2245,20 @@ GHC_INLINE file_status status_from_INFO(const path& p, const INFO* info, std::er return file_status(ft, prms); } -#endif +# endif GHC_INLINE bool is_not_found_error(std::error_code& ec) { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS return ec.value() == ERROR_FILE_NOT_FOUND || ec.value() == ERROR_PATH_NOT_FOUND || ec.value() == ERROR_INVALID_NAME; -#else +# else return ec.value() == ENOENT || ec.value() == ENOTDIR; -#endif +# endif } GHC_INLINE 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 { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS file_status fs; WIN32_FILE_ATTRIBUTE_DATA attr; if (!GetFileAttributesExW(GHC_NATIVEWP(p), GetFileExInfoStandard, &attr)) { @@ -2278,7 +2275,7 @@ GHC_INLINE file_status symlink_status_ex(const path& p, std::error_code& ec, uin return file_status(file_type::not_found); } return ec ? file_status(file_type::none) : fs; -#else +# else (void)sz; (void)nhl; (void)lwt; @@ -2294,13 +2291,13 @@ GHC_INLINE file_status symlink_status_ex(const path& p, std::error_code& ec, uin return file_status(file_type::not_found, perms::unknown); } return file_status(file_type::none); -#endif +# endif } GHC_INLINE 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 { ec.clear(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS if (recurse_count > 16) { ec = detail::make_system_error(0x2A9 /*ERROR_STOPPED_ON_SYMLINK*/); return file_status(file_type::unknown); @@ -2333,7 +2330,7 @@ GHC_INLINE file_status status_ex(const path& p, std::error_code& ec, file_status *nhl = 0; } return detail::status_from_INFO(p, &attr, ec, sz, lwt); -#else +# else (void)recurse_count; struct ::stat st; auto result = ::lstat(p.c_str(), &st); @@ -2374,7 +2371,7 @@ GHC_INLINE file_status status_ex(const path& p, std::error_code& ec, file_status } return file_status(file_type::none); } -#endif +# endif } } // namespace detail @@ -2386,7 +2383,7 @@ GHC_INLINE u8arguments::u8arguments(int& argc, char**& argv) , _refargv(argv) , _isvalid(false) { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS LPWSTR* p; p = ::CommandLineToArgvW(::GetCommandLineW(), &argc); _args.reserve(static_cast(argc)); @@ -2398,16 +2395,16 @@ GHC_INLINE u8arguments::u8arguments(int& argc, char**& argv) argv = _argp.data(); ::LocalFree(p); _isvalid = true; -#else +# else std::setlocale(LC_ALL, ""); -#if defined(__ANDROID__) && __ANDROID_API__ < 26 +# if defined(__ANDROID__) && __ANDROID_API__ < 26 _isvalid = true; -#else +# else if (detail::equals_simple_insensitive(::nl_langinfo(CODESET), "UTF-8")) { _isvalid = true; } -#endif -#endif +# endif +# endif } //----------------------------------------------------------------------------- @@ -2417,17 +2414,17 @@ GHC_INLINE path::path() noexcept {} GHC_INLINE path::path(const path& p) : _path(p._path) -#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) +# if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) , _prefixLength(p._prefixLength) -#endif +# endif { } GHC_INLINE path::path(path&& p) noexcept : _path(std::move(p._path)) -#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) +# if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) , _prefixLength(p._prefixLength) -#endif +# endif { } @@ -2471,18 +2468,18 @@ GHC_INLINE path::~path() {} GHC_INLINE path& path::operator=(const path& p) { _path = p._path; -#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) +# if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) _prefixLength = p._prefixLength; -#endif +# endif return *this; } GHC_INLINE path& path::operator=(path&& p) noexcept { _path = std::move(p._path); -#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) +# if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) _prefixLength = p._prefixLength; -#endif +# endif return *this; } @@ -2632,30 +2629,30 @@ GHC_INLINE path& path::operator+=(const string_type& x) return concat(x); } -#ifdef GHC_WITH_STRING_VIEW +# ifdef GHC_WITH_STRING_VIEW GHC_INLINE path& path::operator+=(basic_string_view x) { return concat(x); } -#endif +# endif GHC_INLINE path& path::operator+=(const value_type* x) { -#ifdef GHC_WITH_STRING_VIEW +# ifdef GHC_WITH_STRING_VIEW basic_string_view part(x); -#else +# else string_type part(x); -#endif +# endif return concat(part); } GHC_INLINE path& path::operator+=(value_type x) { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS if (x == generic_separator) { x = preferred_separator; } -#endif +# endif if (_path.empty() || _path.back() != preferred_separator) { _path += x; } @@ -2706,9 +2703,9 @@ inline path& path::concat(InputIterator first, InputIterator last) GHC_INLINE void path::clear() noexcept { _path.clear(); -#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) +# if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) _prefixLength = 0; -#endif +# endif } GHC_INLINE path& path::make_preferred() @@ -2746,9 +2743,9 @@ GHC_INLINE path& path::replace_extension(const path& replacement) GHC_INLINE void path::swap(path& rhs) noexcept { _path.swap(rhs._path); -#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) +# if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) std::swap(_prefixLength, rhs._prefixLength); -#endif +# endif } //----------------------------------------------------------------------------- @@ -2784,41 +2781,41 @@ inline std::basic_string path::string(const Allocator GHC_INLINE std::string path::string() const { -#ifdef GHC_USE_WCHAR_T +# ifdef GHC_USE_WCHAR_T return detail::toUtf8(native()); -#else +# else return native(); -#endif +# endif } GHC_INLINE std::wstring path::wstring() const { -#ifdef GHC_USE_WCHAR_T +# ifdef GHC_USE_WCHAR_T return native(); -#else +# else return detail::fromUtf8(native()); -#endif +# endif } -#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) +# if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) GHC_INLINE std::u8string path::u8string() const { -#ifdef GHC_USE_WCHAR_T +# ifdef GHC_USE_WCHAR_T return std::u8string(reinterpret_cast(detail::toUtf8(native()).c_str())); -#else +# else return std::u8string(reinterpret_cast(c_str())); -#endif +# endif } -#else +# else GHC_INLINE std::string path::u8string() const { -#ifdef GHC_USE_WCHAR_T +# ifdef GHC_USE_WCHAR_T return detail::toUtf8(native()); -#else +# else return native(); -#endif +# endif } -#endif +# endif GHC_INLINE std::u16string path::u16string() const { @@ -2840,11 +2837,11 @@ template inline std::basic_string path::generic_string(const Allocator& a) const { #ifdef GHC_OS_WINDOWS -#ifdef GHC_USE_WCHAR_T +# ifdef GHC_USE_WCHAR_T auto result = detail::fromWChar, path::string_type>(_path, a); -#else +# else auto result = detail::fromUtf8>(_path, a); -#endif +# endif for (auto& c : result) { if (c == preferred_separator) { c = generic_separator; @@ -2860,72 +2857,72 @@ inline std::basic_string path::generic_string(const A GHC_INLINE std::string path::generic_string() const { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS return generic_string(); -#else +# else return _path; -#endif +# endif } GHC_INLINE std::wstring path::generic_wstring() const { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS return generic_string(); -#else +# else return detail::fromUtf8(_path); -#endif +# endif } // namespace filesystem -#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) +# if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) GHC_INLINE std::u8string path::generic_u8string() const { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS return generic_string(); -#else +# else return std::u8string(reinterpret_cast(_path.c_str())); -#endif +# endif } -#else +# else GHC_INLINE std::string path::generic_u8string() const { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS return generic_string(); -#else +# else return _path; -#endif +# endif } -#endif +# endif GHC_INLINE std::u16string path::generic_u16string() const { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS return generic_string(); -#else +# else return detail::fromUtf8(_path); -#endif +# endif } GHC_INLINE std::u32string path::generic_u32string() const { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS return generic_string(); -#else +# else return detail::fromUtf8(_path); -#endif +# endif } //----------------------------------------------------------------------------- // [fs.path.compare] compare GHC_INLINE int path::compare(const path& p) const noexcept { -#ifdef LWG_2936_BEHAVIOUR +# ifdef LWG_2936_BEHAVIOUR auto rnl1 = root_name_length(); auto rnl2 = p.root_name_length(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS auto rnc = detail::compare_simple_insensitive(_path.c_str(), rnl1, p._path.c_str(), rnl2); -#else +# else auto rnc = _path.compare(0, rnl1, p._path, 0, (std::min(rnl1, rnl2))); -#endif +# endif if (rnc) { return rnc; } @@ -2956,8 +2953,8 @@ GHC_INLINE int path::compare(const path& p) const noexcept return 1; } return *iter1 < *iter2 ? -1 : 1; -#else // LWG_2936_BEHAVIOUR -#ifdef GHC_OS_WINDOWS +# else // LWG_2936_BEHAVIOUR +# ifdef GHC_OS_WINDOWS auto rnl1 = root_name_length(); auto rnl2 = p.root_name_length(); auto rnc = detail::compare_simple_insensitive(_path.c_str(), rnl1, p._path.c_str(), rnl2); @@ -2965,10 +2962,10 @@ GHC_INLINE int path::compare(const path& p) const noexcept return rnc; } return _path.compare(rnl1, std::string::npos, p._path, rnl2, std::string::npos); -#else +# else return _path.compare(p._path); -#endif -#endif +# endif +# endif } GHC_INLINE int path::compare(const string_type& s) const @@ -2976,12 +2973,12 @@ GHC_INLINE int path::compare(const string_type& s) const return compare(path(s)); } -#ifdef GHC_WITH_STRING_VIEW +# ifdef GHC_WITH_STRING_VIEW GHC_INLINE int path::compare(basic_string_view s) const { return compare(path(s)); } -#endif +# endif GHC_INLINE int path::compare(const value_type* s) const { @@ -2990,27 +2987,27 @@ GHC_INLINE int path::compare(const value_type* s) const //----------------------------------------------------------------------------- // [fs.path.decompose] decomposition -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS GHC_INLINE void path::handle_prefixes() { -#if defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) +# if defined(GHC_WIN_AUTO_PREFIX_LONG_PATH) _prefixLength = 0; if (_path.length() >= 6 && _path[2] == '?' && std::toupper(static_cast(_path[4])) >= 'A' && std::toupper(static_cast(_path[4])) <= 'Z' && _path[5] == ':') { if (detail::startsWith(_path, impl_string_type(GHC_PLATFORM_LITERAL("\\\\?\\"))) || detail::startsWith(_path, impl_string_type(GHC_PLATFORM_LITERAL("\\??\\")))) { _prefixLength = 4; } } -#endif // GHC_WIN_AUTO_PREFIX_LONG_PATH +# endif // GHC_WIN_AUTO_PREFIX_LONG_PATH } -#endif +# endif GHC_INLINE path::string_type::size_type path::root_name_length() const noexcept { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS if (_path.length() >= _prefixLength + 2 && std::toupper(static_cast(_path[_prefixLength])) >= 'A' && std::toupper(static_cast(_path[_prefixLength])) <= 'Z' && _path[_prefixLength + 1] == ':') { return 2; } -#endif +# endif if (_path.length() > _prefixLength + 2 && _path[_prefixLength] == preferred_separator && _path[_prefixLength + 1] == preferred_separator && _path[_prefixLength + 2] != preferred_separator && std::isprint(_path[_prefixLength + 2])) { impl_string_type::size_type pos = _path.find(preferred_separator, _prefixLength + 3); if (pos == impl_string_type::npos) { @@ -3099,7 +3096,7 @@ GHC_INLINE path path::extension() const return path(); } -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS namespace detail { GHC_INLINE bool has_executable_extension(const path& p) { @@ -3119,7 +3116,7 @@ GHC_INLINE bool has_executable_extension(const path& p) return false; } } // namespace detail -#endif +# endif //----------------------------------------------------------------------------- // [fs.path.query] query @@ -3172,11 +3169,11 @@ GHC_INLINE bool path::has_extension() const GHC_INLINE bool path::is_absolute() const { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS return has_root_name() && has_root_directory(); -#else +# else return has_root_directory(); -#endif +# endif } GHC_INLINE bool path::is_relative() const @@ -3320,15 +3317,15 @@ GHC_INLINE path::impl_string_type::const_iterator path::iterator::decrement(cons // if this is now the root slash or the trailing slash, we are done, // else check for network name if (i != _root && (pos != _last || *i != preferred_separator)) { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS static const impl_string_type seps = GHC_PLATFORM_LITERAL("\\:"); i = std::find_first_of(std::reverse_iterator(i), std::reverse_iterator(_first), seps.begin(), seps.end()).base(); if (i > _first && *i == ':') { i++; } -#else +# else i = std::find(std::reverse_iterator(i), std::reverse_iterator(_first), preferred_separator).base(); -#endif +# endif // Now we have to check if this is a network name if (i - _first == 2 && *_first == preferred_separator && *(_first + 1) == preferred_separator) { i -= 2; @@ -3425,12 +3422,12 @@ GHC_INLINE size_t hash_value(const path& p) noexcept return std::hash()(p.generic_string()); } -#ifdef GHC_HAS_THREEWAY_COMP +# ifdef GHC_HAS_THREEWAY_COMP GHC_INLINE std::strong_ordering operator<=>(const path& lhs, const path& rhs) noexcept { return lhs.compare(rhs) <=> 0; } -#endif +# endif GHC_INLINE bool operator==(const path& lhs, const path& rhs) noexcept { @@ -3580,7 +3577,7 @@ GHC_INLINE const char* filesystem_error::what() const noexcept //----------------------------------------------------------------------------- // [fs.op.funcs] filesystem operations -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE path absolute(const path& p) { std::error_code ec; @@ -3590,12 +3587,12 @@ GHC_INLINE path absolute(const path& p) } return result; } -#endif +# endif GHC_INLINE path absolute(const path& p, std::error_code& ec) { ec.clear(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS if (p.empty()) { return absolute(current_path(ec), ec) / ""; } @@ -3613,7 +3610,7 @@ GHC_INLINE path absolute(const path& p, std::error_code& ec) } ec = detail::make_system_error(); return path(); -#else +# else path base = current_path(ec); if (!ec) { if (p.empty()) { @@ -3638,10 +3635,10 @@ GHC_INLINE path absolute(const path& p, std::error_code& ec) } ec = detail::make_system_error(); return path(); -#endif +# endif } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE path canonical(const path& p) { std::error_code ec; @@ -3651,7 +3648,7 @@ GHC_INLINE path canonical(const path& p) } return result; } -#endif +# endif GHC_INLINE path canonical(const path& p, std::error_code& ec) { @@ -3716,7 +3713,7 @@ GHC_INLINE path canonical(const path& p, std::error_code& ec) return result; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void copy(const path& from, const path& to) { copy(from, to, copy_options::none); @@ -3730,7 +3727,7 @@ GHC_INLINE void copy(const path& from, const path& to, copy_options options) throw filesystem_error(detail::systemErrorText(ec.value()), from, to, ec); } } -#endif +# endif GHC_INLINE void copy(const path& from, const path& to, std::error_code& ec) noexcept { @@ -3778,11 +3775,11 @@ GHC_INLINE void copy(const path& from, const path& to, copy_options options, std if ((options & copy_options::create_symlinks) != copy_options::none) { create_symlink(from.is_absolute() ? from : canonical(from, ec), to, ec); } -#ifndef GHC_OS_WEB +# ifndef GHC_OS_WEB else if ((options & copy_options::create_hard_links) != copy_options::none) { create_hard_link(from, to, ec); } -#endif +# endif else if (is_directory(fs_to)) { copy_file(from, to / from.filename(), options, ec); } @@ -3791,11 +3788,11 @@ GHC_INLINE void copy(const path& from, const path& to, copy_options options, std } } } -#ifdef LWG_2682_BEHAVIOUR +# ifdef LWG_2682_BEHAVIOUR else if (is_directory(fs_from) && (options & copy_options::create_symlinks) != copy_options::none) { ec = detail::make_error_code(detail::portable_error::is_a_directory); } -#endif +# endif else if (is_directory(fs_from) && (options == copy_options::none || (options & copy_options::recursive) != copy_options::none)) { if (!exists(fs_to)) { create_directory(to, from, ec); @@ -3815,7 +3812,7 @@ GHC_INLINE void copy(const path& from, const path& to, copy_options options, std return; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool copy_file(const path& from, const path& to) { return copy_file(from, to, copy_options::none); @@ -3830,7 +3827,7 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options option) } return result; } -#endif +# endif GHC_INLINE bool copy_file(const path& from, const path& to, std::error_code& ec) noexcept { @@ -3870,13 +3867,13 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options } overwrite = true; } -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS if (!::CopyFileW(GHC_NATIVEWP(from), GHC_NATIVEWP(to), !overwrite)) { ec = detail::make_system_error(); return false; } return true; -#else +# else std::vector buffer(16384, '\0'); int in = -1, out = -1; if ((in = ::open(from.c_str(), O_RDONLY)) < 0) { @@ -3911,10 +3908,10 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options ::close(in); ::close(out); return true; -#endif +# endif } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void copy_symlink(const path& existing_symlink, const path& new_symlink) { std::error_code ec; @@ -3923,7 +3920,7 @@ GHC_INLINE void copy_symlink(const path& existing_symlink, const path& new_symli throw filesystem_error(detail::systemErrorText(ec.value()), existing_symlink, new_symlink, ec); } } -#endif +# endif GHC_INLINE void copy_symlink(const path& existing_symlink, const path& new_symlink, std::error_code& ec) noexcept { @@ -3939,7 +3936,7 @@ GHC_INLINE void copy_symlink(const path& existing_symlink, const path& new_symli } } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool create_directories(const path& p) { std::error_code ec; @@ -3949,7 +3946,7 @@ GHC_INLINE bool create_directories(const path& p) } return result; } -#endif +# endif GHC_INLINE bool create_directories(const path& p, std::error_code& ec) noexcept { @@ -3980,17 +3977,17 @@ GHC_INLINE bool create_directories(const path& p, std::error_code& ec) noexcept } didCreate = true; } -#ifndef LWG_2935_BEHAVIOUR +# ifndef LWG_2935_BEHAVIOUR else if (!is_directory(fs)) { ec = detail::make_error_code(detail::portable_error::exists); return false; } -#endif +# endif } return didCreate; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool create_directory(const path& p) { std::error_code ec; @@ -4000,14 +3997,14 @@ GHC_INLINE bool create_directory(const path& p) } return result; } -#endif +# endif GHC_INLINE bool create_directory(const path& p, std::error_code& ec) noexcept { return create_directory(p, path(), ec); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool create_directory(const path& p, const path& attributes) { std::error_code ec; @@ -4017,23 +4014,23 @@ GHC_INLINE bool create_directory(const path& p, const path& attributes) } return result; } -#endif +# endif GHC_INLINE bool create_directory(const path& p, const path& attributes, std::error_code& ec) noexcept { std::error_code tec; ec.clear(); auto fs = status(p, tec); -#ifdef LWG_2935_BEHAVIOUR +# ifdef LWG_2935_BEHAVIOUR if (status_known(fs) && exists(fs)) { return false; } -#else +# else if (status_known(fs) && exists(fs) && is_directory(fs)) { return false; } -#endif -#ifdef GHC_OS_WINDOWS +# endif +# ifdef GHC_OS_WINDOWS if (!attributes.empty()) { if (!::CreateDirectoryExW(GHC_NATIVEWP(attributes), GHC_NATIVEWP(p), NULL)) { ec = detail::make_system_error(); @@ -4044,7 +4041,7 @@ GHC_INLINE bool create_directory(const path& p, const path& attributes, std::err ec = detail::make_system_error(); return false; } -#else +# else ::mode_t attribs = static_cast(perms::all); if (!attributes.empty()) { struct ::stat fileStat; @@ -4058,11 +4055,11 @@ GHC_INLINE bool create_directory(const path& p, const path& attributes, std::err ec = detail::make_system_error(); return false; } -#endif +# endif return true; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void create_directory_symlink(const path& to, const path& new_symlink) { std::error_code ec; @@ -4071,15 +4068,15 @@ GHC_INLINE void create_directory_symlink(const path& to, const path& new_symlink throw filesystem_error(detail::systemErrorText(ec.value()), to, new_symlink, ec); } } -#endif +# endif GHC_INLINE void create_directory_symlink(const path& to, const path& new_symlink, std::error_code& ec) noexcept { detail::create_symlink(to, new_symlink, true, ec); } -#ifndef GHC_OS_WEB -#ifdef GHC_WITH_EXCEPTIONS +# ifndef GHC_OS_WEB +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void create_hard_link(const path& to, const path& new_hard_link) { std::error_code ec; @@ -4088,15 +4085,15 @@ GHC_INLINE void create_hard_link(const path& to, const path& new_hard_link) throw filesystem_error(detail::systemErrorText(ec.value()), to, new_hard_link, ec); } } -#endif +# endif GHC_INLINE void create_hard_link(const path& to, const path& new_hard_link, std::error_code& ec) noexcept { detail::create_hardlink(to, new_hard_link, ec); } -#endif +# endif -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void create_symlink(const path& to, const path& new_symlink) { std::error_code ec; @@ -4105,14 +4102,14 @@ GHC_INLINE void create_symlink(const path& to, const path& new_symlink) throw filesystem_error(detail::systemErrorText(ec.value()), to, new_symlink, ec); } } -#endif +# endif GHC_INLINE void create_symlink(const path& to, const path& new_symlink, std::error_code& ec) noexcept { detail::create_symlink(to, new_symlink, false, ec); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE path current_path() { std::error_code ec; @@ -4122,12 +4119,12 @@ GHC_INLINE path current_path() } return result; } -#endif +# endif GHC_INLINE path current_path(std::error_code& ec) { ec.clear(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS DWORD pathlen = ::GetCurrentDirectoryW(0, 0); std::unique_ptr buffer(new wchar_t[size_t(pathlen) + 1]); if (::GetCurrentDirectoryW(pathlen, buffer.get()) == 0) { @@ -4135,7 +4132,7 @@ GHC_INLINE path current_path(std::error_code& ec) return path(); } return path(std::wstring(buffer.get()), path::native_format); -#else +# else size_t pathlen = static_cast(std::max(int(::pathconf(".", _PC_PATH_MAX)), int(PATH_MAX))); std::unique_ptr buffer(new char[pathlen + 1]); if (::getcwd(buffer.get(), pathlen) == nullptr) { @@ -4143,10 +4140,10 @@ GHC_INLINE path current_path(std::error_code& ec) return path(); } return path(buffer.get()); -#endif +# endif } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void current_path(const path& p) { std::error_code ec; @@ -4155,20 +4152,20 @@ GHC_INLINE void current_path(const path& p) throw filesystem_error(detail::systemErrorText(ec.value()), p, ec); } } -#endif +# endif GHC_INLINE void current_path(const path& p, std::error_code& ec) noexcept { ec.clear(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS if (!::SetCurrentDirectoryW(GHC_NATIVEWP(p))) { ec = detail::make_system_error(); } -#else +# else if (::chdir(p.string().c_str()) == -1) { ec = detail::make_system_error(); } -#endif +# endif } GHC_INLINE bool exists(file_status s) noexcept @@ -4176,12 +4173,12 @@ GHC_INLINE bool exists(file_status s) noexcept return status_known(s) && s.type() != file_type::not_found; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool exists(const path& p) { return exists(status(p)); } -#endif +# endif GHC_INLINE bool exists(const path& p, std::error_code& ec) noexcept { @@ -4192,7 +4189,7 @@ GHC_INLINE bool exists(const path& p, std::error_code& ec) noexcept return exists(s); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool equivalent(const path& p1, const path& p2) { std::error_code ec; @@ -4202,23 +4199,23 @@ GHC_INLINE bool equivalent(const path& p1, const path& p2) } return result; } -#endif +# endif GHC_INLINE bool equivalent(const path& p1, const path& p2, std::error_code& ec) noexcept { ec.clear(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS 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)); auto e1 = ::GetLastError(); 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)); if (!file1 || !file2) { -#ifdef LWG_2937_BEHAVIOUR +# ifdef LWG_2937_BEHAVIOUR ec = detail::make_system_error(e1 ? e1 : ::GetLastError()); -#else +# else if (file1 == file2) { ec = detail::make_system_error(e1 ? e1 : ::GetLastError()); } -#endif +# endif return false; } BY_HANDLE_FILE_INFORMATION inf1, inf2; @@ -4232,26 +4229,26 @@ GHC_INLINE bool equivalent(const path& p1, const path& p2, std::error_code& ec) } return inf1.ftLastWriteTime.dwLowDateTime == inf2.ftLastWriteTime.dwLowDateTime && inf1.ftLastWriteTime.dwHighDateTime == inf2.ftLastWriteTime.dwHighDateTime && inf1.nFileIndexHigh == inf2.nFileIndexHigh && inf1.nFileIndexLow == inf2.nFileIndexLow && inf1.nFileSizeHigh == inf2.nFileSizeHigh && inf1.nFileSizeLow == inf2.nFileSizeLow && inf1.dwVolumeSerialNumber == inf2.dwVolumeSerialNumber; -#else +# else struct ::stat s1, s2; auto rc1 = ::stat(p1.c_str(), &s1); auto e1 = errno; auto rc2 = ::stat(p2.c_str(), &s2); if (rc1 || rc2) { -#ifdef LWG_2937_BEHAVIOUR +# ifdef LWG_2937_BEHAVIOUR ec = detail::make_system_error(e1 ? e1 : errno); -#else +# else if (rc1 && rc2) { ec = detail::make_system_error(e1 ? e1 : errno); } -#endif +# endif return false; } 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; -#endif +# endif } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE uintmax_t file_size(const path& p) { std::error_code ec; @@ -4261,30 +4258,30 @@ GHC_INLINE uintmax_t file_size(const path& p) } return result; } -#endif +# endif GHC_INLINE uintmax_t file_size(const path& p, std::error_code& ec) noexcept { ec.clear(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS WIN32_FILE_ATTRIBUTE_DATA attr; if (!GetFileAttributesExW(GHC_NATIVEWP(p), GetFileExInfoStandard, &attr)) { ec = detail::make_system_error(); return static_cast(-1); } return static_cast(attr.nFileSizeHigh) << (sizeof(attr.nFileSizeHigh) * 8) | attr.nFileSizeLow; -#else +# else struct ::stat fileStat; if (::stat(p.c_str(), &fileStat) == -1) { ec = detail::make_system_error(); return static_cast(-1); } return static_cast(fileStat.st_size); -#endif +# endif } -#ifndef GHC_OS_WEB -#ifdef GHC_WITH_EXCEPTIONS +# ifndef GHC_OS_WEB +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE uintmax_t hard_link_count(const path& p) { std::error_code ec; @@ -4294,12 +4291,12 @@ GHC_INLINE uintmax_t hard_link_count(const path& p) } return result; } -#endif +# endif GHC_INLINE uintmax_t hard_link_count(const path& p, std::error_code& ec) noexcept { ec.clear(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS uintmax_t result = static_cast(-1); 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)); BY_HANDLE_FILE_INFORMATION inf; @@ -4315,28 +4312,28 @@ GHC_INLINE uintmax_t hard_link_count(const path& p, std::error_code& ec) noexcep } } return result; -#else +# else uintmax_t result = 0; file_status fs = detail::status_ex(p, ec, nullptr, nullptr, &result, nullptr); if (fs.type() == file_type::not_found) { ec = detail::make_error_code(detail::portable_error::not_found); } return ec ? static_cast(-1) : result; -#endif +# endif } -#endif +# endif GHC_INLINE bool is_block_file(file_status s) noexcept { return s.type() == file_type::block; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool is_block_file(const path& p) { return is_block_file(status(p)); } -#endif +# endif GHC_INLINE bool is_block_file(const path& p, std::error_code& ec) noexcept { @@ -4348,12 +4345,12 @@ GHC_INLINE bool is_character_file(file_status s) noexcept return s.type() == file_type::character; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool is_character_file(const path& p) { return is_character_file(status(p)); } -#endif +# endif GHC_INLINE bool is_character_file(const path& p, std::error_code& ec) noexcept { @@ -4365,19 +4362,19 @@ GHC_INLINE bool is_directory(file_status s) noexcept return s.type() == file_type::directory; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool is_directory(const path& p) { return is_directory(status(p)); } -#endif +# endif GHC_INLINE bool is_directory(const path& p, std::error_code& ec) noexcept { return is_directory(status(p, ec)); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool is_empty(const path& p) { if (is_directory(p)) { @@ -4387,7 +4384,7 @@ GHC_INLINE bool is_empty(const path& p) return file_size(p) == 0; } } -#endif +# endif GHC_INLINE bool is_empty(const path& p, std::error_code& ec) noexcept { @@ -4416,12 +4413,12 @@ GHC_INLINE bool is_fifo(file_status s) noexcept return s.type() == file_type::fifo; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool is_fifo(const path& p) { return is_fifo(status(p)); } -#endif +# endif GHC_INLINE bool is_fifo(const path& p, std::error_code& ec) noexcept { @@ -4433,12 +4430,12 @@ GHC_INLINE bool is_other(file_status s) noexcept return exists(s) && !is_regular_file(s) && !is_directory(s) && !is_symlink(s); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool is_other(const path& p) { return is_other(status(p)); } -#endif +# endif GHC_INLINE bool is_other(const path& p, std::error_code& ec) noexcept { @@ -4450,12 +4447,12 @@ GHC_INLINE bool is_regular_file(file_status s) noexcept return s.type() == file_type::regular; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool is_regular_file(const path& p) { return is_regular_file(status(p)); } -#endif +# endif GHC_INLINE bool is_regular_file(const path& p, std::error_code& ec) noexcept { @@ -4467,12 +4464,12 @@ GHC_INLINE bool is_socket(file_status s) noexcept return s.type() == file_type::socket; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool is_socket(const path& p) { return is_socket(status(p)); } -#endif +# endif GHC_INLINE bool is_socket(const path& p, std::error_code& ec) noexcept { @@ -4484,19 +4481,19 @@ GHC_INLINE bool is_symlink(file_status s) noexcept return s.type() == file_type::symlink; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool is_symlink(const path& p) { return is_symlink(symlink_status(p)); } -#endif +# endif GHC_INLINE bool is_symlink(const path& p, std::error_code& ec) noexcept { return is_symlink(symlink_status(p, ec)); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE file_time_type last_write_time(const path& p) { std::error_code ec; @@ -4506,7 +4503,7 @@ GHC_INLINE file_time_type last_write_time(const path& p) } return result; } -#endif +# endif GHC_INLINE file_time_type last_write_time(const path& p, std::error_code& ec) noexcept { @@ -4516,7 +4513,7 @@ GHC_INLINE file_time_type last_write_time(const path& p, std::error_code& ec) no return ec ? (file_time_type::min)() : std::chrono::system_clock::from_time_t(result); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void last_write_time(const path& p, file_time_type new_time) { std::error_code ec; @@ -4525,13 +4522,13 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time) throw filesystem_error(detail::systemErrorText(ec.value()), p, ec); } } -#endif +# endif GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::error_code& ec) noexcept { ec.clear(); auto d = new_time.time_since_epoch(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS 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)); FILETIME ft; auto tt = std::chrono::duration_cast(d).count() * 10 + 116444736000000000; @@ -4540,9 +4537,9 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err if (!::SetFileTime(file.get(), 0, 0, &ft)) { ec = detail::make_system_error(); } -#elif defined(GHC_OS_MACOS) -#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED -#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300 +# elif defined(GHC_OS_MACOS) +# ifdef __MAC_OS_X_VERSION_MIN_REQUIRED +# if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300 struct ::stat fs; if (::stat(p.c_str(), &fs) == 0) { struct ::timeval tv[2]; @@ -4556,7 +4553,7 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err } ec = detail::make_system_error(); return; -#else +# else struct ::timespec times[2]; times[0].tv_sec = 0; times[0].tv_nsec = UTIME_OMIT; @@ -4566,29 +4563,29 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err ec = detail::make_system_error(); } return; -#endif -#endif -#else -#ifndef UTIME_OMIT -#define UTIME_OMIT ((1l << 30) - 2l) -#endif +# endif +# endif +# else +# ifndef UTIME_OMIT +# define UTIME_OMIT ((1l << 30) - 2l) +# endif struct ::timespec times[2]; times[0].tv_sec = 0; times[0].tv_nsec = UTIME_OMIT; times[1].tv_sec = static_cast(std::chrono::duration_cast(d).count()); times[1].tv_nsec = static_cast(std::chrono::duration_cast(d).count() % 1000000000); -#if defined(__ANDROID_API__) && __ANDROID_API__ < 12 +# if defined(__ANDROID_API__) && __ANDROID_API__ < 12 if (syscall(__NR_utimensat, AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) { -#else +# else if (::utimensat(AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) { -#endif +# endif ec = detail::make_system_error(); } return; -#endif +# endif } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void permissions(const path& p, perms prms, perm_options opts) { std::error_code ec; @@ -4597,7 +4594,7 @@ GHC_INLINE void permissions(const path& p, perms prms, perm_options opts) throw filesystem_error(detail::systemErrorText(ec.value()), p, ec); } } -#endif +# endif GHC_INLINE void permissions(const path& p, perms prms, std::error_code& ec) noexcept { @@ -4619,8 +4616,8 @@ GHC_INLINE void permissions(const path& p, perms prms, perm_options opts, std::e prms = fs.permissions() & ~prms; } } -#ifdef GHC_OS_WINDOWS -#ifdef __GNUC__ +# ifdef GHC_OS_WINDOWS +# ifdef __GNUC__ auto oldAttr = GetFileAttributesW(GHC_NATIVEWP(p)); if (oldAttr != INVALID_FILE_ATTRIBUTES) { DWORD newAttr = ((prms & perms::owner_write) == perms::owner_write) ? oldAttr & ~(static_cast(FILE_ATTRIBUTE_READONLY)) : oldAttr | FILE_ATTRIBUTE_READONLY; @@ -4629,7 +4626,7 @@ GHC_INLINE void permissions(const path& p, perms prms, perm_options opts, std::e } } ec = detail::make_system_error(); -#else +# else int mode = 0; if ((prms & perms::owner_read) == perms::owner_read) { mode |= _S_IREAD; @@ -4640,17 +4637,17 @@ GHC_INLINE void permissions(const path& p, perms prms, perm_options opts, std::e if (::_wchmod(p.wstring().c_str(), mode) != 0) { ec = detail::make_system_error(); } -#endif -#else +# endif +# else if ((opts & perm_options::nofollow) != perm_options::nofollow) { if (::chmod(p.c_str(), static_cast(prms)) != 0) { ec = detail::make_system_error(); } } -#endif +# endif } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE path proximate(const path& p, std::error_code& ec) { auto cp = current_path(ec); @@ -4659,21 +4656,21 @@ GHC_INLINE path proximate(const path& p, std::error_code& ec) } return path(); } -#endif +# endif -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE path proximate(const path& p, const path& base) { return weakly_canonical(p).lexically_proximate(weakly_canonical(base)); } -#endif +# endif GHC_INLINE path proximate(const path& p, const path& base, std::error_code& ec) { return weakly_canonical(p, ec).lexically_proximate(weakly_canonical(base, ec)); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE path read_symlink(const path& p) { std::error_code ec; @@ -4683,7 +4680,7 @@ GHC_INLINE path read_symlink(const path& p) } return result; } -#endif +# endif GHC_INLINE path read_symlink(const path& p, std::error_code& ec) { @@ -4701,19 +4698,19 @@ GHC_INLINE path relative(const path& p, std::error_code& ec) return relative(p, current_path(ec), ec); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE path relative(const path& p, const path& base) { return weakly_canonical(p).lexically_relative(weakly_canonical(base)); } -#endif +# endif GHC_INLINE path relative(const path& p, const path& base, std::error_code& ec) { return weakly_canonical(p, ec).lexically_relative(weakly_canonical(base, ec)); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool remove(const path& p) { std::error_code ec; @@ -4723,18 +4720,18 @@ GHC_INLINE bool remove(const path& p) } return result; } -#endif +# endif GHC_INLINE bool remove(const path& p, std::error_code& ec) noexcept { ec.clear(); -#ifdef GHC_OS_WINDOWS -#ifdef GHC_USE_WCHAR_T +# ifdef GHC_OS_WINDOWS +# ifdef GHC_USE_WCHAR_T auto cstr = p.c_str(); -#else +# else std::wstring np = detail::fromUtf8(p.u8string()); auto cstr = np.c_str(); -#endif +# endif DWORD attr = GetFileAttributesW(cstr); if (attr == INVALID_FILE_ATTRIBUTES) { auto error = ::GetLastError(); @@ -4762,7 +4759,7 @@ GHC_INLINE bool remove(const path& p, std::error_code& ec) noexcept } } } -#else +# else if (::remove(p.c_str()) == -1) { auto error = errno; if (error == ENOENT) { @@ -4770,11 +4767,11 @@ GHC_INLINE bool remove(const path& p, std::error_code& ec) noexcept } ec = detail::make_system_error(); } -#endif +# endif return ec ? false : true; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE uintmax_t remove_all(const path& p) { std::error_code ec; @@ -4784,7 +4781,7 @@ GHC_INLINE uintmax_t remove_all(const path& p) } return result; } -#endif +# endif GHC_INLINE uintmax_t remove_all(const path& p, std::error_code& ec) noexcept { @@ -4832,7 +4829,7 @@ GHC_INLINE uintmax_t remove_all(const path& p, std::error_code& ec) noexcept return count; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void rename(const path& from, const path& to) { std::error_code ec; @@ -4841,27 +4838,27 @@ GHC_INLINE void rename(const path& from, const path& to) throw filesystem_error(detail::systemErrorText(ec.value()), from, to, ec); } } -#endif +# endif GHC_INLINE void rename(const path& from, const path& to, std::error_code& ec) noexcept { ec.clear(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS if (from != to) { if (!MoveFileExW(GHC_NATIVEWP(from), GHC_NATIVEWP(to), (DWORD)MOVEFILE_REPLACE_EXISTING)) { ec = detail::make_system_error(); } } -#else +# else if (from != to) { if (::rename(from.c_str(), to.c_str()) != 0) { ec = detail::make_system_error(); } } -#endif +# endif } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void resize_file(const path& p, uintmax_t size) { std::error_code ec; @@ -4870,20 +4867,20 @@ GHC_INLINE void resize_file(const path& p, uintmax_t size) throw filesystem_error(detail::systemErrorText(ec.value()), p, ec); } } -#endif +# endif GHC_INLINE void resize_file(const path& p, uintmax_t size, std::error_code& ec) noexcept { ec.clear(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS LARGE_INTEGER lisize; lisize.QuadPart = static_cast(size); if (lisize.QuadPart < 0) { -#ifdef ERROR_FILE_TOO_LARGE +# ifdef ERROR_FILE_TOO_LARGE ec = detail::make_system_error(ERROR_FILE_TOO_LARGE); -#else +# else ec = detail::make_system_error(223); -#endif +# endif return; } detail::unique_handle file(CreateFileW(GHC_NATIVEWP(p), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL)); @@ -4893,14 +4890,14 @@ GHC_INLINE void resize_file(const path& p, uintmax_t size, std::error_code& ec) else if (SetFilePointerEx(file.get(), lisize, NULL, FILE_BEGIN) == 0 || SetEndOfFile(file.get()) == 0) { ec = detail::make_system_error(); } -#else +# else if (::truncate(p.c_str(), static_cast(size)) != 0) { ec = detail::make_system_error(); } -#endif +# endif } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE space_info space(const path& p) { std::error_code ec; @@ -4910,12 +4907,12 @@ GHC_INLINE space_info space(const path& p) } return result; } -#endif +# endif GHC_INLINE space_info space(const path& p, std::error_code& ec) noexcept { ec.clear(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS ULARGE_INTEGER freeBytesAvailableToCaller = {{ 0, 0 }}; ULARGE_INTEGER totalNumberOfBytes = {{ 0, 0 }}; ULARGE_INTEGER totalNumberOfFreeBytes = {{ 0, 0 }}; @@ -4924,17 +4921,17 @@ GHC_INLINE space_info space(const path& p, std::error_code& ec) noexcept return {static_cast(-1), static_cast(-1), static_cast(-1)}; } return {static_cast(totalNumberOfBytes.QuadPart), static_cast(totalNumberOfFreeBytes.QuadPart), static_cast(freeBytesAvailableToCaller.QuadPart)}; -#else +# else struct ::statvfs sfs; if (::statvfs(p.c_str(), &sfs) != 0) { ec = detail::make_system_error(); return {static_cast(-1), static_cast(-1), static_cast(-1)}; } return {static_cast(sfs.f_blocks) * static_cast(sfs.f_frsize), static_cast(sfs.f_bfree) * static_cast(sfs.f_frsize), static_cast(sfs.f_bavail) * static_cast(sfs.f_frsize)}; -#endif +# endif } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE file_status status(const path& p) { std::error_code ec; @@ -4944,7 +4941,7 @@ GHC_INLINE file_status status(const path& p) } return result; } -#endif +# endif GHC_INLINE file_status status(const path& p, std::error_code& ec) noexcept { @@ -4956,7 +4953,7 @@ GHC_INLINE bool status_known(file_status s) noexcept return s.type() != file_type::none; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE file_status symlink_status(const path& p) { std::error_code ec; @@ -4966,14 +4963,14 @@ GHC_INLINE file_status symlink_status(const path& p) } return result; } -#endif +# endif GHC_INLINE file_status symlink_status(const path& p, std::error_code& ec) noexcept { return detail::symlink_status_ex(p, ec); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE path temp_directory_path() { std::error_code ec; @@ -4983,12 +4980,12 @@ GHC_INLINE path temp_directory_path() } return result; } -#endif +# endif GHC_INLINE path temp_directory_path(std::error_code& ec) noexcept { ec.clear(); -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS wchar_t buffer[512]; auto rc = GetTempPathW(511, buffer); if (!rc || rc > 511) { @@ -4996,7 +4993,7 @@ GHC_INLINE path temp_directory_path(std::error_code& ec) noexcept return path(); } return path(std::wstring(buffer)); -#else +# else static const char* temp_vars[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR", nullptr}; const char* temp_path = nullptr; for (auto temp_name = temp_vars; *temp_name != nullptr; ++temp_name) { @@ -5006,10 +5003,10 @@ GHC_INLINE path temp_directory_path(std::error_code& ec) noexcept } } return path("/tmp"); -#endif +# endif } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE path weakly_canonical(const path& p) { std::error_code ec; @@ -5019,7 +5016,7 @@ GHC_INLINE path weakly_canonical(const path& p) } return result; } -#endif +# endif GHC_INLINE path weakly_canonical(const path& p, std::error_code& ec) noexcept { @@ -5131,25 +5128,25 @@ GHC_INLINE perms file_status::permissions() const noexcept // directory_entry::directory_entry() noexcept = default; // directory_entry::directory_entry(const directory_entry&) = default; // directory_entry::directory_entry(directory_entry&&) noexcept = default; -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE directory_entry::directory_entry(const filesystem::path& p) : _path(p) , _file_size(static_cast(-1)) -#ifndef GHC_OS_WINDOWS +# ifndef GHC_OS_WINDOWS , _hard_link_count(static_cast(-1)) -#endif +# endif , _last_write_time(0) { refresh(); } -#endif +# endif GHC_INLINE directory_entry::directory_entry(const filesystem::path& p, std::error_code& ec) : _path(p) , _file_size(static_cast(-1)) -#ifndef GHC_OS_WINDOWS +# ifndef GHC_OS_WINDOWS , _hard_link_count(static_cast(-1)) -#endif +# endif , _last_write_time(0) { refresh(ec); @@ -5162,13 +5159,13 @@ GHC_INLINE directory_entry::~directory_entry() {} // directory_entry& directory_entry::operator=(directory_entry&&) noexcept = default; // [fs.dir.entry.mods] directory_entry modifiers -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void directory_entry::assign(const filesystem::path& p) { _path = p; refresh(); } -#endif +# endif GHC_INLINE void directory_entry::assign(const filesystem::path& p, std::error_code& ec) { @@ -5176,13 +5173,13 @@ GHC_INLINE void directory_entry::assign(const filesystem::path& p, std::error_co refresh(ec); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void directory_entry::replace_filename(const filesystem::path& p) { _path.replace_filename(p); refresh(); } -#endif +# endif GHC_INLINE void directory_entry::replace_filename(const filesystem::path& p, std::error_code& ec) { @@ -5190,7 +5187,7 @@ GHC_INLINE void directory_entry::replace_filename(const filesystem::path& p, std refresh(ec); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void directory_entry::refresh() { std::error_code ec; @@ -5199,15 +5196,15 @@ GHC_INLINE void directory_entry::refresh() throw filesystem_error(detail::systemErrorText(ec.value()), _path, ec); } } -#endif +# endif GHC_INLINE void directory_entry::refresh(std::error_code& ec) noexcept { -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS _status = detail::status_ex(_path, ec, &_symlink_status, &_file_size, nullptr, &_last_write_time); -#else +# else _status = detail::status_ex(_path, ec, &_symlink_status, &_file_size, &_hard_link_count, &_last_write_time); -#endif +# endif } // [fs.dir.entry.obs] directory_entry observers @@ -5221,12 +5218,12 @@ GHC_INLINE directory_entry::operator const filesystem::path&() const noexcept return _path; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE file_type directory_entry::status_file_type() const { return _status.type() != file_type::none ? _status.type() : filesystem::status(path()).type(); } -#endif +# endif GHC_INLINE file_type directory_entry::status_file_type(std::error_code& ec) const noexcept { @@ -5237,72 +5234,72 @@ GHC_INLINE file_type directory_entry::status_file_type(std::error_code& ec) cons return filesystem::status(path(), ec).type(); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool directory_entry::exists() const { return status_file_type() != file_type::not_found; } -#endif +# endif GHC_INLINE bool directory_entry::exists(std::error_code& ec) const noexcept { return status_file_type(ec) != file_type::not_found; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool directory_entry::is_block_file() const { return status_file_type() == file_type::block; } -#endif +# endif GHC_INLINE bool directory_entry::is_block_file(std::error_code& ec) const noexcept { return status_file_type(ec) == file_type::block; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool directory_entry::is_character_file() const { return status_file_type() == file_type::character; } -#endif +# endif GHC_INLINE bool directory_entry::is_character_file(std::error_code& ec) const noexcept { return status_file_type(ec) == file_type::character; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool directory_entry::is_directory() const { return status_file_type() == file_type::directory; } -#endif +# endif GHC_INLINE bool directory_entry::is_directory(std::error_code& ec) const noexcept { return status_file_type(ec) == file_type::directory; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool directory_entry::is_fifo() const { return status_file_type() == file_type::fifo; } -#endif +# endif GHC_INLINE bool directory_entry::is_fifo(std::error_code& ec) const noexcept { return status_file_type(ec) == file_type::fifo; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool directory_entry::is_other() const { auto ft = status_file_type(); return ft != file_type::none && ft != file_type::not_found && ft != file_type::regular && ft != file_type::directory && !is_symlink(); } -#endif +# endif GHC_INLINE bool directory_entry::is_other(std::error_code& ec) const noexcept { @@ -5311,36 +5308,36 @@ GHC_INLINE bool directory_entry::is_other(std::error_code& ec) const noexcept return !ec && other; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool directory_entry::is_regular_file() const { return status_file_type() == file_type::regular; } -#endif +# endif GHC_INLINE bool directory_entry::is_regular_file(std::error_code& ec) const noexcept { return status_file_type(ec) == file_type::regular; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool directory_entry::is_socket() const { return status_file_type() == file_type::socket; } -#endif +# endif GHC_INLINE bool directory_entry::is_socket(std::error_code& ec) const noexcept { return status_file_type(ec) == file_type::socket; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE bool directory_entry::is_symlink() const { return _symlink_status.type() != file_type::none ? _symlink_status.type() == file_type::symlink : filesystem::is_symlink(symlink_status()); } -#endif +# endif GHC_INLINE bool directory_entry::is_symlink(std::error_code& ec) const noexcept { @@ -5351,7 +5348,7 @@ GHC_INLINE bool directory_entry::is_symlink(std::error_code& ec) const noexcept return filesystem::is_symlink(symlink_status(ec)); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE uintmax_t directory_entry::file_size() const { if (_file_size != static_cast(-1)) { @@ -5359,7 +5356,7 @@ GHC_INLINE uintmax_t directory_entry::file_size() const } return filesystem::file_size(path()); } -#endif +# endif GHC_INLINE uintmax_t directory_entry::file_size(std::error_code& ec) const noexcept { @@ -5370,32 +5367,32 @@ GHC_INLINE uintmax_t directory_entry::file_size(std::error_code& ec) const noexc return filesystem::file_size(path(), ec); } -#ifndef GHC_OS_WEB -#ifdef GHC_WITH_EXCEPTIONS +# ifndef GHC_OS_WEB +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE uintmax_t directory_entry::hard_link_count() const { -#ifndef GHC_OS_WINDOWS +# ifndef GHC_OS_WINDOWS if (_hard_link_count != static_cast(-1)) { return _hard_link_count; } -#endif +# endif return filesystem::hard_link_count(path()); } -#endif +# endif GHC_INLINE uintmax_t directory_entry::hard_link_count(std::error_code& ec) const noexcept { -#ifndef GHC_OS_WINDOWS +# ifndef GHC_OS_WINDOWS if (_hard_link_count != static_cast(-1)) { ec.clear(); return _hard_link_count; } -#endif +# endif return filesystem::hard_link_count(path(), ec); } -#endif +# endif -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE file_time_type directory_entry::last_write_time() const { if (_last_write_time != 0) { @@ -5403,7 +5400,7 @@ GHC_INLINE file_time_type directory_entry::last_write_time() const } return filesystem::last_write_time(path()); } -#endif +# endif GHC_INLINE file_time_type directory_entry::last_write_time(std::error_code& ec) const noexcept { @@ -5414,7 +5411,7 @@ GHC_INLINE file_time_type directory_entry::last_write_time(std::error_code& ec) return filesystem::last_write_time(path(), ec); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE file_status directory_entry::status() const { if (_status.type() != file_type::none && _status.permissions() != perms::unknown) { @@ -5422,7 +5419,7 @@ GHC_INLINE file_status directory_entry::status() const } return filesystem::status(path()); } -#endif +# endif GHC_INLINE file_status directory_entry::status(std::error_code& ec) const noexcept { @@ -5433,7 +5430,7 @@ GHC_INLINE file_status directory_entry::status(std::error_code& ec) const noexce return filesystem::status(path(), ec); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE file_status directory_entry::symlink_status() const { if (_symlink_status.type() != file_type::none && _symlink_status.permissions() != perms::unknown) { @@ -5441,7 +5438,7 @@ GHC_INLINE file_status directory_entry::symlink_status() const } return filesystem::symlink_status(path()); } -#endif +# endif GHC_INLINE file_status directory_entry::symlink_status(std::error_code& ec) const noexcept { @@ -5452,12 +5449,12 @@ GHC_INLINE file_status directory_entry::symlink_status(std::error_code& ec) cons return filesystem::symlink_status(path(), ec); } -#ifdef GHC_HAS_THREEWAY_COMP +# ifdef GHC_HAS_THREEWAY_COMP GHC_INLINE std::strong_ordering directory_entry::operator<=>(const directory_entry& rhs) const noexcept { return _path <=> rhs._path; } -#endif +# endif GHC_INLINE bool directory_entry::operator<(const directory_entry& rhs) const noexcept { @@ -5492,7 +5489,7 @@ GHC_INLINE bool directory_entry::operator>=(const directory_entry& rhs) const no //----------------------------------------------------------------------------- // [fs.class.directory_iterator] class directory_iterator -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS class directory_iterator::impl { public: @@ -5535,10 +5532,10 @@ public: do { if (FindNextFileW(_dirHandle, &_findData)) { _dir_entry._path = _base; -#ifdef GHC_USE_WCHAR_T +# ifdef GHC_USE_WCHAR_T _dir_entry._path.append_name(_findData.cFileName); -#else -#ifdef GHC_RAISE_UNICODE_ERRORS +# else +# ifdef GHC_RAISE_UNICODE_ERRORS try { _dir_entry._path.append_name(detail::toUtf8(_findData.cFileName).c_str()); } @@ -5546,10 +5543,10 @@ public: ec = fe.code(); return; } -#else +# else _dir_entry._path.append_name(detail::toUtf8(_findData.cFileName).c_str()); -#endif -#endif +# endif +# endif copyToDirEntry(ec); } else { @@ -5594,7 +5591,7 @@ public: directory_entry _dir_entry; std::error_code _ec; }; -#else +# else // POSIX implementation class directory_iterator::impl { @@ -5658,10 +5655,10 @@ public: void copyToDirEntry() { -#ifdef GHC_NO_DIRENT_D_TYPE +# ifdef GHC_NO_DIRENT_D_TYPE _dir_entry._symlink_status = file_status(); _dir_entry._status = file_status(); -#else +# else _dir_entry._symlink_status.permissions(perms::unknown); switch (_entry->d_type) { case DT_BLK: @@ -5699,7 +5696,7 @@ public: _dir_entry._status.type(file_type::none); _dir_entry._status.permissions(perms::unknown); } -#endif +# endif _dir_entry._file_size = static_cast(-1); _dir_entry._hard_link_count = static_cast(-1); _dir_entry._last_write_time = 0; @@ -5711,7 +5708,7 @@ public: directory_entry _dir_entry; std::error_code _ec; }; -#endif +# endif // [fs.dir.itr.members] member functions GHC_INLINE directory_iterator::directory_iterator() noexcept @@ -5719,7 +5716,7 @@ GHC_INLINE directory_iterator::directory_iterator() noexcept { } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE directory_iterator::directory_iterator(const path& p) : _impl(new impl(p, directory_options::none)) { @@ -5736,7 +5733,7 @@ GHC_INLINE directory_iterator::directory_iterator(const path& p, directory_optio throw filesystem_error(detail::systemErrorText(_impl->_ec.value()), p, _impl->_ec); } } -#endif +# endif GHC_INLINE directory_iterator::directory_iterator(const path& p, std::error_code& ec) noexcept : _impl(new impl(p, directory_options::none)) @@ -5788,7 +5785,7 @@ GHC_INLINE const directory_entry* directory_iterator::operator->() const return &_impl->_dir_entry; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE directory_iterator& directory_iterator::operator++() { std::error_code ec; @@ -5798,7 +5795,7 @@ GHC_INLINE directory_iterator& directory_iterator::operator++() } return *this; } -#endif +# endif GHC_INLINE directory_iterator& directory_iterator::increment(std::error_code& ec) noexcept { @@ -5837,7 +5834,7 @@ GHC_INLINE recursive_directory_iterator::recursive_directory_iterator() noexcept _impl->_dir_iter_stack.push(directory_iterator()); } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE recursive_directory_iterator::recursive_directory_iterator(const path& p) : _impl(new recursive_directory_iterator_impl(directory_options::none, true)) { @@ -5849,7 +5846,7 @@ GHC_INLINE recursive_directory_iterator::recursive_directory_iterator(const path { _impl->_dir_iter_stack.push(directory_iterator(p, options)); } -#endif +# endif GHC_INLINE recursive_directory_iterator::recursive_directory_iterator(const path& p, directory_options options, std::error_code& ec) noexcept : _impl(new recursive_directory_iterator_impl(options, true)) @@ -5914,7 +5911,7 @@ GHC_INLINE recursive_directory_iterator& recursive_directory_iterator::operator= return *this; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE recursive_directory_iterator& recursive_directory_iterator::operator++() { std::error_code ec; @@ -5924,7 +5921,7 @@ GHC_INLINE recursive_directory_iterator& recursive_directory_iterator::operator+ } return *this; } -#endif +# endif GHC_INLINE recursive_directory_iterator& recursive_directory_iterator::increment(std::error_code& ec) noexcept { @@ -5954,7 +5951,7 @@ GHC_INLINE recursive_directory_iterator& recursive_directory_iterator::increment return *this; } -#ifdef GHC_WITH_EXCEPTIONS +# ifdef GHC_WITH_EXCEPTIONS GHC_INLINE void recursive_directory_iterator::pop() { std::error_code ec; @@ -5963,7 +5960,7 @@ GHC_INLINE void recursive_directory_iterator::pop() throw filesystem_error(detail::systemErrorText(ec.value()), _impl->_dir_iter_stack.empty() ? path() : _impl->_dir_iter_stack.top()->path(), ec); } } -#endif +# endif GHC_INLINE void recursive_directory_iterator::pop(std::error_code& ec) { diff --git a/src/filesystem.cpp b/src/filesystem.cpp new file mode 100644 index 0000000..ad7be84 --- /dev/null +++ b/src/filesystem.cpp @@ -0,0 +1,28 @@ +//--------------------------------------------------------------------------------------- +// +// ghc::filesystem - A C++17-like filesystem implementation for C++11/C++14 +// +//--------------------------------------------------------------------------------------- +// +// Copyright (c) 2018, Steffen Schümann +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +//--------------------------------------------------------------------------------------- +#include \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f9fdd18..751b2c2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -78,6 +78,18 @@ if(CMAKE_CXX_COMPILER_ID MATCHES MSVC) endif() add_test(fwd_impl_test fwd_impl_test) +if(GHC_FILESYSTEM_BUILD_STATIC) + add_executable(filesystem_test_static filesystem_test.cpp catch.hpp) + target_link_libraries(filesystem_test_static ghc_filesystem_static) + ParseAndAddCatchTests(filesystem_test_static) +endif() + +if(GHC_FILESYSTEM_BUILD_SHARED) + add_executable(filesystem_test_shared filesystem_test.cpp catch.hpp) + target_link_libraries(filesystem_test_shared ghc_filesystem_shared) + ParseAndAddCatchTests(filesystem_test_shared) +endif() + add_executable(exception exception.cpp) if(NOT MSVC) target_compile_options(exception PRIVATE -fno-exceptions) diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 7fdd0a5..6d6ffb0 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -35,32 +35,32 @@ #include #if (defined(WIN32) || defined(_WIN32)) && !defined(__GNUC__) -#define NOMINMAX 1 +# define NOMINMAX 1 #endif #ifdef USE_STD_FS -#include +# include namespace fs { using namespace std::filesystem; using ifstream = std::ifstream; using ofstream = std::ofstream; using fstream = std::fstream; } // namespace fs -#ifdef __GNUC__ -#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -#endif -#ifdef _MSC_VER -#define IS_WCHAR_PATH -#endif -#ifdef WIN32 -#define GHC_OS_WINDOWS -#endif +# ifdef __GNUC__ +# define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +# endif +# ifdef _MSC_VER +# define IS_WCHAR_PATH +# endif +# ifdef WIN32 +# define GHC_OS_WINDOWS +# endif #else -#ifdef GHC_FILESYSTEM_FWD_TEST -#include -#else -#include -#endif +# ifdef GHC_FILESYSTEM_FWD_TEST +# include +# else +# include +# endif namespace fs { using namespace ghc::filesystem; using ifstream = ghc::filesystem::ifstream; @@ -70,17 +70,17 @@ using fstream = ghc::filesystem::fstream; #endif #if defined(WIN32) || defined(_WIN32) -#include +# include #else -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include #endif #ifndef GHC_FILESYSTEM_FWD_TEST -#define CATCH_CONFIG_MAIN +# define CATCH_CONFIG_MAIN #endif #include "catch.hpp" @@ -131,9 +131,7 @@ struct StringMaker template <> struct StringMaker { - static std::string convert(fs::file_status const& value) { - return std::string("[") + std::to_string(static_cast(value.type())) + "," + std::to_string(static_cast(value.permissions())) + "]"; - } + static std::string convert(fs::file_status const& value) { return std::string("[") + std::to_string(static_cast(value.type())) + "," + std::to_string(static_cast(value.permissions())) + "]"; } }; #ifdef __cpp_lib_char8_t @@ -232,18 +230,18 @@ static bool is_symlink_creation_supported() bool result = true; HKEY key; REGSAM flags = KEY_READ; -#ifdef _WIN64 +# ifdef _WIN64 flags |= KEY_WOW64_64KEY; -#elif defined(KEY_WOW64_64KEY) +# elif defined(KEY_WOW64_64KEY) if (isWow64Proc()) { flags |= KEY_WOW64_64KEY; } else { flags |= KEY_WOW64_32KEY; } -#else +# else result = false; -#endif +# endif if (result) { auto err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppModelUnlock", 0, flags, &key); if (err == ERROR_SUCCESS) { @@ -296,8 +294,9 @@ public: } value_type* allocate(std::size_t n) { return static_cast(::operator new(n * sizeof(value_type))); } void deallocate(value_type* p, std::size_t) noexcept { ::operator delete(p); } - template - struct rebind { + template + struct rebind + { typedef TestAllocator other; }; }; @@ -337,29 +336,29 @@ TEST_CASE("fs::detail::fromUtf8", "[filesystem][fs.detail.utf8]") CHECK(fs::detail::toUtf8(std::wstring(L"foobar")).length() == 6); CHECK(fs::detail::toUtf8(std::wstring(L"foobar")) == "foobar"); CHECK(fs::detail::toUtf8(std::wstring(L"föobar")).length() == 7); - //CHECK(fs::detail::toUtf8(std::wstring(L"föobar")) == u8"föobar"); + // CHECK(fs::detail::toUtf8(std::wstring(L"föobar")) == u8"föobar"); -#ifdef GHC_RAISE_UNICODE_ERRORS +# ifdef GHC_RAISE_UNICODE_ERRORS CHECK_THROWS_AS(fs::detail::fromUtf8(std::string("\xed\xa0\x80")), fs::filesystem_error); CHECK_THROWS_AS(fs::detail::fromUtf8(std::string("\xc3")), fs::filesystem_error); -#else - CHECK(std::u16string(2,0xfffd) == fs::detail::fromUtf8(std::string("\xed\xa0\x80"))); - CHECK(std::u16string(1,0xfffd) == fs::detail::fromUtf8(std::string("\xc3"))); -#endif +# else + CHECK(std::u16string(2, 0xfffd) == fs::detail::fromUtf8(std::string("\xed\xa0\x80"))); + CHECK(std::u16string(1, 0xfffd) == fs::detail::fromUtf8(std::string("\xc3"))); +# endif } TEST_CASE("fs::detail::toUtf8", "[filesystem][fs.detail.utf8]") { std::string t; CHECK(std::string("\xc3\xa4/\xe2\x82\xac\xf0\x9d\x84\x9e") == fs::detail::toUtf8(std::u16string(u"\u00E4/\u20AC\U0001D11E"))); -#ifdef GHC_RAISE_UNICODE_ERRORS +# ifdef GHC_RAISE_UNICODE_ERRORS CHECK_THROWS_AS(fs::detail::toUtf8(std::u16string(1, 0xd800)), fs::filesystem_error); CHECK_THROWS_AS(fs::detail::appendUTF8(t, 0x200000), fs::filesystem_error); -#else +# else CHECK(std::string("\xEF\xBF\xBD") == fs::detail::toUtf8(std::u16string(1, 0xd800))); fs::detail::appendUTF8(t, 0x200000); CHECK(std::string("\xEF\xBF\xBD") == t); -#endif +# endif } #endif @@ -586,21 +585,21 @@ TEST_CASE("fs.path.modifiers - path modifiers", "[filesystem][path][fs.path.modi TEST_CASE("fs.path.native.obs - path native format observers", "[filesystem][path][fs.path.native.obs]") { #ifdef GHC_OS_WINDOWS -#if defined(IS_WCHAR_PATH) || defined(GHC_USE_WCHAR_T) +# if defined(IS_WCHAR_PATH) || defined(GHC_USE_WCHAR_T) CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").native() == fs::path::string_type(L"\u00E4\\\u20AC")); // CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").string() == std::string("ä\\€")); // MSVCs returns local DBCS encoding -#else +# else CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").native() == fs::path::string_type("\xc3\xa4\\\xe2\x82\xac")); CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").string() == std::string("\xc3\xa4\\\xe2\x82\xac")); CHECK(!::strcmp(fs::u8path("\xc3\xa4\\\xe2\x82\xac").c_str(), "\xc3\xa4\\\xe2\x82\xac")); CHECK((std::string)fs::u8path("\xc3\xa4\\\xe2\x82\xac") == std::string("\xc3\xa4\\\xe2\x82\xac")); -#endif +# endif CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").wstring() == std::wstring(L"\u00E4\\\u20AC")); -#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) +# if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").u8string() == std::u8string(u8"\u00E4\\\u20AC")); -#else +# else CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").u8string() == std::string("\xc3\xa4\\\xe2\x82\xac")); -#endif +# endif CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").u16string() == std::u16string(u"\u00E4\\\u20AC")); CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").u32string() == std::u32string(U"\U000000E4\\\U000020AC")); #else @@ -609,11 +608,11 @@ TEST_CASE("fs.path.native.obs - path native format observers", "[filesystem][pat CHECK((std::string)fs::u8path("\xc3\xa4/\xe2\x82\xac") == std::string("\xc3\xa4/\xe2\x82\xac")); CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").string() == std::string("\xc3\xa4/\xe2\x82\xac")); CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").wstring() == std::wstring(L"ä/€")); -#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) +# if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").u8string() == std::u8string(u8"\xc3\xa4/\xe2\x82\xac")); -#else +# else CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").u8string() == std::string("\xc3\xa4/\xe2\x82\xac")); -#endif +# endif CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").u16string() == std::u16string(u"\u00E4/\u20AC")); INFO("This check might fail on GCC8 (with \"Illegal byte sequence\") due to not detecting the valid unicode codepoint U+1D11E."); CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac\xf0\x9d\x84\x9e").u16string() == std::u16string(u"\u00E4/\u20AC\U0001D11E")); @@ -624,33 +623,33 @@ TEST_CASE("fs.path.native.obs - path native format observers", "[filesystem][pat TEST_CASE("fs.path.generic.obs - path generic format observers", "[filesystem][path][fs.path.generic.obs]") { #ifdef GHC_OS_WINDOWS -#ifndef IS_WCHAR_PATH +# ifndef IS_WCHAR_PATH CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_string() == std::string("\xc3\xa4/\xe2\x82\xac")); -#endif -#ifndef USE_STD_FS +# endif +# ifndef USE_STD_FS auto t = fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_string, TestAllocator>(); CHECK(t.c_str() == std::string("\xc3\xa4/\xe2\x82\xac")); -#endif +# endif CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_wstring() == std::wstring(L"\U000000E4/\U000020AC")); -#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) +# if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_u8string() == std::u8string(u8"\u00E4/\u20AC")); -#else +# else CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_u8string() == std::string("\xc3\xa4/\xe2\x82\xac")); -#endif +# endif CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_u16string() == std::u16string(u"\u00E4/\u20AC")); CHECK(fs::u8path("\xc3\xa4\\\xe2\x82\xac").generic_u32string() == std::u32string(U"\U000000E4/\U000020AC")); #else CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_string() == std::string("\xc3\xa4/\xe2\x82\xac")); -#ifndef USE_STD_FS +# ifndef USE_STD_FS auto t = fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_string, TestAllocator>(); CHECK(t.c_str() == std::string("\xc3\xa4/\xe2\x82\xac")); -#endif +# endif CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_wstring() == std::wstring(L"ä/€")); -#if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) +# if defined(__cpp_lib_char8_t) && !defined(GHC_FILESYSTEM_ENFORCE_CPP17_API) CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_u8string() == std::u8string(u8"\xc3\xa4/\xe2\x82\xac")); -#else +# else CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_u8string() == std::string("\xc3\xa4/\xe2\x82\xac")); -#endif +# endif CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_u16string() == std::u16string(u"\u00E4/\u20AC")); CHECK(fs::u8path("\xc3\xa4/\xe2\x82\xac").generic_u32string() == std::u32string(U"\U000000E4/\U000020AC")); #endif @@ -679,7 +678,7 @@ TEST_CASE("fs.path.compare - path compare", "[filesystem][path][fs.path.compare] #ifdef LWG_2936_BEHAVIOUR CHECK(fs::path("/a/b/").compare("/a/b/c") < 0); CHECK(fs::path("/a/b/").compare("a/c") > 0); -#endif // LWG_2936_BEHAVIOUR +#endif // LWG_2936_BEHAVIOUR } TEST_CASE("fs.path.decompose - path decomposition", "[filesystem][path][fs.path.decompose]") @@ -1403,7 +1402,7 @@ TEST_CASE("fs.class.directory_iterator - class directory_iterator", "[filesystem CHECK(++iter == fs::directory_iterator()); CHECK_THROWS_AS(fs::directory_iterator(t.path() / "non-existing"), fs::filesystem_error); int cnt = 0; - for(auto de : fs::directory_iterator(t.path())) { + for (auto de : fs::directory_iterator(t.path())) { ++cnt; } CHECK(cnt == 1); @@ -1521,12 +1520,12 @@ TEST_CASE("fs.class.rec.dir.itr - class recursive_directory_iterator", "[filesys generateFile("e"); auto iter = fs::recursive_directory_iterator("."); std::multimap result; - while(iter != fs::recursive_directory_iterator()) { + while (iter != fs::recursive_directory_iterator()) { result.insert(std::make_pair(iter->path().generic_string(), iter.depth())); ++iter; } std::stringstream os; - for(auto p : result) { + for (auto p : result) { os << "[" << p.first << "," << p.second << "],"; } CHECK(os.str() == "[./a,0],[./d1,0],[./d1/b,1],[./d1/c,1],[./d1/d2,1],[./d1/d2/d,2],[./e,0],"); @@ -1541,11 +1540,11 @@ TEST_CASE("fs.class.rec.dir.itr - class recursive_directory_iterator", "[filesys generateFile("d1/d2/d"); generateFile("e"); std::multiset result; - for(auto de : fs::recursive_directory_iterator(".")) { + for (auto de : fs::recursive_directory_iterator(".")) { result.insert(de.path().generic_string()); } std::stringstream os; - for(auto p : result) { + for (auto p : result) { os << p << ","; } CHECK(os.str() == "./a,./d1,./d1/b,./d1/c,./d1/d2,./d1/d2/d,./e,"); @@ -1559,15 +1558,15 @@ TEST_CASE("fs.class.rec.dir.itr - class recursive_directory_iterator", "[filesys generateFile("e"); auto iter = fs::recursive_directory_iterator("."); std::multimap result; - while(iter != fs::recursive_directory_iterator()) { + while (iter != fs::recursive_directory_iterator()) { result.insert(std::make_pair(iter->path().generic_string(), iter.depth())); - if(iter->path() == "./d1/d2") { + if (iter->path() == "./d1/d2") { iter.disable_recursion_pending(); } ++iter; } std::stringstream os; - for(auto p : result) { + for (auto p : result) { os << "[" << p.first << "," << p.second << "],"; } CHECK(os.str() == "[./a,0],[./d1,0],[./d1/d2,1],[./e,0],"); @@ -1581,9 +1580,9 @@ TEST_CASE("fs.class.rec.dir.itr - class recursive_directory_iterator", "[filesys generateFile("e"); auto iter = fs::recursive_directory_iterator("."); std::multimap result; - while(iter != fs::recursive_directory_iterator()) { + while (iter != fs::recursive_directory_iterator()) { result.insert(std::make_pair(iter->path().generic_string(), iter.depth())); - if(iter->path() == "./d1/d2") { + if (iter->path() == "./d1/d2") { iter.pop(); } else { @@ -1591,7 +1590,7 @@ TEST_CASE("fs.class.rec.dir.itr - class recursive_directory_iterator", "[filesys } } std::stringstream os; - for(auto p : result) { + for (auto p : result) { os << "[" << p.first << "," << p.second << "],"; } CHECK(os.str() == "[./a,0],[./d1,0],[./d1/d2,1],[./e,0],"); @@ -1605,24 +1604,24 @@ TEST_CASE("fs.class.rec.dir.itr - class recursive_directory_iterator", "[filesys fs::create_directory_symlink("../d1", "d2/ds1"); fs::create_directory_symlink("d3", "d2/ds2"); std::multiset result; - REQUIRE_NOTHROW([&](){ + REQUIRE_NOTHROW([&]() { for (const auto& de : fs::recursive_directory_iterator("d2", fs::directory_options::follow_directory_symlink)) { result.insert(de.path().generic_string()); } }()); std::stringstream os; - for(const auto& p : result) { + for (const auto& p : result) { os << p << ","; } CHECK(os.str() == "d2/b,d2/ds1,d2/ds1/a,d2/ds2,"); os.str(""); result.clear(); - REQUIRE_NOTHROW([&](){ - for (const auto& de : fs::recursive_directory_iterator("d2")) { - result.insert(de.path().generic_string()); - } + REQUIRE_NOTHROW([&]() { + for (const auto& de : fs::recursive_directory_iterator("d2")) { + result.insert(de.path().generic_string()); + } }()); - for(const auto& p : result) { + for (const auto& p : result) { os << p << ","; } CHECK(os.str() == "d2/b,d2/ds1,d2/ds2,"); @@ -2048,7 +2047,7 @@ TEST_CASE("fs.op.exists - exists", "[filesystem][operations][fs.op.exists]") CHECK(!ec); #if defined(GHC_OS_WINDOWS) && !defined(GHC_FILESYSTEM_FWD) if (::GetFileAttributesW(L"C:\\fs-test") != INVALID_FILE_ATTRIBUTES) { - CHECK(fs::exists("C:\\fs-test")); + CHECK(fs::exists("C:\\fs-test")); } #endif } @@ -2089,20 +2088,20 @@ TEST_CASE("fs.op.hard_link_count - hard_link_count", "[filesystem][operations][f #ifndef GHC_OS_WEB TemporaryDirectory t(TempOpt::change_path); std::error_code ec; -#ifdef GHC_OS_WINDOWS +# ifdef GHC_OS_WINDOWS // windows doesn't implement "."/".." as hardlinks, so it // starts with 1 and subdirectories don't change the count CHECK(fs::hard_link_count(t.path()) == 1); fs::create_directory("dir"); CHECK(fs::hard_link_count(t.path()) == 1); -#else +# else // unix/bsd/linux typically implements "."/".." as hardlinks // so an empty dir has 2 (from parent and the ".") and // adding a subdirectory adds one due to its ".." CHECK(fs::hard_link_count(t.path()) == getHardlinkCount(t.path())); fs::create_directory("dir"); CHECK(fs::hard_link_count(t.path()) == getHardlinkCount(t.path())); -#endif +# endif generateFile("foo"); CHECK(fs::hard_link_count(t.path() / "foo") == 1); ec = std::error_code(42, std::system_category()); @@ -2675,7 +2674,7 @@ TEST_CASE("fs.op.space - space", "[filesystem][operations][fs.op.space]") CHECK(si.free >= si.available); CHECK(!ec); } -#ifndef GHC_OS_WEB // statvfs under emscripten always returns a result, so this tests would fail +#ifndef GHC_OS_WEB // statvfs under emscripten always returns a result, so this tests would fail { std::error_code ec; fs::space_info si; @@ -2770,7 +2769,7 @@ TEST_CASE("fs.op.weakly_canonical - weakly_canonical", "[filesystem][operations] { INFO("This might fail on std::implementations that return fs::current_path() for fs::canonical(\"\")"); CHECK(fs::weakly_canonical("") == "."); - if(fs::weakly_canonical("") == ".") { + if (fs::weakly_canonical("") == ".") { CHECK(fs::weakly_canonical("foo/bar") == "foo/bar"); CHECK(fs::weakly_canonical("foo/./bar") == "foo/bar"); CHECK(fs::weakly_canonical("foo/../bar") == "bar"); @@ -2807,14 +2806,14 @@ TEST_CASE("std::string_view support", "[filesystem][fs.string_view]") { #if defined(GHC_HAS_STD_STRING_VIEW) || defined(GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW) -#if defined(GHC_HAS_STD_STRING_VIEW) +# if defined(GHC_HAS_STD_STRING_VIEW) using namespace std::literals; using string_view = std::string_view; using wstring_view = std::wstring_view; -#elif defined(GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW) +# elif defined(GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW) using string_view = std::experimental::string_view; using wstring_view = std::experimental::wstring_view; -#endif +# endif { std::string p("foo/bar"); @@ -2884,7 +2883,7 @@ TEST_CASE("Windows: path namespace handling", "[filesystem][path][fs.path.win.na CHECK(!ec); CHECK(p2 == p); } - + struct TestInfo { std::string _path; @@ -2895,13 +2894,13 @@ TEST_CASE("Windows: path namespace handling", "[filesystem][path][fs.path.win.na }; std::vector variants = { {R"(C:\Windows\notepad.exe)", R"(C:\Windows\notepad.exe)", "C:", "C:\\", "C:,/,Windows,notepad.exe"}, -#ifdef USE_STD_FS +# ifdef USE_STD_FS {R"(\\?\C:\Windows\notepad.exe)", R"(\\?\C:\Windows\notepad.exe)", "\\\\?", "\\\\?\\", "//?,/,C:,Windows,notepad.exe"}, {R"(\??\C:\Windows\notepad.exe)", R"(\??\C:\Windows\notepad.exe)", "\\??", "\\??\\", "/??,/,C:,Windows,notepad.exe"}, -#else +# else {R"(\\?\C:\Windows\notepad.exe)", R"(\\?\C:\Windows\notepad.exe)", "C:", "C:\\", "//?/,C:,/,Windows,notepad.exe"}, {R"(\??\C:\Windows\notepad.exe)", R"(\??\C:\Windows\notepad.exe)", "C:", "C:\\", "/?\?/,C:,/,Windows,notepad.exe"}, -#endif +# endif {R"(\\.\C:\Windows\notepad.exe)", R"(\\.\C:\Windows\notepad.exe)", "\\\\.", "\\\\.\\", "//.,/,C:,Windows,notepad.exe"}, {R"(\\?\HarddiskVolume1\Windows\notepad.exe)", R"(\\?\HarddiskVolume1\Windows\notepad.exe)", "\\\\?", "\\\\?\\", "//?,/,HarddiskVolume1,Windows,notepad.exe"}, {R"(\\?\Harddisk0Partition1\Windows\notepad.exe)", R"(\\?\Harddisk0Partition1\Windows\notepad.exe)", "\\\\?", "\\\\?\\", "//?,/,Harddisk0Partition1,Windows,notepad.exe"},