Skip to content

Commit

Permalink
Move file offset to end when file_base::append is specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramirisu authored and chriskohlhoff committed Apr 2, 2024
1 parent 7038ebd commit 6fca427
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions asio/include/asio/detail/impl/win_iocp_file_service.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,30 @@ asio::error_code win_iocp_file_service::open(
HANDLE handle = ::CreateFileA(path, access, share, 0, disposition, flags, 0);
if (handle != INVALID_HANDLE_VALUE)
{
if (disposition == OPEN_ALWAYS && (open_flags & file_base::truncate) != 0)
if (disposition == OPEN_ALWAYS)
{
if (!::SetEndOfFile(handle))
if ((open_flags & file_base::truncate) != 0)
{
DWORD last_error = ::GetLastError();
::CloseHandle(handle);
ec.assign(last_error, asio::error::get_system_category());
ASIO_ERROR_LOCATION(ec);
return ec;
if (!::SetEndOfFile(handle))
{
DWORD last_error = ::GetLastError();
::CloseHandle(handle);
ec.assign(last_error, asio::error::get_system_category());
ASIO_ERROR_LOCATION(ec);
return ec;
}
}
else if ((open_flags & file_base::append) != 0)
{
if (::SetFilePointer(handle, 0, 0, FILE_END)
== INVALID_SET_FILE_POINTER)
{
DWORD last_error = ::GetLastError();
::CloseHandle(handle);
ec.assign(last_error, asio::error::get_system_category());
ASIO_ERROR_LOCATION(ec);
return ec;
}
}
}

Expand Down

0 comments on commit 6fca427

Please sign in to comment.