Article View: comp.os.msdos.programmer
Article #2776Re: How do I SHORTEN a file without rewriting it?
From: John R. Levine
Date: Wed, 24 Oct 1990 15:23
Date: Wed, 24 Oct 1990 15:23
22 lines
1618 bytes
1618 bytes
In article <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?
It is a poorly documented but reliable feature of MS-DOS systems that a
zero length write truncates a file. That is, you seek to where you want
the EOF to be, then do a write(fd, "", 0) or the equivalent.
Note that if you're using a stdio library (fopen et al.) you almost certainly
cannot do this with fwrite. Also, if your stdio is doing lf to cr/lf
translation, you may need to turn that off as well.
Also note that this hack is extremely unportable. Unix systems, for
example, have a variety of ways of truncating files (ftruncate, fcntl, etc.)
none of which involve a zero-length write.
Regards,
John Levine, johnl@esegue.segue.boston.ma.us, {spdcc|ima|world}!esegue!johnl
--
John R. Levine, IECC, POB 349, Cambridge MA 02238, +1 617 864 9650
johnl@esegue.segue.boston.ma.us, {ima|spdcc|world}!esegue!johnl
Atlantic City gamblers lose $8200 per minute. -NY Times
Technical Details
Message-ID:
<1990Oct24.152300.12847@esegue.segue.boston.ma.us>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!ogicse!mintaka!spdcc!esegue!johnlReferences:
<1162@bilver.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ogicse!mintaka!spdcc!esegue!johnl From: johnl@esegue.segue.boston.ma.us (John R. Levine) Newsgroups: comp.os.msdos.programmer Subject: Re: How do I SHORTEN a file without rewriting it? Summary: zero length write Keywords: truncation Message-ID: <1990Oct24.152300.12847@esegue.segue.boston.ma.us> Date: 24 Oct 90 15:23:00 GMT References: <1162@bilver.UUCP> Reply-To: johnl@esegue.segue.boston.ma.us (John R. Levine) Organization: I.E.C.C., Cambridge MA 02238 Lines: 22