mirror of
https://github.com/libretro/RetroArch
synced 2025-04-02 16:20:39 +00:00
(VFS implementation) Small cleanups
This commit is contained in:
parent
fb653d22dc
commit
d41827ec7e
@ -213,7 +213,7 @@ struct libretro_vfs_implementation_file
|
||||
int64_t retro_vfs_file_seek_internal(libretro_vfs_implementation_file *stream, int64_t offset, int whence)
|
||||
{
|
||||
if (!stream)
|
||||
goto error;
|
||||
return -1;
|
||||
|
||||
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
||||
{
|
||||
@ -226,7 +226,7 @@ int64_t retro_vfs_file_seek_internal(libretro_vfs_implementation_file *stream, i
|
||||
int64_t ret = fileXioLseek(fileno(stream->fp), (off_t)offset, whence);
|
||||
/* fileXioLseek could return positive numbers */
|
||||
if (ret > 0)
|
||||
ret = 0;
|
||||
return 0;
|
||||
return ret;
|
||||
#elif defined(ORBIS)
|
||||
int ret = orbisLseek(stream->fd, offset, whence);
|
||||
@ -250,7 +250,7 @@ int64_t retro_vfs_file_seek_internal(libretro_vfs_implementation_file *stream, i
|
||||
{
|
||||
case SEEK_SET:
|
||||
if (offset < 0)
|
||||
goto error;
|
||||
return -1;
|
||||
|
||||
stream->mappos = offset;
|
||||
break;
|
||||
@ -258,14 +258,14 @@ int64_t retro_vfs_file_seek_internal(libretro_vfs_implementation_file *stream, i
|
||||
case SEEK_CUR:
|
||||
if ( (offset < 0 && stream->mappos + offset > stream->mappos) ||
|
||||
(offset > 0 && stream->mappos + offset < stream->mappos))
|
||||
goto error;
|
||||
return -1;
|
||||
|
||||
stream->mappos += offset;
|
||||
break;
|
||||
|
||||
case SEEK_END:
|
||||
if (stream->mapsize + offset < stream->mapsize)
|
||||
goto error;
|
||||
return -1;
|
||||
|
||||
stream->mappos = stream->mapsize + offset;
|
||||
break;
|
||||
@ -275,12 +275,9 @@ int64_t retro_vfs_file_seek_internal(libretro_vfs_implementation_file *stream, i
|
||||
#endif
|
||||
|
||||
if (lseek(stream->fd, offset, whence) < 0)
|
||||
goto error;
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -293,20 +290,25 @@ error:
|
||||
* 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)
|
||||
libretro_vfs_implementation_file *retro_vfs_file_open_impl(
|
||||
const char *path, unsigned mode, unsigned hints)
|
||||
{
|
||||
int flags = 0;
|
||||
const char *mode_str = NULL;
|
||||
libretro_vfs_implementation_file *stream = (libretro_vfs_implementation_file*)calloc(1, sizeof(*stream));
|
||||
libretro_vfs_implementation_file *stream = (libretro_vfs_implementation_file*)
|
||||
calloc(1, sizeof(*stream));
|
||||
|
||||
#ifdef VFS_FRONTEND
|
||||
const char *dumb_prefix = "vfsonly://";
|
||||
int dumb_prefix_len = (int)strlen(dumb_prefix);
|
||||
size_t dumb_prefix_siz = strlen(dumb_prefix);
|
||||
int dumb_prefix_len = (int)dumb_prefix_siz;
|
||||
int path_len = (int)strlen(path);
|
||||
|
||||
if (path_len >= dumb_prefix_len)
|
||||
{
|
||||
if (!memcmp(path, dumb_prefix, dumb_prefix_len))
|
||||
path += strlen(dumb_prefix);
|
||||
path += dumb_prefix_siz;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!stream)
|
||||
@ -524,9 +526,9 @@ int retro_vfs_file_error_impl(libretro_vfs_implementation_file *stream)
|
||||
|
||||
int64_t retro_vfs_file_size_impl(libretro_vfs_implementation_file *stream)
|
||||
{
|
||||
if (!stream)
|
||||
return 0;
|
||||
if (stream)
|
||||
return stream->size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t retro_vfs_file_truncate_impl(libretro_vfs_implementation_file *stream, int64_t length)
|
||||
@ -602,13 +604,12 @@ int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream,
|
||||
void *s, uint64_t len)
|
||||
{
|
||||
if (!stream || !s)
|
||||
goto error;
|
||||
return -1;
|
||||
|
||||
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
||||
{
|
||||
#ifdef ORBIS
|
||||
int64_t ret = orbisRead(stream->fd, s, (size_t)len);
|
||||
if( ret < 0)
|
||||
if (orbisRead(stream->fd, s, (size_t)len) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
#else
|
||||
@ -619,7 +620,7 @@ int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream,
|
||||
if (stream->hints & RETRO_VFS_FILE_ACCESS_HINT_FREQUENT_ACCESS)
|
||||
{
|
||||
if (stream->mappos > stream->mapsize)
|
||||
goto error;
|
||||
return -1;
|
||||
|
||||
if (stream->mappos + len > stream->mapsize)
|
||||
len = stream->mapsize - stream->mappos;
|
||||
@ -632,35 +633,29 @@ int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream,
|
||||
#endif
|
||||
|
||||
return read(stream->fd, s, (size_t)len);
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int64_t retro_vfs_file_write_impl(libretro_vfs_implementation_file *stream, const void *s, uint64_t len)
|
||||
{
|
||||
if (!stream)
|
||||
goto error;
|
||||
return -1;
|
||||
|
||||
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
|
||||
{
|
||||
#ifdef ORBIS
|
||||
int64_t ret = orbisWrite(stream->fd, s, (size_t)len);
|
||||
if( ret < 0)
|
||||
if (orbisWrite(stream->fd, s, (size_t)len) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
#else
|
||||
return fwrite(s, 1, (size_t)len, stream->fp);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
if (stream->hints & RETRO_VFS_FILE_ACCESS_HINT_FREQUENT_ACCESS)
|
||||
goto error;
|
||||
return -1;
|
||||
#endif
|
||||
return write(stream->fd, s, (size_t)len);
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int retro_vfs_file_flush_impl(libretro_vfs_implementation_file *stream)
|
||||
@ -676,15 +671,17 @@ int retro_vfs_file_flush_impl(libretro_vfs_implementation_file *stream)
|
||||
|
||||
int retro_vfs_file_remove_impl(const char *path)
|
||||
{
|
||||
#if defined(_WIN32) && !defined(_XBOX)
|
||||
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500
|
||||
char *path_local = NULL;
|
||||
#else
|
||||
wchar_t *path_wide = NULL;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (!path || !*path)
|
||||
return -1;
|
||||
|
||||
(void)path_local;
|
||||
(void)path_wide;
|
||||
|
||||
#if defined(_WIN32) && !defined(_XBOX)
|
||||
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500
|
||||
path_local = utf8_to_local_string_alloc(path);
|
||||
@ -723,60 +720,53 @@ int retro_vfs_file_remove_impl(const char *path)
|
||||
|
||||
int retro_vfs_file_rename_impl(const char *old_path, const char *new_path)
|
||||
{
|
||||
int ret = -1;
|
||||
#if defined(_WIN32) && !defined(_XBOX)
|
||||
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500
|
||||
char *old_path_local = NULL;
|
||||
char *new_path_local = NULL;
|
||||
#else
|
||||
wchar_t *old_path_wide = NULL;
|
||||
wchar_t *new_path_wide = NULL;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (!old_path || !*old_path || !new_path || !*new_path)
|
||||
return -1;
|
||||
|
||||
(void)old_path_local;
|
||||
(void)new_path_local;
|
||||
(void)old_path_wide;
|
||||
(void)new_path_wide;
|
||||
|
||||
#if defined(_WIN32) && !defined(_XBOX)
|
||||
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500
|
||||
old_path_local = utf8_to_local_string_alloc(old_path);
|
||||
new_path_local = utf8_to_local_string_alloc(new_path);
|
||||
|
||||
if (old_path_local)
|
||||
{
|
||||
char *new_path_local = utf8_to_local_string_alloc(new_path);
|
||||
|
||||
if (new_path_local)
|
||||
{
|
||||
int ret = rename(old_path_local, new_path_local);
|
||||
free(old_path_local);
|
||||
if (rename(old_path_local, new_path_local) == 0)
|
||||
ret = 0;
|
||||
free(new_path_local);
|
||||
return ret==0 ? 0 : -1;
|
||||
}
|
||||
|
||||
free(old_path_local);
|
||||
}
|
||||
|
||||
if (new_path_local)
|
||||
free(new_path_local);
|
||||
#else
|
||||
old_path_wide = utf8_to_utf16_string_alloc(old_path);
|
||||
new_path_wide = utf8_to_utf16_string_alloc(new_path);
|
||||
|
||||
if (old_path_wide)
|
||||
{
|
||||
wchar_t *new_path_wide = utf8_to_utf16_string_alloc(new_path);
|
||||
|
||||
if (new_path_wide)
|
||||
{
|
||||
int ret = _wrename(old_path_wide, new_path_wide);
|
||||
free(old_path_wide);
|
||||
if (_wrename(old_path_wide, new_path_wide) == 0)
|
||||
ret = 0;
|
||||
free(new_path_wide);
|
||||
return ret==0 ? 0 : -1;
|
||||
}
|
||||
|
||||
free(old_path_wide);
|
||||
}
|
||||
|
||||
if (new_path_wide)
|
||||
free(new_path_wide);
|
||||
#endif
|
||||
return -1;
|
||||
return ret;
|
||||
#else
|
||||
#ifdef ORBIS
|
||||
/* stub for now */
|
||||
@ -803,17 +793,16 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
|
||||
#endif
|
||||
#if defined(VITA) || defined(PSP)
|
||||
SceIoStat buf;
|
||||
int stat_ret;
|
||||
char *tmp = strdup(path);
|
||||
size_t len = strlen(tmp);
|
||||
if (tmp[len-1] == '/')
|
||||
tmp[len-1] = '\0';
|
||||
|
||||
if (sceIoGetstat(tmp, &buf) < 0)
|
||||
{
|
||||
stat_ret = sceIoGetstat(tmp, &buf);
|
||||
free(tmp);
|
||||
if (stat_ret < 0)
|
||||
return 0;
|
||||
}
|
||||
free(tmp);
|
||||
#elif defined(PS2)
|
||||
iox_stat_t buf;
|
||||
char *tmp = strdup(path);
|
||||
@ -830,16 +819,15 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
|
||||
#elif defined(_WIN32)
|
||||
DWORD file_info;
|
||||
struct _stat buf;
|
||||
#if defined(LEGACY_WIN32)
|
||||
char *path_local = NULL;
|
||||
#else
|
||||
wchar_t *path_wide = NULL;
|
||||
#endif
|
||||
|
||||
if (!path || !*path)
|
||||
return 0;
|
||||
|
||||
(void)path_wide;
|
||||
(void)path_local;
|
||||
(void)file_info;
|
||||
|
||||
#if defined(LEGACY_WIN32)
|
||||
path_local = utf8_to_local_string_alloc(path);
|
||||
file_info = GetFileAttributes(path_local);
|
||||
@ -995,10 +983,13 @@ static bool dirent_check_error(libretro_vfs_implementation_dir *rdir)
|
||||
libretro_vfs_implementation_dir *retro_vfs_opendir_impl(const char *name, bool include_hidden)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
char path_buf[1024];
|
||||
char *path_local = NULL;
|
||||
wchar_t *path_wide = NULL;
|
||||
unsigned path_len;
|
||||
char path_buf[1024];
|
||||
#if defined(LEGACY_WIN32)
|
||||
char *path_local = NULL;
|
||||
#else
|
||||
wchar_t *path_wide = NULL;
|
||||
#endif
|
||||
#endif
|
||||
libretro_vfs_implementation_dir *rdir;
|
||||
|
||||
@ -1014,9 +1005,6 @@ libretro_vfs_implementation_dir *retro_vfs_opendir_impl(const char *name, bool i
|
||||
rdir->orig_path = strdup(name);
|
||||
|
||||
#if defined(_WIN32)
|
||||
(void)path_wide;
|
||||
(void)path_local;
|
||||
|
||||
path_buf[0] = '\0';
|
||||
path_len = strlen(name);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user