questions about a backup program for the MS-DOS environment

Joseph H Allen jhallen at wpi.wpi.edu
Wed May 2 07:21:35 AEST 1990


In article <1990Apr25.125806.20450 at druid.uucp> darcy at druid.UUCP (D'Arcy J.M. Cain) writes:
>In article <255 at uecok.UUCP> dcrow at uecok (David Crow -- ECU Student) writes:
>> [...]
>>      - possibly a faster copying scheme.  the following is the
>>         code I am using to copy from one file to another:
>>
>>            do
>>            {
>>               n = fread(buf, sizeof(char), MAXBUF, infile);
>>               fwrite(buf, sizeof(char), n, outfile);
>>            } while (n == MAXBUF);        /* where MAXBUF = 7500 */
>>
>Try:
>     while ((n = fread(buf, sizeof(char), BUFSIZ, infile)) != 0)
>		fwrite(buf, sizeof(char), n, outfile);
>
>By using BUFSIZ instead of your own buffer length you get a buffer size
>equal to what the fread and fwrite routines use.  

No, no, no Yuck!  Don't use the C functions, and don't use such tiny buffers.
(no wonder it's so slow :-)

Try (in small or tiny model):

#include <dos.h>

char far *buffer=farmalloc(65024);
unsigned n;
int readfile;	/* Open handle (use _open() ) */
int writefile;	/* Open handle (use _open() ) */

do
 {
 _BX=readfile;		/* Handle */
 _CX=65024;		/* Count */
 _DX=FP_OFF(buffer);	/* Offset of buffer */
 _DS=FP_SEG(buffer);	/* Segment of buffer */
 _AH=0x3f;
 geninterrupt(0x21);	/* Read */
 __emit__(0x73,2,0x2b,0xc0);	/* Clear AX if error.  This codes to:
					jnc over
					sub ax,ax
				    over:
				*/
 _DS=_SS;		/* Restore data segment */

 n=_AX;			/* Get amount actually read */
 if(!n) break;		/* If we're done */

 _CX=n;
 _BX=writefile;
 _DX=FP_OFF(buffer);
 _DS=FP_SEG(buffer);
 _AH=0x40;
 geninterrupt(0x21);	/* Write */
 _DS=_SS;
 } while(n==65024);
-- 
jhallen at wpi.wpi.edu (130.215.24.1)



More information about the Comp.lang.c mailing list