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

Returns int64 value in function of seeking to file end on x64 Windows. #1057

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion Release/include/cpprest/filestream.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,19 @@ class basic_file_buffer : public details::streambuf_state_manager<_CharType>
if (mode == std::ios_base::in)
{
m_readOps.wait();
size_t current_pos = static_cast<size_t>(-1);
switch (way)
{
case std::ios_base::beg: return (pos_type)_seekrdpos_fsb(m_info, size_t(offset), sizeof(_CharType));
case std::ios_base::cur:
return (pos_type)_seekrdpos_fsb(m_info, size_t(m_info->m_rdpos + offset), sizeof(_CharType));
case std::ios_base::end: return (pos_type)_seekrdtoend_fsb(m_info, int64_t(offset), sizeof(_CharType));
case std::ios_base::end:
current_pos = _seekrdtoend_fsb(m_info, int64_t(offset), sizeof(_CharType));
if (current_pos == static_cast<size_t>(-1))
{
return -1;
}
return (pos_type)current_pos;
default:
// Fail on invalid input (_S_ios_seekdir_end)
assert(false);
Expand Down
15 changes: 15 additions & 0 deletions Release/src/streams/fileio_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,11 +905,26 @@ size_t __cdecl _seekrdtoend_fsb(_In_ streams::details::_file_info* info, int64_t
fInfo->m_bufoff = fInfo->m_buffill = fInfo->m_bufsize = 0;
}

#ifdef _WIN64
LARGE_INTEGER filesize;
filesize.QuadPart = 0;

BOOL result = GetFileSizeEx(fInfo->m_handle, &filesize);
if (FALSE == result)
{
return static_cast<size_t>(-1);
}
else
{
fInfo->m_rdpos = static_cast<size_t>(filesize.QuadPart) / char_size;
}
#else
auto newpos = SetFilePointer(fInfo->m_handle, (LONG)(offset * char_size), nullptr, FILE_END);

if (newpos == INVALID_SET_FILE_POINTER) return static_cast<size_t>(-1);

fInfo->m_rdpos = static_cast<size_t>(newpos) / char_size;
#endif

return fInfo->m_rdpos;
}
Expand Down