How do I SHORTEN a file without rewriting it?

Doug Stevens dougs at videovax.tv.tek.com
Tue Nov 6 04:52:16 AEST 1990


> In <1162 at bilver.UUCP> alex at 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).

	



More information about the Comp.lang.c mailing list