mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-07 02:40:23 +00:00
(libretro-common) streams - cleanups
This commit is contained in:
parent
734ef07fcc
commit
7fe34b97a6
@ -434,8 +434,8 @@ int filestream_close(RFILE *stream)
|
|||||||
munmap(stream->mapped, stream->mapsize);
|
munmap(stream->mapped, stream->mapsize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (stream->fd > 0)
|
if (stream->fd > 0)
|
||||||
close(stream->fd);
|
close(stream->fd);
|
||||||
#endif
|
#endif
|
||||||
free(stream);
|
free(stream);
|
||||||
|
|
||||||
|
@ -32,9 +32,9 @@ static size_t last_file_size = 0;
|
|||||||
|
|
||||||
struct memstream
|
struct memstream
|
||||||
{
|
{
|
||||||
uint8_t *m_buf;
|
uint8_t *buf;
|
||||||
size_t m_size;
|
size_t size;
|
||||||
size_t m_ptr;
|
size_t ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void memstream_set_buffer(uint8_t *buffer, size_t size)
|
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)
|
static void memstream_init(memstream_t *stream, uint8_t *buffer, size_t max_size)
|
||||||
{
|
{
|
||||||
stream->m_buf = buffer;
|
stream->buf = buffer;
|
||||||
stream->m_size = max_size;
|
stream->size = max_size;
|
||||||
stream->m_ptr = 0;
|
stream->ptr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memstream_t *memstream_open(void)
|
memstream_t *memstream_open(void)
|
||||||
@ -71,29 +71,29 @@ memstream_t *memstream_open(void)
|
|||||||
|
|
||||||
void memstream_close(memstream_t *stream)
|
void memstream_close(memstream_t *stream)
|
||||||
{
|
{
|
||||||
last_file_size = stream->m_ptr;
|
last_file_size = stream->ptr;
|
||||||
free(stream);
|
free(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t memstream_read(memstream_t *stream, void *data, size_t bytes)
|
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)
|
if (bytes > avail)
|
||||||
bytes = avail;
|
bytes = avail;
|
||||||
|
|
||||||
memcpy(data, stream->m_buf + stream->m_ptr, bytes);
|
memcpy(data, stream->buf + stream->ptr, bytes);
|
||||||
stream->m_ptr += bytes;
|
stream->ptr += bytes;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t memstream_write(memstream_t *stream, const void *data, size_t 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)
|
if (bytes > avail)
|
||||||
bytes = avail;
|
bytes = avail;
|
||||||
|
|
||||||
memcpy(stream->m_buf + stream->m_ptr, data, bytes);
|
memcpy(stream->buf + stream->ptr, data, bytes);
|
||||||
stream->m_ptr += bytes;
|
stream->ptr += bytes;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,18 +107,18 @@ int memstream_seek(memstream_t *stream, int offset, int whence)
|
|||||||
ptr = offset;
|
ptr = offset;
|
||||||
break;
|
break;
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
ptr = stream->m_ptr + offset;
|
ptr = stream->ptr + offset;
|
||||||
break;
|
break;
|
||||||
case SEEK_END:
|
case SEEK_END:
|
||||||
ptr = stream->m_size + offset;
|
ptr = stream->size + offset;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptr <= stream->m_size)
|
if (ptr <= stream->size)
|
||||||
{
|
{
|
||||||
stream->m_ptr = ptr;
|
stream->ptr = ptr;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@ -126,7 +126,7 @@ int memstream_seek(memstream_t *stream, int offset, int whence)
|
|||||||
|
|
||||||
size_t memstream_pos(memstream_t *stream)
|
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)
|
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)
|
int memstream_getc(memstream_t *stream)
|
||||||
{
|
{
|
||||||
if (stream->m_ptr >= stream->m_size)
|
if (stream->ptr >= stream->size)
|
||||||
return EOF;
|
return EOF;
|
||||||
return stream->m_buf[stream->m_ptr++];
|
return stream->buf[stream->ptr++];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user