From 3ff83bdc275d5c86ac4e62bc4a5502c76d3fde29 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 25 Feb 2020 19:27:54 +0100 Subject: [PATCH] Use wchar_t overloads and custom filebuf also on cygwin boost::filesystem::path uses wchar_t* on cygwin and cygwins std::filesystem::path may use it too --- include/boost/nowide/config.hpp | 11 ++++++++++- include/boost/nowide/fstream.hpp | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/boost/nowide/config.hpp b/include/boost/nowide/config.hpp index d95e013..15f24b5 100644 --- a/include/boost/nowide/config.hpp +++ b/include/boost/nowide/config.hpp @@ -46,6 +46,15 @@ #include #endif // auto-linking disabled +/// @def BOOST_NOWIDE_USE_WCHAR_OVERLOADS +/// @brief Whether to use the wchar_t* overloads in fstream/filebuf +/// Enabled on Windows and Cygwin as the latter may use wchar_t in filesystem::path +#if defined(BOOST_WINDOWS) || defined(__CYGWIN__) +#define BOOST_NOWIDE_USE_WCHAR_OVERLOADS 1 +#else +#define BOOST_NOWIDE_USE_WCHAR_OVERLOADS 0 +#endif + /// @def BOOST_NOWIDE_USE_FILEBUF_REPLACEMENT /// @brief Define to 1 to use internal class from filebuf.hpp /// @@ -55,7 +64,7 @@ /// /// Affects boost::nowide::basic_filebuf, /// boost::nowide::basic_ofstream, boost::nowide::basic_ifstream, boost::nowide::basic_fstream -#if defined(BOOST_WINDOWS) +#if defined(BOOST_WINDOWS) || BOOST_NOWIDE_USE_WCHAR_OVERLOADS #ifdef BOOST_NOWIDE_USE_FILEBUF_REPLACEMENT #undef BOOST_NOWIDE_USE_FILEBUF_REPLACEMENT #endif diff --git a/include/boost/nowide/fstream.hpp b/include/boost/nowide/fstream.hpp index 299339f..754c528 100644 --- a/include/boost/nowide/fstream.hpp +++ b/include/boost/nowide/fstream.hpp @@ -77,7 +77,7 @@ namespace nowide { { open(file_name, mode); } -#ifdef BOOST_WINDOWS +#if BOOST_NOWIDE_USE_WCHAR_OVERLOADS explicit basic_ifstream(const wchar_t* file_name, std::ios_base::openmode mode = std::ios_base::in) { open(file_name, mode); @@ -118,7 +118,7 @@ namespace nowide { { open(file_name, mode); } -#ifdef BOOST_WINDOWS +#if BOOST_NOWIDE_USE_WCHAR_OVERLOADS explicit basic_ofstream(const wchar_t* file_name, std::ios_base::openmode mode = std::ios_base::out) { open(file_name, mode); @@ -162,7 +162,7 @@ namespace nowide { { open(file_name, mode); } -#ifdef BOOST_WINDOWS +#if BOOST_NOWIDE_USE_WCHAR_OVERLOADS explicit basic_fstream(const wchar_t* file_name, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) { @@ -252,7 +252,7 @@ namespace nowide { else clear(); } -#ifdef BOOST_WINDOWS +#if BOOST_NOWIDE_USE_WCHAR_OVERLOADS void open(const wchar_t* file_name, std::ios_base::openmode mode = T_StreamType::mode()) { if(!rdbuf()->open(file_name, mode | T_StreamType::mode_modifier()))