From 2824d138b9dcc2c113c8057d0ef377e3edfb24be Mon Sep 17 00:00:00 2001 From: ds-sloth <72112344+ds-sloth@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:12:34 -0400 Subject: [PATCH] SDL_rwops.c: stdio_seek - skip API call for RW_SEEK_CUR with 0 offset Reference Issue #10556. --- src/file/SDL_rwops.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index 444bf4af3d5c5..8d2042cc0534c 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -369,6 +369,7 @@ stdio_size(SDL_RWops * context) static Sint64 SDLCALL stdio_seek(SDL_RWops *context, Sint64 offset, int whence) { int stdiowhence; + SDL_bool is_noop; switch (whence) { case RW_SEEK_SET: @@ -390,7 +391,10 @@ static Sint64 SDLCALL stdio_seek(SDL_RWops *context, Sint64 offset, int whence) } #endif - if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) { + /* don't make a possibly-costly API call for the noop seek from SDL_RWtell */ + is_noop = (whence == RW_SEEK_CUR) && (offset == 0); + + if (is_noop || fseek(context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) { Sint64 pos = ftell(context->hidden.stdio.fp); if (pos < 0) { return SDL_SetError("Couldn't get stream offset");