Path: utzoo!attcan!uunet!cs.utexas.edu!sun-barr!olivea!tymix!cirrusl!sunstorm!dhesi From: dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) Newsgroups: comp.lang.c Subject: Re: How do I SHORTEN a file without rewriting it? Keywords: truncation Message-ID: <2652@cirrusl.UUCP> Date: 5 Nov 90 07:13:36 GMT References: <1162@bilver.UUCP> <747@csource.oz.au> <9505@jarthur.Claremont.EDU> Sender: news@cirrusl.UUCP Organization: Cirrus Logic Inc. Lines: 33 In <9505@jarthur.Claremont.EDU> dfoster@jarthur.Claremont.EDU (Derek R. Foster) writes: >>>Is there a way to shorten a file... >>Write zero bytes at that position. >If this works, it isn't documented in the Microsoft C manuals I have. >[chsize()] seems to be the only way of doing this from within >Microsoft C... A write of zero bytes using the MS-DOS "write to file handle" system call will indeed truncate the file at the current seek position. User programs could well contain statements of the sort: count = read(fin, buf, count); if (count != -1) (void) write(fout, buf, count); A zero-byte write could truncate the file connected with fout. If we had seeked to near the beginning of a long file and were trying to overwrite some of the data without losing the rest, truncation would be disastrous. So it's at least an even bet that your C library carefully avoids passing zero-byte writes on to MS-DOS. The chsize() function, on the other hand, most likely simply does a seek followed by zero-byte write. -- Rahul Dhesi UUCP: oliveb!cirrusl!dhesi A pointer is not an address. It is a way of finding an address. -- me