Fixed bug 4820 - SDL assumes RW_SEEK_SET == SEEK_SET
authorSylvain Becker <sylvain.becker@gmail.com>
Thu, 10 Oct 2019 17:21:46 +0200
changeset 13108efa5fe44e4e8
parent 13107 074c42dbf8c9
child 13109 28c572567380
Fixed bug 4820 - SDL assumes RW_SEEK_SET == SEEK_SET
src/file/SDL_rwops.c
     1.1 --- a/src/file/SDL_rwops.c	Wed Oct 09 19:38:16 2019 -0400
     1.2 +++ b/src/file/SDL_rwops.c	Thu Oct 10 17:21:46 2019 +0200
     1.3 @@ -361,13 +361,29 @@
     1.4  static Sint64 SDLCALL
     1.5  stdio_seek(SDL_RWops * context, Sint64 offset, int whence)
     1.6  {
     1.7 +    int stdiowhence;
     1.8 +
     1.9 +    switch (whence) {
    1.10 +    case RW_SEEK_SET:
    1.11 +        stdiowhence = SEEK_SET;
    1.12 +        break;
    1.13 +    case RW_SEEK_CUR:
    1.14 +        stdiowhence = SEEK_CUR;
    1.15 +        break;
    1.16 +    case RW_SEEK_END:
    1.17 +        stdiowhence = SEEK_END;
    1.18 +        break;
    1.19 +    default:
    1.20 +        return SDL_SetError("Unknown value for 'whence'");
    1.21 +    }
    1.22 +
    1.23  #if defined(FSEEK_OFF_MIN) && defined(FSEEK_OFF_MAX)
    1.24      if (offset < (Sint64)(FSEEK_OFF_MIN) || offset > (Sint64)(FSEEK_OFF_MAX)) {
    1.25          return SDL_SetError("Seek offset out of range");
    1.26      }
    1.27  #endif
    1.28  
    1.29 -    if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, whence) == 0) {
    1.30 +    if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) {
    1.31          Sint64 pos = ftell(context->hidden.stdio.fp);
    1.32          if (pos < 0) {
    1.33              return SDL_SetError("Couldn't get stream offset");