From 6ab9bd2780aa401ccac56a9d2c5566ae58232aed Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Fri, 28 Jul 2017 08:36:46 -0700 Subject: [PATCH] Use fopen_s on Windows fix #691 --- CHANGELOG.md | 1 + include/boost/beast/config.hpp | 3 +-- include/boost/beast/core/impl/file_stdio.ipp | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b30daa0f..05714cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Version 91: * Set BOOST_ASIO_NO_DEPRECATED * Use Asio array optimization in static_buffer_base * Rename wstest source file +* Use fopen_s on Windows WebSocket: diff --git a/include/boost/beast/config.hpp b/include/boost/beast/config.hpp index 89f2ec8c..07abf2f9 100644 --- a/include/boost/beast/config.hpp +++ b/include/boost/beast/config.hpp @@ -10,9 +10,8 @@ #ifndef BOOST_BEAST_CONFIG_HPP #define BOOST_BEAST_CONFIG_HPP -#include - // Available to every header +#include #include #include diff --git a/include/boost/beast/core/impl/file_stdio.ipp b/include/boost/beast/core/impl/file_stdio.ipp index 0a975a88..ca5cb0cb 100644 --- a/include/boost/beast/core/impl/file_stdio.ipp +++ b/include/boost/beast/core/impl/file_stdio.ipp @@ -96,12 +96,22 @@ open(char const* path, file_mode mode, error_code& ec) case file_mode::append_new: s = "abx"; break; case file_mode::append_existing: s = "ab"; break; } +#if BOOST_MSVC + auto const ev = fopen_s(&f_, path, s); + if(ev) + { + f_ = nullptr; + ec.assign(ev, generic_category()); + return; + } +#else f_ = std::fopen(path, s); if(! f_) { ec.assign(errno, generic_category()); return; } +#endif ec.assign(0, ec.category()); }