VFS: Allow truncating memory chunk VFiles
Jeffrey Pfau jeffrey@endrift.com
Fri, 21 Oct 2016 23:18:18 -0700
2 files changed,
7 insertions(+),
6 deletions(-)
M
src/util/vfs/vfs-mem.c
→
src/util/vfs/vfs-mem.c
@@ -116,7 +116,11 @@ void _vfmExpand(struct VFileMem* vfm, size_t newSize) {
void* oldBuf = vfm->mem; vfm->mem = anonymousMemoryMap(newSize); if (oldBuf) { - memcpy(vfm->mem, oldBuf, vfm->size); + 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 _vfmTruncate(struct VFile* vf, size_t size) { struct VFileMem* vfm = (struct VFileMem*) vf; - if (size > vfm->size) { - _vfmExpand(vfm, size); - } else { - // TODO - } + _vfmExpand(vfm, size); } void _vfmTruncateNoop(struct VFile* vf, size_t size) {