add intfstream_truncate for file streams

Will return 0 for non-file streams.  I didn't want to mess around with
memory_stream (which could in theory have a truncate impl that sets
size) because there were globals and stuff and I got nervous (also
truncate might *grow* a file if the new length is longer than the old
one and then I'd have to think about realloc, etc).
This commit is contained in:
Joseph C. Osborn 2024-06-18 09:14:41 -07:00 committed by LibretroAdmin
parent ab9ee963cb
commit 42f066a842
2 changed files with 31 additions and 0 deletions

View File

@ -88,6 +88,9 @@ int intfstream_getc(intfstream_internal_t *intf);
int64_t intfstream_seek(intfstream_internal_t *intf,
int64_t offset, int whence);
int64_t intfstream_truncate(intfstream_internal_t *intf,
uint64_t len);
void intfstream_rewind(intfstream_internal_t *intf);
int64_t intfstream_tell(intfstream_internal_t *intf);

View File

@ -309,6 +309,34 @@ int64_t intfstream_seek(
return -1;
}
int64_t intfstream_truncate(intfstream_internal_t *intf, uint64_t len)
{
if (!intf)
return 0;
switch (intf->type)
{
case INTFSTREAM_FILE:
return filestream_truncate(intf->file.fp, len);
case INTFSTREAM_MEMORY:
break;
case INTFSTREAM_CHD:
#ifdef HAVE_CHD
break;
#else
break;
#endif
case INTFSTREAM_RZIP:
#if defined(HAVE_ZLIB)
break;
#else
break;
#endif
}
return 0;
}
int64_t intfstream_read(intfstream_internal_t *intf, void *s, uint64_t len)
{
if (!intf)