Don't use opaque handle to get around warnings and other issues

This commit is contained in:
twinaphex 2017-12-14 15:06:28 +01:00
parent dadf968134
commit e23409926e
5 changed files with 94 additions and 55 deletions

View File

@ -25,6 +25,8 @@
#include <dynamic/dylib.h> #include <dynamic/dylib.h>
#include <string/stdstring.h> #include <string/stdstring.h>
#include <retro_assert.h> #include <retro_assert.h>
#include <libretro_vfs.h>
#include <vfs/vfs_implementation.h>
#include <features/features_cpu.h> #include <features/features_cpu.h>
@ -1650,6 +1652,33 @@ bool rarch_environment_cb(unsigned cmd, void *data)
break; break;
} }
case RETRO_ENVIRONMENT_GET_VFS_INTERFACE:
{
const uint32_t supported_vfs_version = 1;
static struct retro_vfs_interface vfs_iface =
{
retro_vfs_file_get_path_impl,
retro_vfs_file_open_impl,
retro_vfs_file_close_impl,
retro_vfs_file_size_impl,
retro_vfs_file_tell_impl,
retro_vfs_file_seek_impl,
retro_vfs_file_read_impl,
retro_vfs_file_write_impl,
retro_vfs_file_flush_impl,
retro_vfs_file_delete_impl
};
struct retro_vfs_interface_info *vfs_iface_info = (struct retro_vfs_interface_info *) data;
if (vfs_iface_info->required_interface_version <= supported_vfs_version)
{
vfs_iface_info->required_interface_version = supported_vfs_version;
vfs_iface_info->iface = &vfs_iface;
}
break;
}
/* Default */ /* Default */
default: default:
RARCH_LOG("Environ UNSUPPORTED (#%u).\n", cmd); RARCH_LOG("Environ UNSUPPORTED (#%u).\n", cmd);

View File

@ -47,41 +47,41 @@ struct retro_vfs_file_handle;
/* Get path from opaque handle. Returns the exact same path passed to file_open when getting the handle /* Get path from opaque handle. Returns the exact same path passed to file_open when getting the handle
* Introduced in VFS API v1 */ * Introduced in VFS API v1 */
typedef const char *(RETRO_CALLCONV *retro_vfs_file_get_path_t)(struct retro_vfs_file_handle *stream); typedef const char *(RETRO_CALLCONV *retro_vfs_file_get_path_t)(void *data);
/* Open a file for reading or writing. If path points to a directory, this will /* Open a file for reading or writing. If path points to a directory, this will
* fail. Returns the opaque file handle, or NULL for error. * fail. Returns the opaque file handle, or NULL for error.
* Introduced in VFS API v1 */ * Introduced in VFS API v1 */
typedef struct retro_vfs_file_handle *(RETRO_CALLCONV *retro_vfs_file_open_t)(const char *path, unsigned mode, unsigned hints); typedef void *(RETRO_CALLCONV *retro_vfs_file_open_t)(const char *path, unsigned mode, unsigned hints);
/* Close the file and release its resources. Must be called if open_file returns non-NULL. Returns 0 on succes, -1 on failure. /* Close the file and release its resources. Must be called if open_file returns non-NULL. Returns 0 on succes, -1 on failure.
* Whether the call succeeds ot not, the handle passed as parameter becomes invalid and should no longer be used. * Whether the call succeeds ot not, the handle passed as parameter becomes invalid and should no longer be used.
* Introduced in VFS API v1 */ * Introduced in VFS API v1 */
typedef int (RETRO_CALLCONV *retro_vfs_file_close_t)(struct retro_vfs_file_handle *stream); typedef int (RETRO_CALLCONV *retro_vfs_file_close_t)(void *data);
/* Return the size of the file in bytes, or -1 for error. /* Return the size of the file in bytes, or -1 for error.
* Introduced in VFS API v1 */ * Introduced in VFS API v1 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_size_t)(struct retro_vfs_file_handle *stream); typedef int64_t (RETRO_CALLCONV *retro_vfs_file_size_t)(void *data);
/* Get the current read / write position for the file. Returns - 1 for error. /* Get the current read / write position for the file. Returns - 1 for error.
* Introduced in VFS API v1 */ * Introduced in VFS API v1 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_tell_t)(struct retro_vfs_file_handle *stream); typedef int64_t (RETRO_CALLCONV *retro_vfs_file_tell_t)(void *data);
/* Set the current read/write position for the file. Returns the new position, -1 for error. /* Set the current read/write position for the file. Returns the new position, -1 for error.
* Introduced in VFS API v1 */ * Introduced in VFS API v1 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_seek_t)(struct retro_vfs_file_handle *stream, int64_t offset, int whence); typedef int64_t (RETRO_CALLCONV *retro_vfs_file_seek_t)(void *data, int64_t offset, int whence);
/* Read data from a file. Returns the number of bytes read, or -1 for error. /* Read data from a file. Returns the number of bytes read, or -1 for error.
* Introduced in VFS API v1 */ * Introduced in VFS API v1 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_read_t)(struct retro_vfs_file_handle *stream, void *s, uint64_t len); typedef int64_t (RETRO_CALLCONV *retro_vfs_file_read_t)(void *data, void *s, uint64_t len);
/* Write data to a file. Returns the number of bytes written, or -1 for error. /* Write data to a file. Returns the number of bytes written, or -1 for error.
* Introduced in VFS API v1 */ * Introduced in VFS API v1 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_write_t)(struct retro_vfs_file_handle *stream, const void *s, uint64_t len); typedef int64_t (RETRO_CALLCONV *retro_vfs_file_write_t)(void *data, const void *s, uint64_t len);
/* Flush pending writes to file, if using buffered IO. Returns 0 on sucess, or -1 on failure. /* Flush pending writes to file, if using buffered IO. Returns 0 on sucess, or -1 on failure.
* Introduced in VFS API v1 */ * Introduced in VFS API v1 */
typedef int (RETRO_CALLCONV *retro_vfs_file_flush_t)(struct retro_vfs_file_handle *stream); typedef int (RETRO_CALLCONV *retro_vfs_file_flush_t)(void *data);
/* Delete the specified file. Returns 0 on success, -1 on failure /* Delete the specified file. Returns 0 on success, -1 on failure
* Introduced in VFS API v1 */ * Introduced in VFS API v1 */

View File

@ -32,32 +32,26 @@
* for VFS and as fallbacks for when the front end does not provide VFS functionality. * for VFS and as fallbacks for when the front end does not provide VFS functionality.
*/ */
#ifdef VFS_FRONTEND void *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints);
typedef struct retro_vfs_file_handle libretro_vfs_implementation_file;
#else
typedef struct libretro_vfs_implementation_file libretro_vfs_implementation_file;
#endif
libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints); int retro_vfs_file_close_impl(void *data);
int retro_vfs_file_close_impl(libretro_vfs_implementation_file *stream); int retro_vfs_file_error_impl(void *data);
int retro_vfs_file_error_impl(libretro_vfs_implementation_file *stream); int64_t retro_vfs_file_size_impl(void *data);
int64_t retro_vfs_file_size_impl(libretro_vfs_implementation_file *stream); int64_t retro_vfs_file_tell_impl(void *data);
int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream); int64_t retro_vfs_file_seek_impl(void *data, int64_t offset, int whence);
int64_t retro_vfs_file_seek_impl(libretro_vfs_implementation_file *stream, int64_t offset, int whence); int64_t retro_vfs_file_read_impl(void *data, void *s, uint64_t len);
int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, void *s, uint64_t len); int64_t retro_vfs_file_write_impl(void *data, const void *s, uint64_t len);
int64_t retro_vfs_file_write_impl(libretro_vfs_implementation_file *stream, const void *s, uint64_t len); int retro_vfs_file_flush_impl(void *data);
int retro_vfs_file_flush_impl(libretro_vfs_implementation_file *stream);
int retro_vfs_file_delete_impl(const char *path); int retro_vfs_file_delete_impl(const char *path);
const char *retro_vfs_file_get_path_impl(libretro_vfs_implementation_file *stream); const char *retro_vfs_file_get_path_impl(void *data);
#endif #endif

View File

@ -99,7 +99,7 @@ int64_t filestream_get_size(RFILE *stream)
if (filestream_size_cb != NULL) if (filestream_size_cb != NULL)
output = filestream_size_cb(stream->hfile); output = filestream_size_cb(stream->hfile);
else else
output = retro_vfs_file_size_impl((libretro_vfs_implementation_file*)stream->hfile); output = retro_vfs_file_size_impl(stream->hfile);
if (output == vfs_error_return_value) if (output == vfs_error_return_value)
stream->error_flag = true; stream->error_flag = true;
@ -177,7 +177,7 @@ ssize_t filestream_seek(RFILE *stream, ssize_t offset, int whence)
if (filestream_seek_cb != NULL) if (filestream_seek_cb != NULL)
output = filestream_seek_cb(stream->hfile, offset, whence); output = filestream_seek_cb(stream->hfile, offset, whence);
else else
output = retro_vfs_file_seek_impl((libretro_vfs_implementation_file*)stream->hfile, offset, whence); output = retro_vfs_file_seek_impl(stream->hfile, offset, whence);
if (output == vfs_error_return_value) if (output == vfs_error_return_value)
stream->error_flag = true; stream->error_flag = true;
@ -203,7 +203,7 @@ ssize_t filestream_tell(RFILE *stream)
if (filestream_size_cb != NULL) if (filestream_size_cb != NULL)
output = filestream_tell_cb(stream->hfile); output = filestream_tell_cb(stream->hfile);
else else
output = retro_vfs_file_tell_impl((libretro_vfs_implementation_file*)stream->hfile); output = retro_vfs_file_tell_impl(stream->hfile);
if (output == vfs_error_return_value) if (output == vfs_error_return_value)
stream->error_flag = true; stream->error_flag = true;
@ -226,7 +226,7 @@ ssize_t filestream_read(RFILE *stream, void *s, size_t len)
if (filestream_read_cb != NULL) if (filestream_read_cb != NULL)
output = filestream_read_cb(stream->hfile, s, len); output = filestream_read_cb(stream->hfile, s, len);
else else
output = retro_vfs_file_read_impl((libretro_vfs_implementation_file*)stream->hfile, s, len); output = retro_vfs_file_read_impl(stream->hfile, s, len);
if (output == vfs_error_return_value) if (output == vfs_error_return_value)
stream->error_flag = true; stream->error_flag = true;
@ -241,7 +241,7 @@ int filestream_flush(RFILE *stream)
if (filestream_flush_cb != NULL) if (filestream_flush_cb != NULL)
output = filestream_flush_cb(stream->hfile); output = filestream_flush_cb(stream->hfile);
else else
output = retro_vfs_file_flush_impl((libretro_vfs_implementation_file*)stream->hfile); output = retro_vfs_file_flush_impl(stream->hfile);
if (output == vfs_error_return_value) if (output == vfs_error_return_value)
stream->error_flag = true; stream->error_flag = true;
@ -262,7 +262,7 @@ const char *filestream_get_path(RFILE *stream)
if (filestream_get_path_cb != NULL) if (filestream_get_path_cb != NULL)
return filestream_get_path_cb(stream->hfile); return filestream_get_path_cb(stream->hfile);
return retro_vfs_file_get_path_impl((libretro_vfs_implementation_file*)stream->hfile); return retro_vfs_file_get_path_impl(stream->hfile);
} }
ssize_t filestream_write(RFILE *stream, const void *s, size_t len) ssize_t filestream_write(RFILE *stream, const void *s, size_t len)
@ -272,7 +272,7 @@ ssize_t filestream_write(RFILE *stream, const void *s, size_t len)
if (filestream_write_cb != NULL) if (filestream_write_cb != NULL)
output = filestream_write_cb(stream->hfile, s, len); output = filestream_write_cb(stream->hfile, s, len);
else else
output = retro_vfs_file_write_impl((libretro_vfs_implementation_file*)stream->hfile, s, len); output = retro_vfs_file_write_impl(stream->hfile, s, len);
if (output == vfs_error_return_value) if (output == vfs_error_return_value)
stream->error_flag = true; stream->error_flag = true;
@ -281,11 +281,11 @@ ssize_t filestream_write(RFILE *stream, const void *s, size_t len)
} }
/* Hack function */ /* Hack function */
int retro_vfs_file_putc(libretro_vfs_implementation_file *stream, int c); int retro_vfs_file_putc(void *data, int c);
int filestream_putc(RFILE *stream, int c) int filestream_putc(RFILE *stream, int c)
{ {
return retro_vfs_file_putc((libretro_vfs_implementation_file*)stream->hfile, c); return retro_vfs_file_putc(stream->hfile, c);
} }
int filestream_vprintf(RFILE *stream, const char* format, va_list args) int filestream_vprintf(RFILE *stream, const char* format, va_list args)
@ -321,12 +321,12 @@ int filestream_error(RFILE *stream)
int filestream_close(RFILE *stream) int filestream_close(RFILE *stream)
{ {
int output; int output;
struct retro_vfs_file_handle* fp = stream->hfile; void *fp = stream->hfile;
if (filestream_close_cb != NULL) if (filestream_close_cb != NULL)
output = filestream_close_cb(fp); output = filestream_close_cb(fp);
else else
output = retro_vfs_file_close_impl((libretro_vfs_implementation_file*)fp); output = retro_vfs_file_close_impl(fp);
if (output == 0) if (output == 0)
free(stream); free(stream);

View File

@ -94,21 +94,15 @@
#include <retro_miscellaneous.h> #include <retro_miscellaneous.h>
#include <encodings/utf.h> #include <encodings/utf.h>
#if 0
#ifdef RARCH_INTERNAL #ifdef RARCH_INTERNAL
#ifndef VFS_FRONTEND #ifndef VFS_FRONTEND
#define VFS_FRONTEND #define VFS_FRONTEND
#endif #endif
#endif #endif
#endif
#define RFILE_HINT_UNBUFFERED (1 << 8) #define RFILE_HINT_UNBUFFERED (1 << 8)
#ifdef VFS_FRONTEND
struct retro_vfs_file_handle
#else
struct libretro_vfs_implementation_file struct libretro_vfs_implementation_file
#endif
{ {
int fd; int fd;
unsigned hints; unsigned hints;
@ -124,8 +118,9 @@ struct libretro_vfs_implementation_file
#endif #endif
}; };
int64_t retro_vfs_file_seek_internal(libretro_vfs_implementation_file *stream, int64_t offset, int whence) int64_t retro_vfs_file_seek_internal(void *data, int64_t offset, int whence)
{ {
struct libretro_vfs_implementation_file *stream = (struct libretro_vfs_implementation_file*)data;
if (!stream) if (!stream)
goto error; goto error;
@ -188,7 +183,7 @@ error:
* Returns a pointer to an RFILE if opened successfully, otherwise NULL. * Returns a pointer to an RFILE if opened successfully, otherwise NULL.
**/ **/
libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints) void *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints)
{ {
int flags = 0; int flags = 0;
#if !defined(_WIN32) || defined(LEGACY_WIN32) #if !defined(_WIN32) || defined(LEGACY_WIN32)
@ -196,7 +191,8 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, uns
#else #else
const wchar_t *mode_str = NULL; const wchar_t *mode_str = NULL;
#endif #endif
libretro_vfs_implementation_file *stream = (libretro_vfs_implementation_file*)calloc(1, sizeof(*stream)); struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)calloc(1, sizeof(*stream));
if (!stream) if (!stream)
return NULL; return NULL;
@ -337,8 +333,10 @@ error:
return NULL; return NULL;
} }
int retro_vfs_file_close_impl(libretro_vfs_implementation_file *stream) int retro_vfs_file_close_impl(void *data)
{ {
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream) if (!stream)
return -1; return -1;
@ -364,20 +362,26 @@ int retro_vfs_file_close_impl(libretro_vfs_implementation_file *stream)
return 0; return 0;
} }
int retro_vfs_file_error_impl(libretro_vfs_implementation_file *stream) int retro_vfs_file_error_impl(void *data)
{ {
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
return ferror(stream->fp); return ferror(stream->fp);
} }
int64_t retro_vfs_file_size_impl(libretro_vfs_implementation_file *stream) int64_t retro_vfs_file_size_impl(void *data)
{ {
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream) if (!stream)
return 0; return 0;
return stream->size; return stream->size;
} }
int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream) int64_t retro_vfs_file_tell_impl(void *data)
{ {
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream) if (!stream)
return -1; return -1;
@ -396,13 +400,17 @@ int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream)
return 0; return 0;
} }
int64_t retro_vfs_file_seek_impl(libretro_vfs_implementation_file *stream, int64_t offset, int whence) int64_t retro_vfs_file_seek_impl(void *data, int64_t offset, int whence)
{ {
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
return retro_vfs_file_seek_internal(stream, offset, whence); return retro_vfs_file_seek_internal(stream, offset, whence);
} }
int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, void *s, uint64_t len) int64_t retro_vfs_file_read_impl(void *data, void *s, uint64_t len)
{ {
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream || !s) if (!stream || !s)
goto error; goto error;
@ -431,8 +439,10 @@ error:
return -1; return -1;
} }
int64_t retro_vfs_file_write_impl(libretro_vfs_implementation_file *stream, const void *s, uint64_t len) int64_t retro_vfs_file_write_impl(void *data, const void *s, uint64_t len)
{ {
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream) if (!stream)
goto error; goto error;
@ -449,8 +459,10 @@ error:
return -1; return -1;
} }
int retro_vfs_file_flush_impl(libretro_vfs_implementation_file *stream) int retro_vfs_file_flush_impl(void *data)
{ {
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream) if (!stream)
return -1; return -1;
return fflush(stream->fp); return fflush(stream->fp);
@ -461,14 +473,18 @@ int retro_vfs_file_delete_impl(const char *path)
return remove(path) == 0; return remove(path) == 0;
} }
const char *retro_vfs_file_get_path_impl(libretro_vfs_implementation_file *stream) const char *retro_vfs_file_get_path_impl(void *data)
{ {
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
/* TODO/FIXME - implement */ /* TODO/FIXME - implement */
return NULL; return NULL;
} }
int retro_vfs_file_putc(libretro_vfs_implementation_file *stream, int c) int retro_vfs_file_putc(void *data, int c)
{ {
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream) if (!stream)
return EOF; return EOF;