Skip to content

Commit

Permalink
add intfstream_truncate for file streams
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
JoeOsborn authored and LibretroAdmin committed Jun 18, 2024
1 parent ab9ee96 commit 42f066a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libretro-common/include/streams/interface_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions libretro-common/streams/interface_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 42f066a

Please sign in to comment.