Truncate a File?

Ralf.Brown at B.GP.CS.CMU.EDU Ralf.Brown at B.GP.CS.CMU.EDU
Tue Jul 31 21:15:16 AEST 1990


In article <10914 at spool.cs.wisc.edu>, rose at 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 at cs.cmu.edu  BIT: ralf%cs.cmu.edu at 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



More information about the Comp.lang.c mailing list