This commit is contained in:
twinaphex 2017-12-16 14:29:00 +01:00
parent bb58677f28
commit f3cdebfa26
5 changed files with 46 additions and 9 deletions

View File

@ -967,6 +967,23 @@ enum retro_mod
* core supports VFS before it starts handing out paths.
* It is recomended to do so in retro_set_environment */
/* VFS functionality */
/* File paths:
* File paths passed as parameters when using this api shall be well formed unix-style,
* using "/" (unquoted forward slash) as directory separator regardless of the platform's native separator.
* Paths shall also include at least one forward slash ("game.bin" is an invalid path, use "./game.bin" instead).
* Other than the directory separator, cores shall not make assumptions about path format:
* "C:/path/game.bin", "http://example.com/game.bin", "#game/game.bin", "./game.bin" (without quotes) are all valid paths.
* Cores may replace the basename or remove path components from the end, and/or add new components;
* however, cores shall not append "./", "../" or multiple consecutive forward slashes ("//") to paths they request to front end.
* The frontend is encouraged to make such paths work as well as it can, but is allowed to give up if the core alters paths too much.
* Frontends are encouraged, but not required, to support native file system paths (modulo replacing the directory separator, if applicable).
* Cores are allowed to try using them, but must remain functional if the front rejects such requests.
* Cores are encouraged to use the libretro-common filestream functions for file I/O,
* as they seamlessly integrate with VFS, deal with directory separator replacement as appropriate
* and provide platform-specific fallbacks in cases where front ends do not support VFS. */
/* Opaque file handle
* Introduced in VFS API v1 */
struct retro_vfs_file_handle;
@ -985,6 +1002,11 @@ struct retro_vfs_file_handle;
/* Indicate that the file will be accessed many times. The frontend should aggressively cache everything. */
#define RETRO_VFS_FILE_ACCESS_HINT_FREQUENT_ACCESS (1 << 0)
/* Seek positions */
#define RETRO_VFS_SEEK_POSITION_START 0
#define RETRO_VFS_SEEK_POSITION_CURRENT 1
#define RETRO_VFS_SEEK_POSITION_END 2
/* 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_get_path_t)(struct retro_vfs_file_handle *stream);
@ -1009,7 +1031,7 @@ typedef int64_t (RETRO_CALLCONV *retro_vfs_tell_t)(struct retro_vfs_file_handle
/* 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_seek_t)(struct retro_vfs_file_handle *stream, int64_t offset, int whence);
typedef int64_t (RETRO_CALLCONV *retro_vfs_seek_t)(struct retro_vfs_file_handle *stream, int64_t offset, int seek_position);
/* Read data from a file. Returns the number of bytes read, or -1 for error.
* Introduced in VFS API v1 */

View File

@ -60,7 +60,7 @@ int64_t filestream_get_size(RFILE *stream);
**/
RFILE *filestream_open(const char *path, unsigned mode, unsigned hints);
ssize_t filestream_seek(RFILE *stream, ssize_t offset, int whence);
ssize_t filestream_seek(RFILE *stream, ssize_t offset, int seek_position);
ssize_t filestream_read(RFILE *stream, void *data, int64_t len);

View File

@ -48,7 +48,7 @@ int64_t retro_vfs_file_size_impl(libretro_vfs_implementation_file *stream);
int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream);
int64_t retro_vfs_file_seek_impl(libretro_vfs_implementation_file *stream, int64_t offset, int whence);
int64_t retro_vfs_file_seek_impl(libretro_vfs_implementation_file *stream, int64_t offset, int seek_position);
int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, void *s, uint64_t len);

View File

@ -188,14 +188,14 @@ int filestream_getc(RFILE *stream)
return EOF;
}
ssize_t filestream_seek(RFILE *stream, ssize_t offset, int whence)
ssize_t filestream_seek(RFILE *stream, ssize_t offset, int seek_position)
{
int64_t output;
if (filestream_seek_cb != NULL)
output = filestream_seek_cb(stream->hfile, offset, whence);
output = filestream_seek_cb(stream->hfile, offset, seek_position);
else
output = retro_vfs_file_seek_impl((libretro_vfs_implementation_file*)stream->hfile, offset, whence);
output = retro_vfs_file_seek_impl((libretro_vfs_implementation_file*)stream->hfile, offset, seek_position);
if (output == vfs_error_return_value)
stream->error_flag = true;
@ -233,7 +233,7 @@ void filestream_rewind(RFILE *stream)
{
if (!stream)
return;
filestream_seek(stream, 0L, SEEK_SET);
filestream_seek(stream, 0L, RETRO_VFS_SEEK_POSITION_START);
stream->error_flag = false;
}

View File

@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -376,9 +377,23 @@ int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream)
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(libretro_vfs_implementation_file *stream, int64_t offset, int seek_position)
{
return retro_vfs_file_seek_internal(stream, offset, whence);
int whence = -1;
switch (seek_position)
{
case RETRO_VFS_SEEK_POSITION_START:
whence = SEEK_SET;
break;
case RETRO_VFS_SEEK_POSITION_CURRENT:
whence = SEEK_CUR;
break;
case RETRO_VFS_SEEK_POSITION_END:
whence = SEEK_END;
break;
}
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)