Re: fopen gives wrong bufsiz
Ismo Salonen wrote:
AAW wrote:
I?m not using the _bufsiz to read the file. I?m using the standard
functions. However, _bufsiz does not show the correct size of the
file. I can use fscanf etc. to read the file but I can only read
0x1000 bytes of data and not the whole file.
The _bufsiz is implementation detail, you should not need to know its
existense. It will never be the same as the filesize other than by pure
coincidence. It is not needed to be same. File is read in piece after
piece.
It will not prevent reading the whole file. Show the actual code, how
are you reading the file, the error must be there.
ismo
<<It will never be the same as the filesize other than by pure
> coincidence. >>
Interesting, so at some point the _bufsize should change and count
change to match it?
Here is more of the code:
if((fp = fopen(strName, "rb")) != NULL)
{
//read in the first part of the data
//if(fread(&m_byDataA, sizeof(BYTE), 1, fp) != EOF)
//if((m_byDataA = getc(fp)) != EOF)
if(fscanf(fp, "%c", &m_byDataA))
{
if(ferror(fp) != 0)
{
//handle error
return FALSE;
}
//read in the second part of the data
//if(fread(&m_byDataB, sizeof(BYTE), 1, fp) != EOF)
//if((m_byDataB = getc(fp)) != EOF)
if(fscanf(fp, "%c", &m_byDataB))
{
if(ferror(fp) != 0)
{
//handle error
return FALSE;
}
}
else
{
//handle error
return FALSE;
}
}
else
{
//handle error
return FALSE;
}
}
As you can see I have tried a few different ways to read the file and
the all ?fail? after reading 0x1000 bytes of data. I say ?fail? but they
never return EOF but they start to return data not in the file.
<<the error must be there. >>
Or perhaps somewhere else? Could some data have been over written in
some other part of the code?