P
Patrice
Hi,
I would to call fopen function several time in my application.
This application permits to read files which path is registered in a
configuration file.
For exemple:
File 1 = toto.txt
File 2 = tot2.txt
....File N = TotoN.txt
Then, I read each file (one by one), get adress of the beginning of
data and size of data.
I use, this function:
static bool OpenFile(char* aSrcPath, uint8** aBuffer, uint32*
aBufferSize)
{
FILE* theInputFile = 0;
uint8* theBuffer = 0;
uint32 theBufferSize = 0;
uint32 theSizeRead = 0;
/********************/
/* we open the file */
/********************/
if ( (theInputFile = fopen(aSrcPath, "rb")) == 0 )
{
return false;
}
/* ********************************* */
/* *** we must to know file size *** */
/* ********************************* */
if ( fseek( theInputFile, 0, SEEK_END ) != 0)
{
fclose(theInputFile);
return false;
}
if ( (theBufferSize = ftell(theInputFile)) == -1L )
{
fclose(theInputFile);
return false;
}
/* ************************** */
/* *** we allocate buffer *** */
/* ************************** */
if ((theBuffer = (uint8*)malloc(theBufferSize))==0)
{
fclose(theInputFile);
return false;
}
/* ****************************** */
/* *** we read file from disk *** */
/* ****************************** */
if ( fseek( theInputFile, 0, SEEK_SET ) != 0)
{
fclose(theInputFile);
freeBuffer(&theBuffer, &theBufferSize);
return false;
}
theSizeRead = fread( theBuffer, sizeof(uint8), theBufferSize,
theInputFile );
if( theSizeRead != theBufferSize )
{
fclose(theInputFile);
freeBuffer(&theBuffer, &theBufferSize);
return false;
}
/* ************************* */
/* *** we can close file *** */
/* ************************* */
fclose(theInputFile);
/* *********** */
/* All it's ok */
/* *********** */
*aBuffer = theBuffer;
*aBufferSize = theBufferSize;
return true;
}
The problem is when I reach 260 calls (to open my 260th file in config
file) of this function fopen failed.
And each time I use it from this point all fopen failed.
I already check path, and when I close my application and I start to
read from the 260th file, it works until 520th file ...
Thanks for your advices,
Patrice.
I would to call fopen function several time in my application.
This application permits to read files which path is registered in a
configuration file.
For exemple:
File 1 = toto.txt
File 2 = tot2.txt
....File N = TotoN.txt
Then, I read each file (one by one), get adress of the beginning of
data and size of data.
I use, this function:
static bool OpenFile(char* aSrcPath, uint8** aBuffer, uint32*
aBufferSize)
{
FILE* theInputFile = 0;
uint8* theBuffer = 0;
uint32 theBufferSize = 0;
uint32 theSizeRead = 0;
/********************/
/* we open the file */
/********************/
if ( (theInputFile = fopen(aSrcPath, "rb")) == 0 )
{
return false;
}
/* ********************************* */
/* *** we must to know file size *** */
/* ********************************* */
if ( fseek( theInputFile, 0, SEEK_END ) != 0)
{
fclose(theInputFile);
return false;
}
if ( (theBufferSize = ftell(theInputFile)) == -1L )
{
fclose(theInputFile);
return false;
}
/* ************************** */
/* *** we allocate buffer *** */
/* ************************** */
if ((theBuffer = (uint8*)malloc(theBufferSize))==0)
{
fclose(theInputFile);
return false;
}
/* ****************************** */
/* *** we read file from disk *** */
/* ****************************** */
if ( fseek( theInputFile, 0, SEEK_SET ) != 0)
{
fclose(theInputFile);
freeBuffer(&theBuffer, &theBufferSize);
return false;
}
theSizeRead = fread( theBuffer, sizeof(uint8), theBufferSize,
theInputFile );
if( theSizeRead != theBufferSize )
{
fclose(theInputFile);
freeBuffer(&theBuffer, &theBufferSize);
return false;
}
/* ************************* */
/* *** we can close file *** */
/* ************************* */
fclose(theInputFile);
/* *********** */
/* All it's ok */
/* *********** */
*aBuffer = theBuffer;
*aBufferSize = theBufferSize;
return true;
}
The problem is when I reach 260 calls (to open my 260th file in config
file) of this function fopen failed.
And each time I use it from this point all fopen failed.
I already check path, and when I close my application and I start to
read from the 260th file, it works until 520th file ...
Thanks for your advices,
Patrice.