(libretro-common) streams - cleanups

This commit is contained in:
twinaphex 2016-04-06 17:03:17 +02:00
parent 734ef07fcc
commit 7fe34b97a6
2 changed files with 22 additions and 22 deletions

View File

@ -434,8 +434,8 @@ int filestream_close(RFILE *stream)
munmap(stream->mapped, stream->mapsize);
#endif
if (stream->fd > 0)
close(stream->fd);
if (stream->fd > 0)
close(stream->fd);
#endif
free(stream);

View File

@ -32,9 +32,9 @@ static size_t last_file_size = 0;
struct memstream
{
uint8_t *m_buf;
size_t m_size;
size_t m_ptr;
uint8_t *buf;
size_t size;
size_t ptr;
};
void memstream_set_buffer(uint8_t *buffer, size_t size)
@ -50,9 +50,9 @@ size_t memstream_get_last_size(void)
static void memstream_init(memstream_t *stream, uint8_t *buffer, size_t max_size)
{
stream->m_buf = buffer;
stream->m_size = max_size;
stream->m_ptr = 0;
stream->buf = buffer;
stream->size = max_size;
stream->ptr = 0;
}
memstream_t *memstream_open(void)
@ -71,29 +71,29 @@ memstream_t *memstream_open(void)
void memstream_close(memstream_t *stream)
{
last_file_size = stream->m_ptr;
last_file_size = stream->ptr;
free(stream);
}
size_t memstream_read(memstream_t *stream, void *data, size_t bytes)
{
size_t avail = stream->m_size - stream->m_ptr;
size_t avail = stream->size - stream->ptr;
if (bytes > avail)
bytes = avail;
memcpy(data, stream->m_buf + stream->m_ptr, bytes);
stream->m_ptr += bytes;
memcpy(data, stream->buf + stream->ptr, bytes);
stream->ptr += bytes;
return bytes;
}
size_t memstream_write(memstream_t *stream, const void *data, size_t bytes)
{
size_t avail = stream->m_size - stream->m_ptr;
size_t avail = stream->size - stream->ptr;
if (bytes > avail)
bytes = avail;
memcpy(stream->m_buf + stream->m_ptr, data, bytes);
stream->m_ptr += bytes;
memcpy(stream->buf + stream->ptr, data, bytes);
stream->ptr += bytes;
return bytes;
}
@ -107,18 +107,18 @@ int memstream_seek(memstream_t *stream, int offset, int whence)
ptr = offset;
break;
case SEEK_CUR:
ptr = stream->m_ptr + offset;
ptr = stream->ptr + offset;
break;
case SEEK_END:
ptr = stream->m_size + offset;
ptr = stream->size + offset;
break;
default:
return -1;
}
if (ptr <= stream->m_size)
if (ptr <= stream->size)
{
stream->m_ptr = ptr;
stream->ptr = ptr;
return 0;
}
return -1;
@ -126,7 +126,7 @@ int memstream_seek(memstream_t *stream, int offset, int whence)
size_t memstream_pos(memstream_t *stream)
{
return stream->m_ptr;
return stream->ptr;
}
char *memstream_gets(memstream_t *stream, char *buffer, size_t len)
@ -136,7 +136,7 @@ char *memstream_gets(memstream_t *stream, char *buffer, size_t len)
int memstream_getc(memstream_t *stream)
{
if (stream->m_ptr >= stream->m_size)
if (stream->ptr >= stream->size)
return EOF;
return stream->m_buf[stream->m_ptr++];
return stream->buf[stream->ptr++];
}