mirror of
https://github.com/boostorg/beast.git
synced 2025-08-03 14:54:32 +02:00
committed by
Vinnie Falco
parent
f0c92f472c
commit
dfb44236e9
@@ -3,6 +3,7 @@ Version 282:
|
|||||||
* Use superproject docca
|
* Use superproject docca
|
||||||
* Fix release build of docs
|
* Fix release build of docs
|
||||||
* file_win32 supports UTF-8 paths
|
* file_win32 supports UTF-8 paths
|
||||||
|
* file_stdio supports unicode paths
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#define BOOST_BEAST_CORE_IMPL_FILE_STDIO_IPP
|
#define BOOST_BEAST_CORE_IMPL_FILE_STDIO_IPP
|
||||||
|
|
||||||
#include <boost/beast/core/file_stdio.hpp>
|
#include <boost/beast/core/file_stdio.hpp>
|
||||||
|
#include <boost/beast/core/detail/win32_unicode_path.hpp>
|
||||||
#include <boost/config/workaround.hpp>
|
#include <boost/config/workaround.hpp>
|
||||||
#include <boost/core/exchange.hpp>
|
#include <boost/core/exchange.hpp>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@@ -79,31 +80,47 @@ open(char const* path, file_mode mode, error_code& ec)
|
|||||||
fclose(f_);
|
fclose(f_);
|
||||||
f_ = nullptr;
|
f_ = nullptr;
|
||||||
}
|
}
|
||||||
|
ec = {};
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
boost::winapi::WCHAR_ const* s;
|
||||||
|
detail::win32_unicode_path unicode_path(path, ec);
|
||||||
|
if (ec)
|
||||||
|
return;
|
||||||
|
#else
|
||||||
char const* s;
|
char const* s;
|
||||||
|
#endif
|
||||||
switch(mode)
|
switch(mode)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case file_mode::read:
|
case file_mode::read:
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
s = L"rb";
|
||||||
|
#else
|
||||||
s = "rb";
|
s = "rb";
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case file_mode::scan:
|
case file_mode::scan:
|
||||||
#ifdef BOOST_MSVC
|
#ifdef BOOST_MSVC
|
||||||
s = "rbS";
|
s = L"rbS";
|
||||||
#else
|
#else
|
||||||
s = "rb";
|
s = "rb";
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case file_mode::write:
|
case file_mode::write:
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
s = L"wb+";
|
||||||
|
#else
|
||||||
s = "wb+";
|
s = "wb+";
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case file_mode::write_new:
|
case file_mode::write_new:
|
||||||
{
|
{
|
||||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
|
#if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
|
||||||
FILE* f0;
|
FILE* f0;
|
||||||
auto const ev = ::fopen_s(&f0, path, "rb");
|
auto const ev = ::_wfopen_s(&f0, unicode_path.c_str(), L"rb");
|
||||||
if(! ev)
|
if(! ev)
|
||||||
{
|
{
|
||||||
std::fclose(f0);
|
std::fclose(f0);
|
||||||
@@ -116,20 +133,29 @@ open(char const* path, file_mode mode, error_code& ec)
|
|||||||
ec.assign(ev, generic_category());
|
ec.assign(ev, generic_category());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s = "wb";
|
s = L"wb";
|
||||||
|
#elif defined(BOOST_MSVC)
|
||||||
|
s = L"wbx";
|
||||||
#else
|
#else
|
||||||
|
|
||||||
s = "wbx";
|
s = "wbx";
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case file_mode::write_existing:
|
case file_mode::write_existing:
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
s = L"rb+";
|
||||||
|
#else
|
||||||
s = "rb+";
|
s = "rb+";
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case file_mode::append:
|
case file_mode::append:
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
s = L"ab";
|
||||||
|
#else
|
||||||
s = "ab";
|
s = "ab";
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case file_mode::append_existing:
|
case file_mode::append_existing:
|
||||||
@@ -137,7 +163,7 @@ open(char const* path, file_mode mode, error_code& ec)
|
|||||||
#ifdef BOOST_MSVC
|
#ifdef BOOST_MSVC
|
||||||
FILE* f0;
|
FILE* f0;
|
||||||
auto const ev =
|
auto const ev =
|
||||||
::fopen_s(&f0, path, "rb+");
|
::_wfopen_s(&f0, unicode_path.c_str(), L"rb+");
|
||||||
if(ev)
|
if(ev)
|
||||||
{
|
{
|
||||||
ec.assign(ev, generic_category());
|
ec.assign(ev, generic_category());
|
||||||
@@ -153,13 +179,17 @@ open(char const* path, file_mode mode, error_code& ec)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
std::fclose(f0);
|
std::fclose(f0);
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
s = L"ab";
|
||||||
|
#else
|
||||||
s = "ab";
|
s = "ab";
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BOOST_MSVC
|
#ifdef BOOST_MSVC
|
||||||
auto const ev = ::fopen_s(&f_, path, s);
|
auto const ev = ::_wfopen_s(&f_, unicode_path.c_str(), s);
|
||||||
if(ev)
|
if(ev)
|
||||||
{
|
{
|
||||||
f_ = nullptr;
|
f_ = nullptr;
|
||||||
@@ -174,7 +204,6 @@ open(char const* path, file_mode mode, error_code& ec)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
ec = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t
|
std::uint64_t
|
||||||
|
@@ -26,7 +26,11 @@ public:
|
|||||||
void
|
void
|
||||||
run()
|
run()
|
||||||
{
|
{
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
test_file<file_stdio, true>();
|
||||||
|
#else
|
||||||
test_file<file_stdio>();
|
test_file<file_stdio>();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ test_file()
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
boost::winapi::WCHAR_ unicode_suffix[] = { 0xd83e, 0xdd84, 0x0000 }; // UTF-16-LE unicorn
|
boost::winapi::WCHAR_ unicode_suffix[] = { 0xd83e, 0xdd84, 0x0000 }; // UTF-16-LE unicorn
|
||||||
#else
|
#else
|
||||||
char unicode_suffix[] = { 0xf0, 0x9f, 0xa6, 0x84, 0x00 }; // UTF-8 unicorn
|
char unicode_suffix[] = { '\xf0', '\x9f', '\xa6', '\x84', '\x00' }; // UTF-8 unicorn
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class temp_path
|
class temp_path
|
||||||
|
Reference in New Issue
Block a user