How do you truncate a file?
Joe Porkka
jap at convex.cl.msu.edu
Tue May 14 00:55:21 AEST 1991
jjr at rushpc (John J. Rushford Jr) writes:
>In article <1991May9.130725.1 at dev8j.mdcbbs.com> campbell at dev8j.mdcbbs.com (Tim Campbell) writes:
>>In article <792 at uswnvg.UUCP>, dfpedro at uswnvg.UUCP (Donn Pedro) writes:
>>> In article <1991May6.194614.9641 at pensoft.uucp>, lwb at 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.
More information about the Comp.lang.c
mailing list