Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!maverick.ksu.ksu.edu!hoss!hoss.unl.edu!ho From: ho@hoss.unl.edu (Tiny Bubbles...) Newsgroups: comp.lang.c Subject: Re: How do I SHORTEN a file without rewriting it? Keywords: truncation Message-ID: <1990Nov04.215129.25491@hoss.unl.edu> Date: 4 Nov 90 21:51:29 GMT References: <1162@bilver.UUCP> <747@csource.oz.au> <9505@jarthur.Claremont.EDU> Sender: news@hoss.unl.edu (Network News Administer) Organization: Daily Nebraskan, University of Nebraska-Lincoln Lines: 20 In <9505@jarthur.Claremont.EDU> dfoster@jarthur.Claremont.EDU (Derek R. Foster) writes: >In article <747@csource.oz.au> david@csource.oz.au (david nugent) writes: >>In <1162@bilver.UUCP> alex@bilver.UUCP (Alex Matulich) writes: >>>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 >>Write zero bytes at that position. > If you are using >streams, you will probably have to close your stream, reopen the file >using handles, chsize() it, close it again, reopen using streams... If I were doing it, I'd just flush the stream, use the fileno() macro to get the handle number, and then either close it or fseek() to the beginning (just to be safe). I often do crappy things like changing file modes, etc. in this manner, and it works fine. Just flush before you access with handles. Again, I'm paranoid. Most of the time, the flush and seek aren't needed. -- ... Michael Ho, University of Nebraska Internet: ho@hoss.unl.edu | "Mine... is the last voice that you will ever hear."