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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
diff --git a/configure b/configure
index ad5874a..bc6f5c3 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 bb6b9ef..c4abe53 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 3f6283a..bf3382d 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 8822a80..68e43db 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 a3ca213..93727ce 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);
}