mirror of
https://github.com/libretro/RetroArch
synced 2025-04-16 08:43:10 +00:00
Make this thing more like stdio
This commit is contained in:
parent
e6462de5be
commit
353b2ebff6
@ -51,6 +51,7 @@ struct RFILE
|
|||||||
{
|
{
|
||||||
struct retro_vfs_file_handle *hfile;
|
struct retro_vfs_file_handle *hfile;
|
||||||
bool error_flag;
|
bool error_flag;
|
||||||
|
bool eof_flag;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* VFS Initialization */
|
/* VFS Initialization */
|
||||||
@ -150,6 +151,7 @@ RFILE *filestream_open(const char *path, unsigned mode, unsigned hints)
|
|||||||
|
|
||||||
output = (RFILE*)malloc(sizeof(RFILE));
|
output = (RFILE*)malloc(sizeof(RFILE));
|
||||||
output->error_flag = false;
|
output->error_flag = false;
|
||||||
|
output->eof_flag = false;
|
||||||
output->hfile = fp;
|
output->hfile = fp;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -199,18 +201,14 @@ ssize_t filestream_seek(RFILE *stream, ssize_t offset, int seek_position)
|
|||||||
|
|
||||||
if (output == vfs_error_return_value)
|
if (output == vfs_error_return_value)
|
||||||
stream->error_flag = true;
|
stream->error_flag = true;
|
||||||
|
stream->eof_flag = false;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
int filestream_eof(RFILE *stream)
|
int filestream_eof(RFILE *stream)
|
||||||
{
|
{
|
||||||
int64_t current_position = filestream_tell(stream);
|
return stream->eof_flag;
|
||||||
int64_t end_position = filestream_get_size(stream);
|
|
||||||
|
|
||||||
if (current_position >= end_position)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -235,6 +233,7 @@ void filestream_rewind(RFILE *stream)
|
|||||||
return;
|
return;
|
||||||
filestream_seek(stream, 0L, RETRO_VFS_SEEK_POSITION_START);
|
filestream_seek(stream, 0L, RETRO_VFS_SEEK_POSITION_START);
|
||||||
stream->error_flag = false;
|
stream->error_flag = false;
|
||||||
|
stream->eof_flag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t filestream_read(RFILE *stream, void *s, int64_t len)
|
ssize_t filestream_read(RFILE *stream, void *s, int64_t len)
|
||||||
@ -249,6 +248,8 @@ ssize_t filestream_read(RFILE *stream, void *s, int64_t len)
|
|||||||
|
|
||||||
if (output == vfs_error_return_value)
|
if (output == vfs_error_return_value)
|
||||||
stream->error_flag = true;
|
stream->error_flag = true;
|
||||||
|
if (output < len)
|
||||||
|
stream->eof_flag = true;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -312,7 +313,7 @@ int filestream_putc(RFILE *stream, int c)
|
|||||||
char c_char = (char)c;
|
char c_char = (char)c;
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return EOF;
|
return EOF;
|
||||||
return filestream_write(stream, &c_char, 1);
|
return filestream_write(stream, &c_char, 1)==1 ? c : EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
int filestream_vprintf(RFILE *stream, const char* format, va_list args)
|
int filestream_vprintf(RFILE *stream, const char* format, va_list args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user