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

This reverts commit e23409926e9a7b8b9038683e2a35db9f9d91e258.
This commit is contained in:
Alcaro 2017-12-14 17:27:02 +01:00
parent 7bf996abe6
commit d5847c2391
5 changed files with 61 additions and 66 deletions

View File

@ -26,6 +26,7 @@
#include <string/stdstring.h>
#include <retro_assert.h>
#include <libretro_vfs.h>
#define VFS_FRONTEND
#include <vfs/vfs_implementation.h>
#include <features/features_cpu.h>
@ -1651,7 +1652,7 @@ bool rarch_environment_cb(unsigned cmd, void *data)
core_set_shared_context = true;
break;
}
case RETRO_ENVIRONMENT_GET_VFS_INTERFACE:
{
const uint32_t supported_vfs_version = 1;

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
* Introduced in VFS API v1 */
typedef const char *(RETRO_CALLCONV *retro_vfs_file_get_path_t)(void *data);
typedef const char *(RETRO_CALLCONV *retro_vfs_file_get_path_t)(struct retro_vfs_file_handle *stream);
/* 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.
* Introduced in VFS API v1 */
typedef void *(RETRO_CALLCONV *retro_vfs_file_open_t)(const char *path, unsigned mode, unsigned hints);
typedef struct retro_vfs_file_handle *(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.
* Whether the call succeeds ot not, the handle passed as parameter becomes invalid and should no longer be used.
* Introduced in VFS API v1 */
typedef int (RETRO_CALLCONV *retro_vfs_file_close_t)(void *data);
typedef int (RETRO_CALLCONV *retro_vfs_file_close_t)(struct retro_vfs_file_handle *stream);
/* Return the size of the file in bytes, or -1 for error.
* Introduced in VFS API v1 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_size_t)(void *data);
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_size_t)(struct retro_vfs_file_handle *stream);
/* Get the current read / write position for the file. Returns - 1 for error.
* Introduced in VFS API v1 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_tell_t)(void *data);
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_tell_t)(struct retro_vfs_file_handle *stream);
/* Set the current read/write position for the file. Returns the new position, -1 for error.
* Introduced in VFS API v1 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_seek_t)(void *data, int64_t offset, int whence);
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_seek_t)(struct retro_vfs_file_handle *stream, int64_t offset, int whence);
/* Read data from a file. Returns the number of bytes read, or -1 for error.
* Introduced in VFS API v1 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_read_t)(void *data, void *s, uint64_t len);
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_read_t)(struct retro_vfs_file_handle *stream, void *s, uint64_t len);
/* Write data to a file. Returns the number of bytes written, or -1 for error.
* Introduced in VFS API v1 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_write_t)(void *data, const void *s, uint64_t len);
typedef int64_t (RETRO_CALLCONV *retro_vfs_file_write_t)(struct retro_vfs_file_handle *stream, const void *s, uint64_t len);
/* Flush pending writes to file, if using buffered IO. Returns 0 on sucess, or -1 on failure.
* Introduced in VFS API v1 */
typedef int (RETRO_CALLCONV *retro_vfs_file_flush_t)(void *data);
typedef int (RETRO_CALLCONV *retro_vfs_file_flush_t)(struct retro_vfs_file_handle *stream);
/* Delete the specified file. Returns 0 on success, -1 on failure
* Introduced in VFS API v1 */

View File

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

View File

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

View File

@ -86,6 +86,12 @@
#define MODE_STR_WRITE_PLUS L"w+"
#endif
#ifdef RARCH_INTERNAL
#ifndef VFS_FRONTEND
#define VFS_FRONTEND
#endif
#endif
#include <vfs/vfs_implementation.h>
#include <libretro_vfs.h>
#include <string/stdstring.h>
@ -95,7 +101,11 @@
#define RFILE_HINT_UNBUFFERED (1 << 8)
#ifdef VFS_FRONTEND
struct retro_vfs_file_handle
#else
struct libretro_vfs_implementation_file
#endif
{
int fd;
unsigned hints;
@ -111,9 +121,8 @@ struct libretro_vfs_implementation_file
#endif
};
int64_t retro_vfs_file_seek_internal(void *data, int64_t offset, int whence)
int64_t retro_vfs_file_seek_internal(libretro_vfs_implementation_file *stream, int64_t offset, int whence)
{
struct libretro_vfs_implementation_file *stream = (struct libretro_vfs_implementation_file*)data;
if (!stream)
goto error;
@ -176,7 +185,7 @@ error:
* Returns a pointer to an RFILE if opened successfully, otherwise NULL.
**/
void *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints)
libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints)
{
int flags = 0;
#if !defined(_WIN32) || defined(LEGACY_WIN32)
@ -184,8 +193,7 @@ void *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints)
#else
const wchar_t *mode_str = NULL;
#endif
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)calloc(1, sizeof(*stream));
libretro_vfs_implementation_file *stream = (libretro_vfs_implementation_file*)calloc(1, sizeof(*stream));
if (!stream)
return NULL;
@ -326,10 +334,8 @@ error:
return NULL;
}
int retro_vfs_file_close_impl(void *data)
int retro_vfs_file_close_impl(libretro_vfs_implementation_file *stream)
{
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream)
return -1;
@ -355,26 +361,20 @@ int retro_vfs_file_close_impl(void *data)
return 0;
}
int retro_vfs_file_error_impl(void *data)
int retro_vfs_file_error_impl(libretro_vfs_implementation_file *stream)
{
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
return ferror(stream->fp);
}
int64_t retro_vfs_file_size_impl(void *data)
int64_t retro_vfs_file_size_impl(libretro_vfs_implementation_file *stream)
{
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream)
return 0;
return stream->size;
}
int64_t retro_vfs_file_tell_impl(void *data)
int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream)
{
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream)
return -1;
@ -393,17 +393,13 @@ int64_t retro_vfs_file_tell_impl(void *data)
return 0;
}
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)
{
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
return retro_vfs_file_seek_internal(stream, offset, 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)
{
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream || !s)
goto error;
@ -432,10 +428,8 @@ error:
return -1;
}
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)
{
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream)
goto error;
@ -452,10 +446,8 @@ error:
return -1;
}
int retro_vfs_file_flush_impl(void *data)
int retro_vfs_file_flush_impl(libretro_vfs_implementation_file *stream)
{
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream)
return -1;
return fflush(stream->fp);
@ -466,18 +458,14 @@ int retro_vfs_file_delete_impl(const char *path)
return remove(path) == 0;
}
const char *retro_vfs_file_get_path_impl(void *data)
const char *retro_vfs_file_get_path_impl(libretro_vfs_implementation_file *stream)
{
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
/* TODO/FIXME - implement */
return NULL;
}
int retro_vfs_file_putc(void *data, int c)
int retro_vfs_file_putc(libretro_vfs_implementation_file *stream, int c)
{
struct libretro_vfs_implementation_file *stream =
(struct libretro_vfs_implementation_file*)data;
if (!stream)
return EOF;