Article View: comp.os.msdos.programmer
Article #1703Re: Truncate a File?
From: Ralf.Brown
Date: Tue, 31 Jul 1990 11:15
Date: Tue, 31 Jul 1990 11:15
33 lines
1777 bytes
1777 bytes
In article <10914@spool.cs.wisc.edu>, rose@galtee.cs.wisc.edu (Barney Frank) wrote:
}I have a requirement to adjust the length of a data file.
}
}4. Ask the operating system to adjust the size of the file down to the new
} "high-water" mark.
}
} It is not sufficient to make a temporary copy of the section of
}interest, unlink the original file, and rename the temporary, because
}the size of the file is of the same order of that of the file system.
}This sounds like a pretty elementary operation to me, but I'll be
}damned if I can find a system call to do anything to the size of a
}file other than just move it down to zero. One can envision some
Ever since DOS 1.00, a WRITE of *zero* bytes has set the file size to the
current file position. So, for example:
mov ax,4200h
mov bx,handle
mov cx,0
mov dx,1234h
int 21h
mov ah,40h
mov bx,handle
xor cx,cx
int 21h
will set the size of the file corresponding to 'handle' to 1234h bytes.
--
UUCP: {ucbvax,harvard}!cs.cmu.edu!ralf -=- 412-268-3053 (school) -=- FAX: ask
ARPA: ralf@cs.cmu.edu BIT: ralf%cs.cmu.edu@CMUCCVMA FIDO: 1:129/3.1
Disclaimer? | I was gratified to be able to answer promptly, and I did.
What's that? | I said I didn't know. --Mark Twain
Technical Details
Message-ID:
<26b56844@ralf>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!pt.cs.cmu.edu!b.gp.cs.cmu.edu!Ralf.Brown@B.GP.CS.CMU.EDUShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!pt.cs.cmu.edu!b.gp.cs.cmu.edu!Ralf.Brown@B.GP.CS.CMU.EDU From: Ralf.Brown@B.GP.CS.CMU.EDU Newsgroups: comp.os.msdos.programmer,comp.lang.c,comp.sources.wanted Subject: Re: Truncate a File? Message-ID: <26b56844@ralf> Date: 31 Jul 90 11:15:16 GMT Sender: ralf@b.gp.cs.cmu.edu Organization: Carnegie Mellon University School of Computer Science Lines: 33 In-Reply-To: <10914@spool.cs.wisc.edu>