mirror of
https://github.com/libretro/RetroArch
synced 2025-03-21 13:20:52 +00:00
Add fallback paths for nbio_stdio.c
This commit is contained in:
parent
c1275cc83d
commit
c3f8b7741c
@ -35,6 +35,18 @@
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if !defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
||||
#define ATLEAST_VC2005
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE - 0) >= 200112) || (defined(__POSIX_VISIBLE) && __POSIX_VISIBLE >= 200112) || (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112) || __USE_LARGEFILE
|
||||
#ifndef HAVE_64BIT_OFFSETS
|
||||
#define HAVE_64BIT_OFFSETS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct nbio_stdio_t
|
||||
{
|
||||
FILE* f;
|
||||
@ -57,11 +69,35 @@ static const char *stdio_modes[] = { "rb", "wb", "r+b", "rb", "wb", "r+b" };
|
||||
static const wchar_t *stdio_modes[] = { L"rb", L"wb", L"r+b", L"rb", L"wb", L"r+b" };
|
||||
#endif
|
||||
|
||||
static int64_t fseek_wrap(FILE *f, int64_t offset, int origin)
|
||||
{
|
||||
#ifdef ATLEAST_VC2005
|
||||
/* VC2005 and up have a special 64-bit fseek */
|
||||
return _fseeki64(f, offset, origin);
|
||||
#elif defined(HAVE_64BIT_OFFSETS)
|
||||
return fseeko(f, (off_t)offset, origin);
|
||||
#else
|
||||
return fseek(f, (long)offset, origin);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int64_t ftell_wrap(FILE *f)
|
||||
{
|
||||
#ifdef ATLEAST_VC2005
|
||||
/* VC2005 and up have a special 64-bit ftell */
|
||||
return _ftelli64(f);
|
||||
#elif defined(HAVE_64BIT_OFFSETS)
|
||||
return ftello(f);
|
||||
#else
|
||||
return ftell(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void *nbio_stdio_open(const char * filename, unsigned mode)
|
||||
{
|
||||
void *buf = NULL;
|
||||
struct nbio_stdio_t* handle = NULL;
|
||||
size_t len = 0;
|
||||
int64_t len = 0;
|
||||
#if !defined(_WIN32) || defined(LEGACY_WIN32)
|
||||
FILE* f = fopen(filename, stdio_modes[mode]);
|
||||
#else
|
||||
@ -87,8 +123,8 @@ static void *nbio_stdio_open(const char * filename, unsigned mode)
|
||||
case BIO_WRITE:
|
||||
break;
|
||||
default:
|
||||
fseek(handle->f, 0, SEEK_END);
|
||||
len = ftell(handle->f);
|
||||
fseek_wrap(handle->f, 0, SEEK_END);
|
||||
len = ftell_wrap(handle->f);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -123,7 +159,7 @@ static void nbio_stdio_begin_read(void *data)
|
||||
if (handle->op >= 0)
|
||||
abort();
|
||||
|
||||
fseek(handle->f, 0, SEEK_SET);
|
||||
fseek_wrap(handle->f, 0, SEEK_SET);
|
||||
|
||||
handle->op = NBIO_READ;
|
||||
handle->progress = 0;
|
||||
@ -138,7 +174,7 @@ static void nbio_stdio_begin_write(void *data)
|
||||
if (handle->op >= 0)
|
||||
abort();
|
||||
|
||||
fseek(handle->f, 0, SEEK_SET);
|
||||
fseek_wrap(handle->f, 0, SEEK_SET);
|
||||
handle->op = NBIO_WRITE;
|
||||
handle->progress = 0;
|
||||
}
|
||||
|
@ -198,8 +198,8 @@ int64_t retro_vfs_file_seek_internal(
|
||||
if (stream->scheme == VFS_SCHEME_CDROM)
|
||||
return retro_vfs_file_seek_cdrom(stream, offset, whence);
|
||||
#endif
|
||||
/* VC2005 and up have a special 64-bit fseek */
|
||||
#ifdef ATLEAST_VC2005
|
||||
/* VC2005 and up have a special 64-bit fseek */
|
||||
return _fseeki64(stream->fp, offset, whence);
|
||||
#elif defined(ORBIS)
|
||||
{
|
||||
@ -607,8 +607,8 @@ int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream)
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
/* VC2005 and up have a special 64-bit ftell */
|
||||
#ifdef ATLEAST_VC2005
|
||||
/* VC2005 and up have a special 64-bit ftell */
|
||||
return _ftelli64(stream->fp);
|
||||
#elif defined(HAVE_64BIT_OFFSETS)
|
||||
return ftello(stream->fp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user