From 42f066a842a1d0b907d22c4b6ad9e2999989c641 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Tue, 18 Jun 2024 09:14:41 -0700 Subject: [PATCH] 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). --- .../include/streams/interface_stream.h | 3 ++ libretro-common/streams/interface_stream.c | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/libretro-common/include/streams/interface_stream.h b/libretro-common/include/streams/interface_stream.h index b62552f219d9..497025933571 100644 --- a/libretro-common/include/streams/interface_stream.h +++ b/libretro-common/include/streams/interface_stream.h @@ -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); diff --git a/libretro-common/streams/interface_stream.c b/libretro-common/streams/interface_stream.c index 5f65c491aa62..ea9b00f17483 100644 --- a/libretro-common/streams/interface_stream.c +++ b/libretro-common/streams/interface_stream.c @@ -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)