mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-06-04 11:13:58 +08:00
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:
commit
1ab54e53cc
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user