From c4683aa4a188d500dfdf026d7373e175500ebc22 Mon Sep 17 00:00:00 2001 From: Oz Date: Tue, 5 Sep 2023 09:00:51 +0200 Subject: [PATCH] Allow wchar_t constructors of iostreams on Windows when using libstdc++ --- include/ghc/filesystem.hpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index c7e9f54..86a6392 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -1142,6 +1142,10 @@ GHC_FS_API void create_hard_link(const path& to, const path& new_hard_link, std: GHC_FS_API uintmax_t hard_link_count(const path& p, std::error_code& ec) noexcept; #endif +#if defined(GHC_OS_WINDOWS) && (!defined(__GLIBCXX__) || (defined(_GLIBCXX_HAVE__WFOPEN) && defined(_GLIBCXX_USE_WCHAR_T))) +#define GHC_HAS_FSTREAM_OPEN_WITH_WCHAR +#endif + // Non-C++17 add-on std::fstream wrappers with path template > class basic_filebuf : public std::basic_filebuf @@ -1153,7 +1157,7 @@ class basic_filebuf : public std::basic_filebuf const basic_filebuf& operator=(const basic_filebuf&) = delete; basic_filebuf* open(const path& p, std::ios_base::openmode mode) { -#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__) +#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR return std::basic_filebuf::open(p.wstring().c_str(), mode) ? this : 0; #else return std::basic_filebuf::open(p.string().c_str(), mode) ? this : 0; @@ -1166,7 +1170,7 @@ class basic_ifstream : public std::basic_ifstream { public: basic_ifstream() {} -#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__) +#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR explicit basic_ifstream(const path& p, std::ios_base::openmode mode = std::ios_base::in) : std::basic_ifstream(p.wstring().c_str(), mode) { @@ -1189,7 +1193,7 @@ class basic_ofstream : public std::basic_ofstream { public: basic_ofstream() {} -#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__) +#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR explicit basic_ofstream(const path& p, std::ios_base::openmode mode = std::ios_base::out) : std::basic_ofstream(p.wstring().c_str(), mode) { @@ -1212,7 +1216,7 @@ class basic_fstream : public std::basic_fstream { public: basic_fstream() {} -#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__) +#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR explicit basic_fstream(const path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : std::basic_fstream(p.wstring().c_str(), mode) {