Skip to content

Commit

Permalink
Fixed bug 3292 - SDL_rwops and 64-bit file I/O
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Aug 12, 2017
1 parent 4c239e5 commit a48c9e6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion configure
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion configure.in
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/SDL_config.h.cmake
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/SDL_config.h.in
Expand Up @@ -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
Expand Down
33 changes: 18 additions & 15 deletions src/file/SDL_rwops.c
Expand Up @@ -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
Expand All @@ -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);
}

Expand Down

0 comments on commit a48c9e6

Please sign in to comment.