MSVC uses ::fopen_s

This commit is contained in:
Vinnie Falco
2019-03-29 17:47:01 -07:00
parent 3c82717fed
commit 965c21615a
2 changed files with 23 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
Version 242: Version 242:
* test::stream has deprecated lowest_layer for ssl * test::stream has deprecated lowest_layer for ssl
* MSVC use ::fopen_s
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@@ -88,7 +88,7 @@ open(char const* path, file_mode mode, error_code& ec)
break; break;
case file_mode::scan: case file_mode::scan:
#if BOOST_MSVC #ifdef BOOST_MSVC
s = "rbS"; s = "rbS";
#else #else
s = "rb"; s = "rb";
@@ -102,12 +102,12 @@ open(char const* path, file_mode mode, error_code& ec)
case file_mode::write_new: case file_mode::write_new:
{ {
#if BOOST_WORKAROUND(BOOST_MSVC, < 1910) #if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
auto const f0 = std::fopen(path, "rb"); x
if(f0) FILE* f0;
auto const ev = ::fopen_s(&f0, path, "rb");
if(ev)
{ {
std::fclose(f0); ec.assign(ev, generic_category());
ec = make_error_code(
errc::file_exists);
return; return;
} }
s = "wb"; s = "wb";
@@ -127,20 +127,31 @@ open(char const* path, file_mode mode, error_code& ec)
case file_mode::append_existing: case file_mode::append_existing:
{ {
auto const f0 = std::fopen(path, "rb+"); #ifdef BOOST_MSVC
if(! f0) FILE* f0;
auto const ev =
::fopen_s(&f0, path, "rb+");
if(ev)
{ {
ec = make_error_code( ec.assign(ev, generic_category());
errc::no_such_file_or_directory);
return; return;
} }
#else
auto const f0 =
std::fopen(path, "rb+");
if(! f0)
{
ec.assign(errno, generic_category());
return;
}
#endif
std::fclose(f0); std::fclose(f0);
s = "ab"; s = "ab";
break; break;
} }
} }
#if BOOST_MSVC #ifdef BOOST_MSVC
auto const ev = ::fopen_s(&f_, path, s); auto const ev = ::fopen_s(&f_, path, s);
if(ev) if(ev)
{ {