Path: utzoo!attcan!uunet!timbuk!cs.umn.edu!ub.d.umn.edu!rutgers!rochester!cornell!uw-beaver!zephyr.ens.tek.com!videovax!dougs From: dougs@videovax.tv.tek.com (Doug Stevens) Newsgroups: comp.lang.c Subject: Re: How do I SHORTEN a file without rewriting it? Summary: Use chsize() or write 0 bytes. Keywords: truncation Message-ID: <6126@videovax.tv.tek.com> Date: 5 Nov 90 17:52:16 GMT References: <1162@bilver.UUCP> <747@csource.oz.au> <9505@jarthur.Claremont.EDU> Organization: Tektronix TV Measurement Systems, Beaverton OR Lines: 16 > In <1162@bilver.UUCP> alex@bilver.UUCP (Alex Matulich) writes: > Is there a way to shorten a file ... ? Turbo-C does indeed include chsize() in the library. Examining their implementation, they use exactly the same trick, ie, a seek to the desired point of truncation, and then a write of 0 bytes. Look at page 1308 of the MS-DOS Encyclopedia (under Interrupt 21H, Function 40H, 'Write File or Device'): 'If CX=0, the file is truncated or extended to the current file pointer location'. (CX is the number of bytes to write).