From 7d78835f87da50d58f88ad780f838f92fd36634b Mon Sep 17 00:00:00 2001 From: ds-sloth <72112344+ds-sloth@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:13:49 -0400 Subject: [PATCH] SDL_iostream.c: stdio_seek - skip API call for SEEK_CUR with 0 offset Fixes #10556. --- src/file/SDL_iostream.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/file/SDL_iostream.c b/src/file/SDL_iostream.c index d10de2da79..7b7b309349 100644 --- a/src/file/SDL_iostream.c +++ b/src/file/SDL_iostream.c @@ -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");