Commit 49c13f4f by Alan Mishchenko

Added new procedures to read files.

parent 795b5a6c
......@@ -104,8 +104,10 @@ extern char * Extra_FileNameExtension( char * FileName );
extern char * Extra_FileNameAppend( char * pBase, char * pSuffix );
extern char * Extra_FileNameGeneric( char * FileName );
extern char * Extra_FileNameGenericAppend( char * pBase, char * pSuffix );
extern int Extra_FileCheck( char * pFileName );
extern int Extra_FileSize( char * pFileName );
extern char * Extra_FileRead( FILE * pFile );
extern char * Extra_FileReadContents( char * pFileName );
extern int Extra_FileIsType( char * pFileName, char * pS1, char * pS2, char * pS3 );
extern char * Extra_TimeStamp();
extern char * Extra_StringAppend( char * pStrGiven, char * pStrAdd );
......
......@@ -203,11 +203,38 @@ char * Extra_FileNameGenericAppend( char * pBase, char * pSuffix )
SeeAlso []
***********************************************************************/
int Extra_FileCheck( char * pFileName )
{
FILE * pFile;
pFile = fopen( pFileName, "rb" );
if ( pFile == NULL )
{
printf( "Extra_FileCheck(): File \"%s\" does not exist.\n", pFileName );
return 0;
}
fseek( pFile, 0, SEEK_END );
if ( ftell( pFile ) == 0 )
printf( "Extra_FileCheck(): File \"%s\" is empty.\n", pFileName );
fclose( pFile );
return 1;
}
/**Function*************************************************************
Synopsis [Returns the file size.]
Description [The file should be closed.]
SideEffects []
SeeAlso []
***********************************************************************/
int Extra_FileSize( char * pFileName )
{
FILE * pFile;
int nFileSize;
pFile = fopen( pFileName, "r" );
pFile = fopen( pFileName, "rb" );
if ( pFile == NULL )
{
printf( "Extra_FileSize(): The file is unavailable (absent or open).\n" );
......@@ -252,6 +279,28 @@ char * Extra_FileRead( FILE * pFile )
/**Function*************************************************************
Synopsis [Read the file into the internal buffer.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
char * Extra_FileReadContents( char * pFileName )
{
FILE * pFile;
char * pBuffer;
pFile = fopen( pFileName, "rb" );
pBuffer = pFile ? Extra_FileRead( pFile ) : NULL;
if ( pFile )
fclose( pFile );
return pBuffer;
}
/**Function*************************************************************
Synopsis [Returns one if the file has a given extension.]
Description []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment