Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!netnews.upenn.edu!msuinfo!convex.cl.msu.edu!jap From: jap@convex.cl.msu.edu (Joe Porkka) Newsgroups: comp.lang.c Subject: Re: How do you truncate a file? Message-ID: <1991May13.145521.8370@msuinfo.cl.msu.edu> Date: 13 May 91 14:55:21 GMT References: <1991May6.194614.9641@pensoft.uucp> <792@uswnvg.UUCP> <1991May9.130725.1@dev8j.mdcbbs.com> <1991May12.155309.7279@rushpc> Sender: news@msuinfo.cl.msu.edu Distribution: usa Organization: Michigan State University Lines: 19 Followup: dev.null jjr@rushpc (John J. Rushford Jr) writes: >In article <1991May9.130725.1@dev8j.mdcbbs.com> campbell@dev8j.mdcbbs.com (Tim Campbell) writes: >>In article <792@uswnvg.UUCP>, dfpedro@uswnvg.UUCP (Donn Pedro) writes: >>> In article <1991May6.194614.9641@pensoft.uucp>, lwb@pensoft.uucp (Lance Bledsoe) writes: >>IF you have DOS and want this to run real fast on any file of any size and >>want it to truncate the file in place (not making a copy), then you could >> >>I just don't know unix well enough to know a clever way to handle this >>situation without actually copying the file. >> >In Unix the above method would wreak havoc with the filesystem if you >could use it. You would have to update the freelist and inode entry >in the superblock or run fsck -y to fix the filesystem. This would >prove to be difficult unless you're 'root'. It would not be a problem on UNIX, or any REAL os ( !msdos). Simply call "ftruncate()" and let the filesystem do its business.