Skip to content

Commit

Permalink
physfs.hpp: Additional error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Sep 14, 2023
1 parent f79f775 commit c2a4d06
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/3rdparty/physfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,25 @@ class fbuf : public streambuf {
pos_type seekoff(off_type pos, ios_base::seekdir dir, ios_base::openmode mode) {
if (dir == std::ios_base::beg)
{
PHYSFS_seek(file, pos);
if (PHYSFS_seek(file, pos) == 0)
{
return pos_type(-1);
}
}
else if (dir == std::ios_base::cur)
{
// subtract characters currently in buffer from seek position
PHYSFS_seek(file, (PHYSFS_tell(file) + pos) - (egptr() - gptr()));
if (PHYSFS_seek(file, (PHYSFS_tell(file) + pos) - (egptr() - gptr())) == 0)
{
return pos_type(-1);
}
}
else if (dir == std::ios_base::end)
{
PHYSFS_seek(file, PHYSFS_fileLength(file) + pos);
if (PHYSFS_seek(file, PHYSFS_fileLength(file) + pos) == 0)
{
return pos_type(-1);
}
}
else
{
Expand All @@ -142,7 +151,10 @@ class fbuf : public streambuf {
}

pos_type seekpos(pos_type pos, std::ios_base::openmode mode) {
PHYSFS_seek(file, pos);
if (PHYSFS_seek(file, pos) == 0)
{
return pos_type(-1);
}
if (mode & std::ios_base::in) {
setg(egptr(), egptr(), egptr());
}
Expand Down

0 comments on commit c2a4d06

Please sign in to comment.