SDL_iostream.c: stdio_seek - skip API call for SEEK_CUR with 0 offset

Fixes #10556.
This commit is contained in:
ds-sloth 2024-08-16 17:13:49 -04:00 committed by GitHub
parent ab53ff77bb
commit 7d78835f87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 1 deletions

View File

@ -360,7 +360,10 @@ static Sint64 SDLCALL stdio_seek(void *userdata, Sint64 offset, SDL_IOWhence whe
}
#endif
if (fseek(iodata->fp, (fseek_off_t)offset, stdiowhence) == 0) {
/* don't make a possibly-costly API call for the noop seek from SDL_TellIO */
const SDL_bool is_noop = (whence == SDL_IO_SEEK_CUR) && (offset == 0);
if (is_noop || fseek(iodata->fp, (fseek_off_t)offset, stdiowhence) == 0) {
const Sint64 pos = ftell(iodata->fp);
if (pos < 0) {
return SDL_SetError("Couldn't get stream offset");