diff --git a/Makefile b/Makefile index e55049a2f8..bb69ce4ada 100644 --- a/Makefile +++ b/Makefile @@ -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)) diff --git a/include/sysconfig.h b/include/sysconfig.h index ef972d5b6e..a47dc1cb7c 100644 --- a/include/sysconfig.h +++ b/include/sysconfig.h @@ -28,9 +28,6 @@ #define ftello rftell #endif /* USE_LIBRETRO_VFS */ -#undef tmpnam -#define tmpnam(string) 0 - #endif /* __cplusplus */ #endif /* _SYSCONFIG_H */ diff --git a/libretro-common/include/streams/file_stream.h b/libretro-common/include/streams/file_stream.h index ab198b28eb..5276f87a2d 100755 --- a/libretro-common/include/streams/file_stream.h +++ b/libretro-common/include/streams/file_stream.h @@ -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); diff --git a/libretro-common/streams/file_stream.c b/libretro-common/streams/file_stream.c index c43423771c..2ac5dbb83f 100755 --- a/libretro-common/streams/file_stream.c +++ b/libretro-common/streams/file_stream.c @@ -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; diff --git a/libretro-common/streams/file_stream_transforms.c b/libretro-common/streams/file_stream_transforms.c index 259847ed91..e94a3112ae 100755 --- a/libretro-common/streams/file_stream_transforms.c +++ b/libretro-common/streams/file_stream_transforms.c @@ -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; } diff --git a/retrodep/archdep.c b/retrodep/archdep.c index 96b7ef0a13..d363361e25 100644 --- a/retrodep/archdep.c +++ b/retrodep/archdep.c @@ -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;