How do I SHORTEN a file without rewriting it?

Alex Matulich alex at bilver.UUCP
Tue Oct 23 10:25:26 AEST 1990


I have a very large file which was made by writing a bunch of data
structures out to disk.  When I wish to delete a structure from this
data file, I simply read all the structures following the one to be deleted
and write them out one record-length forward, one at a time.  I use the
fseek(), fread(), and fwrite() functions for this.

This process does the job, but it leaves an unused record at the end of
the file, and of course the file length remains unchanged.

Is there a way to shorten a file, that is, chop some data off the end of
it, so that it doesn't consume as much physical space on the disk?  The
file I have is too big to read into memory and write back out again, and
there is not enough room on the disk to write out a temporary file.

You can email any help you want, but I'll be looking in this newsgroup
for answers also.  Thanks...

-- 
 _ |__  Alex Matulich   (alex at bilver.UUCP)
 /(+__>  Unicorn Research Corp, 4621 N Landmark Dr, Orlando, FL 32817
//| \     UUCP:  ...uunet!tarpit!bilver!alex
///__)     bitnet:  IN%"bilver!alex at uunet.uu.net"



More information about the Comp.lang.c mailing list