Mail Archives: djgpp/1999/07/31/13:06:17
On Thu, 29 Jul 99 11:51:49 +0300, Oleg Ossovitskii
<Oleg DOT Ossovitskii AT p20 DOT f44 DOT n478 DOT z2 DOT fidonet DOT org> 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 <stdio.h>
#include <io.h>
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
- Raw text -