From fb8f57a9e5d87761486e34c0274d172bfd217e62 Mon Sep 17 00:00:00 2001 From: vm2mv Date: Tue, 6 Jul 2021 11:27:41 +0300 Subject: [PATCH] Fix file open with append/append_existing flag on Windows --- CHANGELOG.md | 4 ++++ include/boost/beast/core/impl/file_win32.ipp | 23 +++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9df35202..12888672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +* Fix file open with append/append_existing flag on Windows. + +-------------------------------------------------------------------------------- + Version 323: * Fix clang-cl UTF8 path handling for `file_win32`. diff --git a/include/boost/beast/core/impl/file_win32.ipp b/include/boost/beast/core/impl/file_win32.ipp index f7b76619..3d0124e6 100644 --- a/include/boost/beast/core/impl/file_win32.ipp +++ b/include/boost/beast/core/impl/file_win32.ipp @@ -198,11 +198,28 @@ open(char const* path, file_mode mode, error_code& ec) creation_disposition, flags_and_attributes, NULL); - if(h_ == boost::winapi::INVALID_HANDLE_VALUE_) + if (h_ == boost::winapi::INVALID_HANDLE_VALUE_) + { ec.assign(boost::winapi::GetLastError(), system_category()); - else - ec = {}; + return; + } + if (mode == file_mode::append || + mode == file_mode::append_existing) + { + boost::winapi::LARGE_INTEGER_ in; + in.QuadPart = 0; + if (!detail::set_file_pointer_ex(h_, in, 0, + boost::winapi::FILE_END_)) + { + ec.assign(boost::winapi::GetLastError(), + system_category()); + boost::winapi::CloseHandle(h_); + h_ = boost::winapi::INVALID_HANDLE_VALUE_; + return; + } + } + ec = {}; } std::uint64_t