mirror of
https://github.com/libretro/RetroArch
synced 2025-03-04 16:13:50 +00:00
Merge pull request #5689 from bparker06/setvbuf
follow rules for setvbuf()
This commit is contained in:
commit
a9c0297931
@ -2605,7 +2605,7 @@ static int cheevos_iterate(coro_t* coro)
|
||||
/* Load the content into memory, or copy it over to our own buffer */
|
||||
if (!CHEEVOS_VAR_DATA)
|
||||
{
|
||||
CHEEVOS_VAR_STREAM = filestream_open(CHEEVOS_VAR_PATH, RFILE_MODE_READ, 0);
|
||||
CHEEVOS_VAR_STREAM = filestream_open(CHEEVOS_VAR_PATH, RFILE_MODE_READ, -1);
|
||||
|
||||
if (!CHEEVOS_VAR_STREAM)
|
||||
CORO_STOP();
|
||||
|
@ -389,14 +389,13 @@ static config_file_t *config_file_new_internal(
|
||||
goto error;
|
||||
|
||||
conf->include_depth = depth;
|
||||
file = filestream_open(path, RFILE_MODE_READ_TEXT, -1);
|
||||
file = filestream_open(path, RFILE_MODE_READ_TEXT, 0x4000);
|
||||
|
||||
if (!file)
|
||||
{
|
||||
free(conf->path);
|
||||
goto error;
|
||||
}
|
||||
setvbuf(filestream_get_fp(file), NULL, _IOFBF, 0x4000);
|
||||
|
||||
while (!filestream_eof(file))
|
||||
{
|
||||
@ -917,15 +916,9 @@ bool config_file_write(config_file_t *conf, const char *path)
|
||||
|
||||
if (!string_is_empty(path))
|
||||
{
|
||||
file = filestream_open(path, RFILE_MODE_WRITE, -1);
|
||||
file = filestream_open(path, RFILE_MODE_WRITE, 0x4000);
|
||||
if (!file)
|
||||
return false;
|
||||
#ifdef WIIU
|
||||
/* TODO: use FBF everywhere once https://i.imgur.com/muVhNeF.jpg is fixed */
|
||||
setvbuf(filestream_get_fp(file), NULL, _IONBF, 0x4000);
|
||||
#else
|
||||
setvbuf(filestream_get_fp(file), NULL, _IOFBF, 0x4000);
|
||||
#endif
|
||||
config_file_dump(conf, filestream_get_fp(file));
|
||||
}
|
||||
else
|
||||
|
@ -107,6 +107,7 @@ struct RFILE
|
||||
#endif
|
||||
int fd;
|
||||
#endif
|
||||
char *buf;
|
||||
};
|
||||
|
||||
FILE* filestream_get_fp(RFILE *stream)
|
||||
@ -154,6 +155,16 @@ void filestream_set_size(RFILE *stream)
|
||||
filestream_seek(stream, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
static void filestream_set_buffer(RFILE *stream, ssize_t len)
|
||||
{
|
||||
if (!stream || !stream->fp)
|
||||
return;
|
||||
|
||||
stream->buf = (char*)calloc(1, len);
|
||||
|
||||
setvbuf(stream->fp, stream->buf, _IOFBF, len);
|
||||
}
|
||||
|
||||
RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
||||
{
|
||||
int flags = 0;
|
||||
@ -254,6 +265,12 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
||||
|
||||
#if defined(PSP)
|
||||
stream->fd = sceIoOpen(path, flags, mode_int);
|
||||
|
||||
if (stream->fd == -1)
|
||||
goto error;
|
||||
|
||||
if (len >= 0)
|
||||
filestream_set_buffer(stream, len);
|
||||
#else
|
||||
#if defined(HAVE_BUFFERED_IO)
|
||||
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0 && mode_str)
|
||||
@ -275,8 +292,12 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
||||
#else
|
||||
stream->fp = fopen(path, mode_str);
|
||||
#endif
|
||||
|
||||
if (!stream->fp)
|
||||
goto error;
|
||||
|
||||
if (len >= 0)
|
||||
filestream_set_buffer(stream, len);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -299,8 +320,12 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
||||
#else
|
||||
stream->fd = open(path, flags, mode_int);
|
||||
#endif
|
||||
|
||||
if (stream->fd == -1)
|
||||
goto error;
|
||||
|
||||
if (len >= 0)
|
||||
filestream_set_buffer(stream, len);
|
||||
#ifdef HAVE_MMAP
|
||||
if (stream->hints & RFILE_HINT_MMAP)
|
||||
{
|
||||
@ -323,11 +348,6 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PSP)
|
||||
if (stream->fd == -1)
|
||||
goto error;
|
||||
#endif
|
||||
|
||||
{
|
||||
const char *ld = (const char*)strrchr(path, '.');
|
||||
if (ld)
|
||||
@ -666,6 +686,8 @@ int filestream_close(RFILE *stream)
|
||||
if (stream->fd > 0)
|
||||
close(stream->fd);
|
||||
#endif
|
||||
if (stream->buf)
|
||||
free(stream->buf);
|
||||
free(stream);
|
||||
|
||||
return 0;
|
||||
|
@ -186,7 +186,7 @@ static struct rmsgpack_read_callbacks stub_callbacks = {
|
||||
int main(void)
|
||||
{
|
||||
struct stub_state state;
|
||||
RFILE *fd = filestream_open("test.msgpack", RFILE_MODE_READ, 0);
|
||||
RFILE *fd = filestream_open("test.msgpack", RFILE_MODE_READ, -1);
|
||||
|
||||
state.i = 0;
|
||||
state.stack[0] = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user