VFS: Allow truncating memory chunk VFiles

This commit is contained in:
Jeffrey Pfau 2016-10-21 23:18:18 -07:00
parent d0f404a6ba
commit 287ab91739
2 changed files with 7 additions and 6 deletions

View File

@ -26,6 +26,7 @@ Misc:
- GBA Video, GB Video: Colors are now fully scaled
- PSP2: Improved controller rumble
- GB, GBA: Prevent loading null ROMs
- VFS: Allow truncating memory chunk VFiles
0.5.1: (2016-10-05)
Bugfixes:

View File

@ -116,7 +116,11 @@ void _vfmExpand(struct VFileMem* vfm, size_t newSize) {
void* oldBuf = vfm->mem;
vfm->mem = anonymousMemoryMap(newSize);
if (oldBuf) {
if (newSize < vfm->size) {
memcpy(vfm->mem, oldBuf, newSize);
} else {
memcpy(vfm->mem, oldBuf, vfm->size);
}
mappedMemoryFree(oldBuf, vfm->size);
}
vfm->size = newSize;
@ -270,11 +274,7 @@ void _vfmUnmap(struct VFile* vf, void* memory, size_t size) {
void _vfmTruncate(struct VFile* vf, size_t size) {
struct VFileMem* vfm = (struct VFileMem*) vf;
if (size > vfm->size) {
_vfmExpand(vfm, size);
} else {
// TODO
}
}
void _vfmTruncateNoop(struct VFile* vf, size_t size) {