Fixed bug 3292 - SDL_rwops and 64-bit file I/O
authorSam Lantinga <slouken@libsdl.org>
Fri, 11 Aug 2017 21:16:33 -0700
changeset 1123015b10ad902dd
parent 11229 436b07ff41b4
child 11231 5235df1ce071
Fixed bug 3292 - SDL_rwops and 64-bit file I/O

Juha Niemimä

On AmigaOS 4 platform with Newlib 'C' library, there is a problem with failing fseeko64. This seemed to be caused by using fopen instead of fopen64.
configure
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
src/file/SDL_rwops.c
     1.1 --- a/configure	Fri Aug 11 20:54:06 2017 -0700
     1.2 +++ b/configure	Fri Aug 11 21:16:33 2017 -0700
     1.3 @@ -16631,7 +16631,7 @@
     1.4  rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
     1.5  fi
     1.6  
     1.7 -    for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval
     1.8 +    for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval
     1.9  do :
    1.10    as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
    1.11  ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
     2.1 --- a/configure.in	Fri Aug 11 20:54:06 2017 -0700
     2.2 +++ b/configure.in	Fri Aug 11 21:16:33 2017 -0700
     2.3 @@ -268,7 +268,7 @@
     2.4          AC_DEFINE(HAVE_MPROTECT, 1, [ ])
     2.5          ]),
     2.6      )
     2.7 -    AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval)
     2.8 +    AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval)
     2.9  
    2.10      AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
    2.11      AC_CHECK_FUNCS(atan atan2 acos asin ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt sqrtf tan tanf)
     3.1 --- a/include/SDL_config.h.cmake	Fri Aug 11 20:54:06 2017 -0700
     3.2 +++ b/include/SDL_config.h.cmake	Fri Aug 11 21:16:33 2017 -0700
     3.3 @@ -159,6 +159,7 @@
     3.4  #cmakedefine HAVE_SQRTF 1
     3.5  #cmakedefine HAVE_TAN 1
     3.6  #cmakedefine HAVE_TANF 1
     3.7 +#cmakedefine HAVE_FOPEN64 1
     3.8  #cmakedefine HAVE_FSEEKO 1
     3.9  #cmakedefine HAVE_FSEEKO64 1
    3.10  #cmakedefine HAVE_SIGACTION 1
     4.1 --- a/include/SDL_config.h.in	Fri Aug 11 20:54:06 2017 -0700
     4.2 +++ b/include/SDL_config.h.in	Fri Aug 11 21:16:33 2017 -0700
     4.3 @@ -161,6 +161,7 @@
     4.4  #undef HAVE_SQRTF
     4.5  #undef HAVE_TAN
     4.6  #undef HAVE_TANF
     4.7 +#undef HAVE_FOPEN64
     4.8  #undef HAVE_FSEEKO
     4.9  #undef HAVE_FSEEKO64
    4.10  #undef HAVE_SIGACTION
     5.1 --- a/src/file/SDL_rwops.c	Fri Aug 11 20:54:06 2017 -0700
     5.2 +++ b/src/file/SDL_rwops.c	Fri Aug 11 21:16:33 2017 -0700
     5.3 @@ -292,6 +292,23 @@
     5.4  
     5.5  #ifdef HAVE_STDIO_H
     5.6  
     5.7 +#ifdef HAVE_FOPEN64
     5.8 +#define fopen   fopen64
     5.9 +#endif
    5.10 +#ifdef HAVE_FSEEKO64
    5.11 +#define fseek_off_t off64_t
    5.12 +#define fseek   fseeko64
    5.13 +#define ftell   ftello64
    5.14 +#elif defined(HAVE_FSEEKO)
    5.15 +#define fseek_off_t off_t
    5.16 +#define fseek   fseeko
    5.17 +#define ftell   ftello
    5.18 +#elif defined(HAVE__FSEEKI64)
    5.19 +#define fseek_off_t __int64
    5.20 +#define fseek   _fseeki64
    5.21 +#define ftell   _ftelli64
    5.22 +#endif
    5.23 +
    5.24  /* Functions to read/write stdio file pointers */
    5.25  
    5.26  static Sint64 SDLCALL
    5.27 @@ -312,23 +329,9 @@
    5.28  static Sint64 SDLCALL
    5.29  stdio_seek(SDL_RWops * context, Sint64 offset, int whence)
    5.30  {
    5.31 -#ifdef HAVE_FSEEKO64
    5.32 -    if (fseeko64(context->hidden.stdio.fp, (off64_t)offset, whence) == 0) {
    5.33 -        return ftello64(context->hidden.stdio.fp);
    5.34 -    }
    5.35 -#elif defined(HAVE_FSEEKO)
    5.36 -    if (fseeko(context->hidden.stdio.fp, (off_t)offset, whence) == 0) {
    5.37 -        return ftello(context->hidden.stdio.fp);
    5.38 -    }
    5.39 -#elif defined(HAVE__FSEEKI64)
    5.40 -    if (_fseeki64(context->hidden.stdio.fp, offset, whence) == 0) {
    5.41 -        return _ftelli64(context->hidden.stdio.fp);
    5.42 -    }
    5.43 -#else
    5.44 -    if (fseek(context->hidden.stdio.fp, offset, whence) == 0) {
    5.45 +    if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, whence) == 0) {
    5.46          return ftell(context->hidden.stdio.fp);
    5.47      }
    5.48 -#endif
    5.49      return SDL_Error(SDL_EFSEEK);
    5.50  }
    5.51