diff --git a/libretro-common/streams/file_stream.c b/libretro-common/streams/file_stream.c index 9a0643063c..956f91b037 100644 --- a/libretro-common/streams/file_stream.c +++ b/libretro-common/streams/file_stream.c @@ -330,9 +330,26 @@ error: char *filestream_gets(RFILE *stream, char *s, size_t len) { + int c = 0; + char *p = NULL; if (!stream) return NULL; - return fgets(s, (int)len, stream->fp); + + /* get max bytes or up to a newline */ + + for (p = s, len--; len > 0; len--) + { + if ((c = filestream_getc(stream)) == EOF) + break; + *p++ = c; + if (c == '\n') + break; + } + *p = 0; + + if (p == s || c == EOF) + return NULL; + return (p); } int filestream_getc(RFILE *stream)