From a48c9e6df80290bb0bc2b38c79b53a3cf18b9166 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 11 Aug 2017 21:16:33 -0700 Subject: [PATCH] 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 | 2 +- configure.in | 2 +- include/SDL_config.h.cmake | 1 + include/SDL_config.h.in | 1 + src/file/SDL_rwops.c | 33 ++++++++++++++++++--------------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/configure b/configure index ad5874ab3febb..bc6f5c3458e88 100755 --- a/configure +++ b/configure @@ -16631,7 +16631,7 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi - 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 + 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 do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.in b/configure.in index bb6b9efcf0e35..c4abe53e4b8e8 100644 --- a/configure.in +++ b/configure.in @@ -268,7 +268,7 @@ if test x$enable_libc = xyes; then AC_DEFINE(HAVE_MPROTECT, 1, [ ]) ]), ) - 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) + 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) AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"]) AC_CHECK_FUNCS(atan atan2 acos asin ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt sqrtf tan tanf) diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index 3f6283a4d6190..bf3382db88e25 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -159,6 +159,7 @@ #cmakedefine HAVE_SQRTF 1 #cmakedefine HAVE_TAN 1 #cmakedefine HAVE_TANF 1 +#cmakedefine HAVE_FOPEN64 1 #cmakedefine HAVE_FSEEKO 1 #cmakedefine HAVE_FSEEKO64 1 #cmakedefine HAVE_SIGACTION 1 diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 8822a80e390dd..68e43db88dd97 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -161,6 +161,7 @@ #undef HAVE_SQRTF #undef HAVE_TAN #undef HAVE_TANF +#undef HAVE_FOPEN64 #undef HAVE_FSEEKO #undef HAVE_FSEEKO64 #undef HAVE_SIGACTION diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index a3ca213c09317..93727ce5b93ae 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -292,6 +292,23 @@ windows_file_close(SDL_RWops * context) #ifdef HAVE_STDIO_H +#ifdef HAVE_FOPEN64 +#define fopen fopen64 +#endif +#ifdef HAVE_FSEEKO64 +#define fseek_off_t off64_t +#define fseek fseeko64 +#define ftell ftello64 +#elif defined(HAVE_FSEEKO) +#define fseek_off_t off_t +#define fseek fseeko +#define ftell ftello +#elif defined(HAVE__FSEEKI64) +#define fseek_off_t __int64 +#define fseek _fseeki64 +#define ftell _ftelli64 +#endif + /* Functions to read/write stdio file pointers */ static Sint64 SDLCALL @@ -312,23 +329,9 @@ stdio_size(SDL_RWops * context) static Sint64 SDLCALL stdio_seek(SDL_RWops * context, Sint64 offset, int whence) { -#ifdef HAVE_FSEEKO64 - if (fseeko64(context->hidden.stdio.fp, (off64_t)offset, whence) == 0) { - return ftello64(context->hidden.stdio.fp); - } -#elif defined(HAVE_FSEEKO) - if (fseeko(context->hidden.stdio.fp, (off_t)offset, whence) == 0) { - return ftello(context->hidden.stdio.fp); - } -#elif defined(HAVE__FSEEKI64) - if (_fseeki64(context->hidden.stdio.fp, offset, whence) == 0) { - return _ftelli64(context->hidden.stdio.fp); - } -#else - if (fseek(context->hidden.stdio.fp, offset, whence) == 0) { + if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, whence) == 0) { return ftell(context->hidden.stdio.fp); } -#endif return SDL_Error(SDL_EFSEEK); }