Xref: utzoo comp.lang.c:28341 comp.lang.misc:4954 comp.sys.ibm.pc:49835 comp.sys.ibm.pc.programmer:1266 Path: utzoo!attcan!uunet!clyde.concordia.ca!mcgill-vision!snorkelwacker!bu.edu!xylogics!transfer!lectroid!jjmhome!m2c!wpi!jhallen From: jhallen@wpi.wpi.edu (Joseph H Allen) Newsgroups: comp.lang.c,comp.lang.misc,comp.sys.ibm.pc,comp.sys.ibm.pc.programmer Subject: Re: questions about a backup program for the MS-DOS environment Keywords: copy Message-ID: <12459@wpi.wpi.edu> Date: 1 May 90 21:21:35 GMT References: <255@uecok.UUCP> <1990Apr25.125806.20450@druid.uucp> Reply-To: jhallen@wpi.wpi.edu (Joseph H Allen) Organization: Worcester Polytechnic Institute, Worcester ,MA Lines: 59 In article <1990Apr25.125806.20450@druid.uucp> darcy@druid.UUCP (D'Arcy J.M. Cain) writes: >In article <255@uecok.UUCP> dcrow@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 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@wpi.wpi.edu (130.215.24.1)