Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hpcvlx!bill
From: bill@hpcvlx.cv.hp.com (Bill Frolik)
Newsgroups: comp.sys.ibm.pc
Subject: Re: Test MS-DOS file truncate, worry with 'lds si,[bp].n'
Message-ID: <101000071@hpcvlx.cv.hp.com>
Date: 2 Oct 89 18:24:54 GMT
References: <17086@rpp386.cactus.org>
Organization: Hewlett-Packard Co., Corvallis, OR, USA
Lines: 55


| Two threads of thought are explored and affirmatively answered ...
|  1)  Can I truncate an existing file to an arbitrary length?
| ...
|;	Verify a method of truncating a file in MS-DOS.
|;	September 19, 1989.  For use with Lilith emulator.
|;	Modify or comment upon freely.  Leave my credits.
|;
|;	MD-DOS functions:
|;	dos	3d02, 
|;	dos	4200, 
|;	dos	4000, 
|;	dos	4000, 
|;	dos	4500, 
|;	dos	3e00, 
|;	dos	3f00, 
|;
|;       I had needed a way to 'clip' a file at some point, so ...
| ...
| Aubrey McIntosh                  Freelance using Modula-2

All you need to do to truncate an existing file is:

	3D02h - open the file
	4200h - move file pointer
	40h   - write to file, length=0
	3Eh   - close file (or let 4Ch do this for you)

I don't know how many times I've seen this discussion on the net,
which is pretty amazing to me because the method for truncating files
IS DOCUMENTED in the DOS Tech Ref Manual (which people apparently either 
don't have or don't read).

From page 6-140 of my IBM DOS 3.30 Technical Reference manual, the second
page of the "40H Write to a File or Device" function description, second
paragraph:

	"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)."

I've been using this method of truncating files for years -- I'm
pretty certain it was documented back in the days of DOS 2.11.
While I applaud the detective work of the folks who learn these things
the hard way (it's the best way to learn DOS inside and out), I have
to suggest that if you plan to do a lot of DOS assembly-level programming,
you should acquire an MS- or PC-DOS tech ref, if you don't already have
one, and make use of it.
________________________________________

Bill Frolik	Hewlett-Packard Co.
hp-pcd!bill	Corvallis, Oregon