mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 00:13:08 +00:00
Remove inaccurate error behavior
Seek can have offsets past the end of a file. Also add logging for two valid whence values that are unsupported on Windows. I'll need to verify that SEEK_HOLE and SEEK_DATA correspond to 3 and 4 respectively, I've yet to check source to verify.
This commit is contained in:
parent
62a8eda2bd
commit
b2c3da432c
@ -125,12 +125,14 @@ namespace {
|
|||||||
[[nodiscard]] constexpr int ToSeekOrigin(SeekOrigin origin) {
|
[[nodiscard]] constexpr int ToSeekOrigin(SeekOrigin origin) {
|
||||||
switch (origin) {
|
switch (origin) {
|
||||||
case SeekOrigin::SetOrigin:
|
case SeekOrigin::SetOrigin:
|
||||||
default:
|
|
||||||
return SEEK_SET;
|
return SEEK_SET;
|
||||||
case SeekOrigin::CurrentPosition:
|
case SeekOrigin::CurrentPosition:
|
||||||
return SEEK_CUR;
|
return SEEK_CUR;
|
||||||
case SeekOrigin::End:
|
case SeekOrigin::End:
|
||||||
return SEEK_END;
|
return SEEK_END;
|
||||||
|
default:
|
||||||
|
LOG_ERROR(Core, "Unsupported origin {}, defaulting to SEEK_SET", origin);
|
||||||
|
return SEEK_SET;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,8 @@ enum class SeekOrigin : u32 {
|
|||||||
SetOrigin, // Seeks from the start of the file.
|
SetOrigin, // Seeks from the start of the file.
|
||||||
CurrentPosition, // Seeks from the current file pointer position.
|
CurrentPosition, // Seeks from the current file pointer position.
|
||||||
End, // Seeks from the end of the file.
|
End, // Seeks from the end of the file.
|
||||||
|
SeekHole, // Seeks from the start of the next hole in the file.
|
||||||
|
SeekData, // Seeks from the start of the next non-hole region in the file.
|
||||||
};
|
};
|
||||||
|
|
||||||
class IOFile final {
|
class IOFile final {
|
||||||
|
@ -367,6 +367,10 @@ s64 PS4_SYSV_ABI posix_lseek(s32 fd, s64 offset, s32 whence) {
|
|||||||
origin = Common::FS::SeekOrigin::CurrentPosition;
|
origin = Common::FS::SeekOrigin::CurrentPosition;
|
||||||
} else if (whence == 2) {
|
} else if (whence == 2) {
|
||||||
origin = Common::FS::SeekOrigin::End;
|
origin = Common::FS::SeekOrigin::End;
|
||||||
|
} else if (whence == 3) {
|
||||||
|
origin = Common::FS::SeekOrigin::SeekHole;
|
||||||
|
} else if (whence == 4) {
|
||||||
|
origin = Common::FS::SeekOrigin::SeekData;
|
||||||
} else {
|
} else {
|
||||||
// whence parameter is invalid
|
// whence parameter is invalid
|
||||||
*__Error() = POSIX_EINVAL;
|
*__Error() = POSIX_EINVAL;
|
||||||
@ -377,10 +381,9 @@ s64 PS4_SYSV_ABI posix_lseek(s32 fd, s64 offset, s32 whence) {
|
|||||||
if (errno != 0) {
|
if (errno != 0) {
|
||||||
// Seek failed in platform-specific code, errno needs to be converted.
|
// Seek failed in platform-specific code, errno needs to be converted.
|
||||||
SetPosixErrno(errno);
|
SetPosixErrno(errno);
|
||||||
} else {
|
return -1;
|
||||||
// Seek failed because offset is beyond the end of the file.
|
|
||||||
*__Error() = POSIX_ENXIO;
|
|
||||||
}
|
}
|
||||||
|
// Shouldn't be possible, but just in case.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user