Q: How can a file be shortened in-place without completely clearing or rewriting it?
A: BSD systems provide ftruncate, several others supply chsize, and a few may provide a (possibly undocumented) fcntl option F_FREESP. Under MS-DOS, you can sometimes use write(fd, "", 0). However, there is no portable solution, nor a way to delete blocks at the beginning or in the middle. See also question 19.14.