Allow wchar_t constructors of iostreams on Windows when using libstdc++

This commit is contained in:
Oz 2023-09-05 09:00:51 +02:00
parent 144954ff4e
commit c4683aa4a1
No known key found for this signature in database
GPG Key ID: 3B09C10F3DB6E52A

View File

@ -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 charT, class traits = std::char_traits<charT>>
class basic_filebuf : public std::basic_filebuf<charT, traits>
@ -1153,7 +1157,7 @@ public:
const basic_filebuf& operator=(const basic_filebuf&) = delete;
basic_filebuf<charT, traits>* 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<charT, traits>::open(p.wstring().c_str(), mode) ? this : 0;
#else
return std::basic_filebuf<charT, traits>::open(p.string().c_str(), mode) ? this : 0;
@ -1166,7 +1170,7 @@ class basic_ifstream : public std::basic_ifstream<charT, traits>
{
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<charT, traits>(p.wstring().c_str(), mode)
{
@ -1189,7 +1193,7 @@ class basic_ofstream : public std::basic_ofstream<charT, traits>
{
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<charT, traits>(p.wstring().c_str(), mode)
{
@ -1212,7 +1216,7 @@ class basic_fstream : public std::basic_fstream<charT, traits>
{
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<charT, traits>(p.wstring().c_str(), mode)
{