From: horst DOT kraemer AT snafu DOT de (Horst Kraemer) Newsgroups: comp.os.msdos.djgpp Subject: Re: Bug of feature? Date: Sat, 31 Jul 1999 15:19:54 GMT Organization: [Posted via] Interactive Networx Message-ID: <37a18356.176517645@news.snafu.de> References: <933253275 AT p20 DOT f44 DOT n478 DOT z2 DOT FidoNet DOT ftn> NNTP-Posting-Host: n36-61.berlin.snafu.de X-Newsreader: Forte Free Agent 1.11/32.235 Lines: 69 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Thu, 29 Jul 99 11:51:49 +0300, Oleg Ossovitskii wrote: > > Hello, All, how do You do? > > In my program i cut big file on pieces with size 'splitSize'. > > ================== Begin of Windows Clipboard ================= > > while( fgets( buf, sizeof(buf), inStream)) // read string from input stream > { > fputs( buf, outStream); // write string to destination stream (file) > // in Borland C++ all works correctly, but in Djgpp > // file split on pieces on 16KB only ! Why? This is bug or feature? > if( filelength( fileno( outStream)) >= splitSize) // check size of file > { > if(curColor > 15) curColor = 1; // write files on screen > textcolor( curColor++); // with different colors > cprintf("%s\r\n", currentFName); // cyclic from 1..15 > fclose(outStream); // close file > // create next filename > sprintf( currentFName, "%s.%03d", name, ++numOfFile); > // open file with new name > if( !(outStream = fopen( currentFName, "w+b"))) > { > fprintf(stderr, "Can't open file '%s' for write.\n", argv[1]); > return 3; > } > } > } > > =================== End of Windows Clipboard ================== It's neither a bug or feature of DJGPP but it is a bug or feature of your program. Please test this program with BORLAND and DJGPP #include #include int main() { FILE *f; if ( (f=fopen("test","wb"))==0) return 1; fputs("hello",f); /* fflush(f); */ printf("%ld\n",filelength(fileno(f))); fclose(f); return 0; } It will display 0 even with BCC, does it ? The problem is that your FILE is buffered and filelength doesn't know. So filelength will always display the length of the file as committed to DOS. If you want to record the correct filelength after every fputs or fwrite you have to flush the FILE via 'fflush(f)' before calling filelength. Regards Horst