Skip to content

Commit f8e45d4

Browse files
committed
Fixed bug 4820 - SDL assumes RW_SEEK_SET == SEEK_SET
1 parent 00da518 commit f8e45d4

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/file/SDL_rwops.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,29 @@ stdio_size(SDL_RWops * context)
361361
static Sint64 SDLCALL
362362
stdio_seek(SDL_RWops * context, Sint64 offset, int whence)
363363
{
364+
int stdiowhence;
365+
366+
switch (whence) {
367+
case RW_SEEK_SET:
368+
stdiowhence = SEEK_SET;
369+
break;
370+
case RW_SEEK_CUR:
371+
stdiowhence = SEEK_CUR;
372+
break;
373+
case RW_SEEK_END:
374+
stdiowhence = SEEK_END;
375+
break;
376+
default:
377+
return SDL_SetError("Unknown value for 'whence'");
378+
}
379+
364380
#if defined(FSEEK_OFF_MIN) && defined(FSEEK_OFF_MAX)
365381
if (offset < (Sint64)(FSEEK_OFF_MIN) || offset > (Sint64)(FSEEK_OFF_MAX)) {
366382
return SDL_SetError("Seek offset out of range");
367383
}
368384
#endif
369385

370-
if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, whence) == 0) {
386+
if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) {
371387
Sint64 pos = ftell(context->hidden.stdio.fp);
372388
if (pos < 0) {
373389
return SDL_SetError("Couldn't get stream offset");

0 commit comments

Comments
 (0)