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 */
|
/* Load the content into memory, or copy it over to our own buffer */
|
||||||
if (!CHEEVOS_VAR_DATA)
|
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)
|
if (!CHEEVOS_VAR_STREAM)
|
||||||
CORO_STOP();
|
CORO_STOP();
|
||||||
|
@ -389,14 +389,13 @@ static config_file_t *config_file_new_internal(
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
conf->include_depth = depth;
|
conf->include_depth = depth;
|
||||||
file = filestream_open(path, RFILE_MODE_READ_TEXT, -1);
|
file = filestream_open(path, RFILE_MODE_READ_TEXT, 0x4000);
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
free(conf->path);
|
free(conf->path);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
setvbuf(filestream_get_fp(file), NULL, _IOFBF, 0x4000);
|
|
||||||
|
|
||||||
while (!filestream_eof(file))
|
while (!filestream_eof(file))
|
||||||
{
|
{
|
||||||
@ -917,15 +916,9 @@ bool config_file_write(config_file_t *conf, const char *path)
|
|||||||
|
|
||||||
if (!string_is_empty(path))
|
if (!string_is_empty(path))
|
||||||
{
|
{
|
||||||
file = filestream_open(path, RFILE_MODE_WRITE, -1);
|
file = filestream_open(path, RFILE_MODE_WRITE, 0x4000);
|
||||||
if (!file)
|
if (!file)
|
||||||
return false;
|
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));
|
config_file_dump(conf, filestream_get_fp(file));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -107,6 +107,7 @@ struct RFILE
|
|||||||
#endif
|
#endif
|
||||||
int fd;
|
int fd;
|
||||||
#endif
|
#endif
|
||||||
|
char *buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
FILE* filestream_get_fp(RFILE *stream)
|
FILE* filestream_get_fp(RFILE *stream)
|
||||||
@ -154,6 +155,16 @@ void filestream_set_size(RFILE *stream)
|
|||||||
filestream_seek(stream, 0, SEEK_SET);
|
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)
|
RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
||||||
{
|
{
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
@ -254,6 +265,12 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
|||||||
|
|
||||||
#if defined(PSP)
|
#if defined(PSP)
|
||||||
stream->fd = sceIoOpen(path, flags, mode_int);
|
stream->fd = sceIoOpen(path, flags, mode_int);
|
||||||
|
|
||||||
|
if (stream->fd == -1)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (len >= 0)
|
||||||
|
filestream_set_buffer(stream, len);
|
||||||
#else
|
#else
|
||||||
#if defined(HAVE_BUFFERED_IO)
|
#if defined(HAVE_BUFFERED_IO)
|
||||||
if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0 && mode_str)
|
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
|
#else
|
||||||
stream->fp = fopen(path, mode_str);
|
stream->fp = fopen(path, mode_str);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!stream->fp)
|
if (!stream->fp)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (len >= 0)
|
||||||
|
filestream_set_buffer(stream, len);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
@ -299,8 +320,12 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
|||||||
#else
|
#else
|
||||||
stream->fd = open(path, flags, mode_int);
|
stream->fd = open(path, flags, mode_int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (stream->fd == -1)
|
if (stream->fd == -1)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (len >= 0)
|
||||||
|
filestream_set_buffer(stream, len);
|
||||||
#ifdef HAVE_MMAP
|
#ifdef HAVE_MMAP
|
||||||
if (stream->hints & RFILE_HINT_MMAP)
|
if (stream->hints & RFILE_HINT_MMAP)
|
||||||
{
|
{
|
||||||
@ -323,11 +348,6 @@ RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PSP)
|
|
||||||
if (stream->fd == -1)
|
|
||||||
goto error;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const char *ld = (const char*)strrchr(path, '.');
|
const char *ld = (const char*)strrchr(path, '.');
|
||||||
if (ld)
|
if (ld)
|
||||||
@ -666,6 +686,8 @@ int filestream_close(RFILE *stream)
|
|||||||
if (stream->fd > 0)
|
if (stream->fd > 0)
|
||||||
close(stream->fd);
|
close(stream->fd);
|
||||||
#endif
|
#endif
|
||||||
|
if (stream->buf)
|
||||||
|
free(stream->buf);
|
||||||
free(stream);
|
free(stream);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -186,7 +186,7 @@ static struct rmsgpack_read_callbacks stub_callbacks = {
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
struct stub_state state;
|
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.i = 0;
|
||||||
state.stack[0] = 0;
|
state.stack[0] = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user