Skip to content
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