### Question 19.13

How can a file be shortened in-place without completely clearing or rewriting it?

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. See also question 19.14.

Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995 // mail feedback