[net.micro.pc] File truncation under PC-DOS

bright@dataioDataio.UUCP (Walter Bright) (02/02/86)

Anyone out there know a way to truncate a file to 'n' bytes in
length (without going in and directly manipulating the FAT)? I
need a method that is 'well-behaved'.

			Thanks in advance.

rde@ukc.UUCP (02/04/86)

In article <901@dataioDataio.UUCP> bright@dataio.UUCP writes:
>Anyone out there know a way to truncate a file to 'n' bytes in
>length (without going in and directly manipulating the FAT)? I
>need a method that is 'well-behaved'.
>
Use  function  42H (seek) to move the file pointer to the place you want
the file truncated. Then use function 40H (write) with a count  of  zero
(CX=0). This  comes  from the MS-DOS Programmer's Manual so it ought (!)
to be well behaved.  Hope this helps.
-- 
           Bob Eager

           rde@ukc.UUCP
           rde@ukc
           ...!mcvax!ukc!rde

           Phone: +44 227 66822 ext 7589

bill@hp-pcd.UUCP (02/05/86)

Truncating a file to 'n' bytes is fairly easy:

[1] Open the file for read/write access using Int 21h function 3Dh.

[2] Use Int 21h function 42h to position the file pointer to position 'n'.

[3] Truncate the file at that point by using Int 21h function 40h (Write
    to File or Device) with a byte count of zero in CX.

[4] Close the file using Int 21h function 3Eh (or 4Ch).

bill frolik
hplabs!hp-pcd!bill