Merge pull request #172 from rikyoz/glibcxx_wchar_streams

Allow wchar_t constructors of fstreams on Windows when using libstdc++
This commit is contained in:
gulrak 2023-09-16 10:09:38 +02:00 committed by GitHub
commit 1ab54e53cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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; GHC_FS_API uintmax_t hard_link_count(const path& p, std::error_code& ec) noexcept;
#endif #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 // Non-C++17 add-on std::fstream wrappers with path
template <class charT, class traits = std::char_traits<charT>> template <class charT, class traits = std::char_traits<charT>>
class basic_filebuf : public std::basic_filebuf<charT, traits> class basic_filebuf : public std::basic_filebuf<charT, traits>
@ -1153,7 +1157,7 @@ public:
const basic_filebuf& operator=(const basic_filebuf&) = delete; const basic_filebuf& operator=(const basic_filebuf&) = delete;
basic_filebuf<charT, traits>* open(const path& p, std::ios_base::openmode mode) 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; return std::basic_filebuf<charT, traits>::open(p.wstring().c_str(), mode) ? this : 0;
#else #else
return std::basic_filebuf<charT, traits>::open(p.string().c_str(), mode) ? this : 0; 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: public:
basic_ifstream() {} 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) 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) : std::basic_ifstream<charT, traits>(p.wstring().c_str(), mode)
{ {
@ -1189,7 +1193,7 @@ class basic_ofstream : public std::basic_ofstream<charT, traits>
{ {
public: public:
basic_ofstream() {} 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) 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) : std::basic_ofstream<charT, traits>(p.wstring().c_str(), mode)
{ {
@ -1212,7 +1216,7 @@ class basic_fstream : public std::basic_fstream<charT, traits>
{ {
public: public:
basic_fstream() {} 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) 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) : std::basic_fstream<charT, traits>(p.wstring().c_str(), mode)
{ {