VFS cleanup + libretro-common update

This commit is contained in:
sonninnos 2021-12-28 01:06:58 +02:00 committed by Tony
parent 7d27232fed
commit 20ae21356b
6 changed files with 73 additions and 18 deletions

View File

@ -383,10 +383,18 @@ else
endif
# 7zip
COMMONFLAGS += -DHAVE_7ZIP -D_7ZIP_ST
ifneq ($(NO_7ZIP), 1)
COMMONFLAGS += -DHAVE_7ZIP -D_7ZIP_ST
endif
COMMONFLAGS += -DHAVE_CONFIG_H -D__LIBRETRO__ -DUSE_LIBRETRO_VFS -DCORE_NAME=\"$(EMUTYPE)\"
COMMONFLAGS += -DHAVE_CONFIG_H -D__LIBRETRO__
# VFS
ifneq ($(NO_LIBRETRO_VFS), 1)
COMMONFLAGS += -DUSE_LIBRETRO_VFS
endif
COMMONFLAGS += -DCORE_NAME=\"$(EMUTYPE)\"
include Makefile.common
$(info CFLAGS: $(CFLAGS) $(COMMONFLAGS))

View File

@ -28,9 +28,6 @@
#define ftello rftell
#endif /* USE_LIBRETRO_VFS */
#undef tmpnam
#define tmpnam(string) 0
#endif /* __cplusplus */
#endif /* _SYSCONFIG_H */

View File

@ -81,6 +81,8 @@ char* filestream_gets(RFILE *stream, char *s, size_t len);
int filestream_getc(RFILE *stream);
int filestream_vscanf(RFILE *stream, const char* format, va_list *args);
int filestream_scanf(RFILE *stream, const char* format, ...);
int filestream_eof(RFILE *stream);

View File

@ -221,11 +221,11 @@ int filestream_getc(RFILE *stream)
return EOF;
}
int filestream_scanf(RFILE *stream, const char* format, ...)
int filestream_vscanf(RFILE *stream, const char* format, va_list *args)
{
char buf[4096];
char subfmt[64];
va_list args;
va_list args_copy;
const char * bufiter = buf;
int ret = 0;
int64_t startpos = filestream_tell(stream);
@ -236,7 +236,16 @@ int filestream_scanf(RFILE *stream, const char* format, ...)
buf[maxlen] = '\0';
va_start(args, format);
/* Have to copy the input va_list here
* > Calling va_arg() on 'args' directly would
* cause the va_list to have an indeterminate value
* in the function calling filestream_vscanf(),
* leading to unexpected behaviour */
#ifdef __va_copy
__va_copy(args_copy, *args);
#else
va_copy(args_copy, *args);
#endif
while (*format)
{
@ -302,7 +311,7 @@ int filestream_scanf(RFILE *stream, const char* format, ...)
}
else
{
int v = sscanf(bufiter, subfmt, va_arg(args, void*), &sublen);
int v = sscanf(bufiter, subfmt, va_arg(args_copy, void*), &sublen);
if (v == EOF)
return EOF;
if (v != 1)
@ -327,13 +336,23 @@ int filestream_scanf(RFILE *stream, const char* format, ...)
}
}
va_end(args);
va_end(args_copy);
filestream_seek(stream, startpos+(bufiter-buf),
RETRO_VFS_SEEK_POSITION_START);
return ret;
}
int filestream_scanf(RFILE *stream, const char* format, ...)
{
int result;
va_list vl;
va_start(vl, format);
result = filestream_vscanf(stream, format, &vl);
va_end(vl);
return result;
}
int64_t filestream_seek(RFILE *stream, int64_t offset, int seek_position)
{
int64_t output;

View File

@ -78,7 +78,7 @@ int rfclose(RFILE* stream)
int64_t rftell(RFILE* stream)
{
if (!stream)
return EOF;
return -1;
return filestream_tell(stream);
}
@ -86,6 +86,10 @@ int64_t rftell(RFILE* stream)
int64_t rfseek(RFILE* stream, int64_t offset, int origin)
{
int seek_position = -1;
if (!stream)
return -1;
switch (origin)
{
case SEEK_SET:
@ -99,48 +103,67 @@ int64_t rfseek(RFILE* stream, int64_t offset, int origin)
break;
}
if (!stream)
return EOF;
return filestream_seek(stream, offset, seek_position);
}
int64_t rfread(void* buffer,
size_t elem_size, size_t elem_count, RFILE* stream)
{
if (!stream || (elem_size == 0) || (elem_count == 0))
return 0;
return (filestream_read(stream, buffer, elem_size * elem_count) / elem_size);
}
char *rfgets(char *buffer, int maxCount, RFILE* stream)
{
if (!stream)
return NULL;
return filestream_gets(stream, buffer, maxCount);
}
int rfgetc(RFILE* stream)
{
if (!stream)
return EOF;
return filestream_getc(stream);
}
int64_t rfwrite(void const* buffer,
size_t elem_size, size_t elem_count, RFILE* stream)
{
if (!stream || (elem_size == 0) || (elem_count == 0))
return 0;
return (filestream_write(stream, buffer, elem_size * elem_count) / elem_size);
}
int rfputc(int character, RFILE * stream)
{
return filestream_putc(stream, character);
if (!stream)
return EOF;
return filestream_putc(stream, character);
}
int64_t rfflush(RFILE * stream)
{
return filestream_flush(stream);
if (!stream)
return EOF;
return filestream_flush(stream);
}
int rfprintf(RFILE * stream, const char * format, ...)
{
int result;
va_list vl;
if (!stream)
return -1;
va_start(vl, format);
result = filestream_vprintf(stream, format, vl);
va_end(vl);
@ -161,8 +184,12 @@ int rfscanf(RFILE * stream, const char * format, ...)
{
int result;
va_list vl;
if (!stream)
return 0;
va_start(vl, format);
result = filestream_scanf(stream, format, vl);
result = filestream_vscanf(stream, format, &vl);
va_end(vl);
return result;
}

View File

@ -507,6 +507,8 @@ char *archdep_tmpnam(void)
lib_free(tmpName);
return lib_strdup(tmpName);
#elif __LIBRETRO__
return NULL;
#else
return lib_strdup(tmpnam(NULL));
#endif
@ -553,7 +555,7 @@ FILE *archdep_mkstemp_fd(char **filename, const char *mode)
char *tmp;
FILE *fd;
tmp = tmpnam(NULL);
tmp = archdep_tmpnam();
if (tmp == NULL)
return NULL;