From 4f464ccaeb5f7b682da11837dad01e89c18882de Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 30 Mar 2019 14:13:36 -0700 Subject: [PATCH] Tidy up file_stdio for VS2015 --- CHANGELOG.md | 1 + include/boost/beast/core/impl/file_stdio.ipp | 10 +++++++++- test/beast/core/file_test.hpp | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e6f604e..0927c125 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 243: * Fix some typos +* Tidy up file_stdio for VS2015 -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/impl/file_stdio.ipp b/include/boost/beast/core/impl/file_stdio.ipp index 0b24074c..30adae62 100644 --- a/include/boost/beast/core/impl/file_stdio.ipp +++ b/include/boost/beast/core/impl/file_stdio.ipp @@ -104,13 +104,21 @@ open(char const* path, file_mode mode, error_code& ec) #if BOOST_WORKAROUND(BOOST_MSVC, < 1910) FILE* f0; auto const ev = ::fopen_s(&f0, path, "rb"); - if(ev) + if(! ev) + { + std::fclose(f0); + ec = make_error_code(errc::file_exists); + return; + } + else if(ev != + errc::no_such_file_or_directory) { ec.assign(ev, generic_category()); return; } s = "wb"; #else + s = "wbx"; #endif break; diff --git a/test/beast/core/file_test.hpp b/test/beast/core/file_test.hpp index 0b5dcdbd..5178b0f1 100644 --- a/test/beast/core/file_test.hpp +++ b/test/beast/core/file_test.hpp @@ -163,7 +163,7 @@ test_file() error_code ec; BEAST_EXPECT(! fs::exists(path)); f.open(path, file_mode::write_new, ec); - BEAST_EXPECT(! ec); + BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(fs::exists(path)); } {