Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file_base::append for both create/open for windows stream_file. #1500

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions asio/include/asio/detail/impl/win_iocp_file_service.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ asio::error_code win_iocp_file_service::open(
if ((open_flags & file_base::sync_all_on_write) != 0)
flags |= FILE_FLAG_WRITE_THROUGH;

impl.offset_ = 0;
HANDLE handle = ::CreateFileA(path, access, share, 0, disposition, flags, 0);
if (handle != INVALID_HANDLE_VALUE)
{
Expand All @@ -110,10 +111,18 @@ asio::error_code win_iocp_file_service::open(
return ec;
}
}
else if ((open_flags & file_base::append) != 0)
}
if (disposition == OPEN_ALWAYS || disposition == OPEN_EXISTING)
{
if ((open_flags & file_base::append) != 0)
{
if (::SetFilePointer(handle, 0, 0, FILE_END)
== INVALID_SET_FILE_POINTER)
LARGE_INTEGER distance, new_offset;
distance.QuadPart = 0;
if (::SetFilePointerEx(handle, distance, &new_offset, FILE_END))
{
impl.offset_ = static_cast<uint64_t>(new_offset.QuadPart);
}
else
{
DWORD last_error = ::GetLastError();
::CloseHandle(handle);
Expand All @@ -127,7 +136,6 @@ asio::error_code win_iocp_file_service::open(
handle_service_.assign(impl, handle, ec);
if (ec)
::CloseHandle(handle);
impl.offset_ = 0;
ASIO_ERROR_LOCATION(ec);
return ec;
}
Expand Down