[comp.sys.ibm.pc] Truncating DOS files

bill@hpcvlo.UUCP (02/18/87)

Okay, you folks who can't seem to find any documentation about truncating
DOS files, I just looked through both of my DOS reference manuals
(an old 2.11 reference from Microsoft, and a 3.2 manual from IBM), and
BOTH of them spell out quite plainly the fact that calling Int 21h
Function 40H with CX=0 will truncate a file:

	********************

	"Disk Operating System Technical Reference"
	(for DOS versions 2.10, 3.00, 3.10 and 3.20)
	First Edition (February 1985)
	Copyright IBM 1985, 1986
	Part No. 6138536

	"DOS Interrupts and Function Calls" chapter, page 6-129:

								40H
					  Write to a File or Device

		To truncate a file at the current position of the file
		pointer, set the number of bytes (CX) to zero before
		issuing the interrupt 21H.  The file pointer can be
		moved to the desired position by reading, writing,
		and performing function call 42H (Move File
		Read/Write Pointer)."

		...

	********************

	"Microsoft MS-DOS Operating System Programmer's Reference Manual"
	(for DOS version 2.0)
	Copyright Microsoft Corp. 1981, 1983
	Document No. 8411-200-00
	Part No. 14F36PM

	SYSTEM CALLS chapter, page 1-117:

		Write to a File or Device (Function 40H)

		...

		The write system call with a count of zero (CX = 0) will set
		the file size to the current position.  Allocation units are
		allocated or released as required.

		...

	********************

Do I have the only two pieces of documentation in existance that mention
this fact, or is everybody else just looking in the wrong places?


Bill Frolik
hp-pcd!bill
Hewlett-Packard Portable Computer Division
Corvallis, Oregon

kfk9673@ritcv.UUCP (02/21/87)

Are you sure you're talking about INT 21H function 40 (28H)??

I have the Programmer's guide to the IBM PC and it says that function 28H
will truncate if CX is 0.

bill@hpcvlo.UUCP (02/23/87)

Yup, I said "function 40h".  I just checked again, and my 3.2 DOS tech ref
says CX=0 will truncate the file for BOTH functions 40h (Write To File or
Device) and function 28h (Random Block Write).

Aside: is it coincidental that the two file-write functions are numbered
28h and 40h?  (28 hex = 40 dec).

Bill Frolik
hp-pcd!bill
Hewlett-Packard Portable Computer Division
Corvallis, Oregon

dick@zaphod.UUCP (02/24/87)

In [many] article[s] ... [everybody] writes:
>
>Okay, you folks who can't seem to find any documentation about truncating
>DOS files, I just looked through both of my DOS reference manuals [...]


E N O U G H   A L R E A D Y ! ! ! !

We get the idea:  the documentation is apparently everywhere and 
intuitively obvious to the most casual reader of anything!  Can we
please get on with the net now?

-- 
Dick Flanagan, W6OLD
...!ucbvax!decwrl!sun!plx!dick
(The usual disclaimers apply)

campbell@maynard.UUCP (02/27/87)

In article <1610007@hpcvlo.HP.COM> bill@hpcvlo.HP.COM (Bill Frolik) writes:
>
>Aside: is it coincidental that the two file-write functions are numbered
>28h and 40h?  (28 hex = 40 dec).

Reminds me of a trick question, which was also a bad joke, I got on an exam
once:

Q.  Prove:  Halloween = Christmas.



A.  31 OCT = 25 DEC

-- 
Larry Campbell                                The Boston Software Works, Inc.
Internet: campbell@maynard.uucp             120 Fulton Street, Boston MA 02109
uucp: {alliant,wjh12}!maynard!campbell              +1 617 367 6846
ARPA: campbell%maynard.uucp@harvisr.harvard.edu      MCI: LCAMPBELL